diff options
| author | 2025-12-29 23:04:50 +0000 | |
|---|---|---|
| committer | 2026-04-04 01:37:54 +0100 | |
| commit | cf1a3fd1e4267ec522c10da087262daddc782b20 (patch) | |
| tree | d11b34eafa4301fe08bdf03027cf6ef9e580f189 | |
| parent | 2088b61f3d6053d3879dcfcbe91c00157d050e16 (diff) | |
| download | sst-cf1a3fd1e4267ec522c10da087262daddc782b20.tar.gz sst-cf1a3fd1e4267ec522c10da087262daddc782b20.zip | |
Add PatchBot stuff
These are a little different than the ones we were using privately
before and will require some one-off hopefully straightforward
copy-pasting for existing developers. But hopefully this'll remove some
friction from using the thing across the board.
I'd still like to investigate smoother auth methods in the future. The
SSH key idea seems like a good one, but there's some annoying obstacles
there. There's also the idea of having the Discord bot send people
tokens. For now, it's still just manual, which is probably good enough
for quite a long time, to be honest.
This also includes the Sorse Tecknoledgy Committy Discord link, because
I've kind of not done well to advertise the existence of that thing. It
has always been technically open the public, except many people probably
don't know it's there.
| -rw-r--r-- | README | 36 | ||||
| -rwxr-xr-x | tools/patchbot/bin/git-grab | 49 | ||||
| -rwxr-xr-x | tools/patchbot/bin/git-submit | 64 | ||||
| -rw-r--r-- | tools/patchbot/lib/patchbot-setup.sh | 61 | ||||
| -rw-r--r-- | tools/patchbot/setup-path.bat | 2 | ||||
| -rw-r--r-- | tools/patchbot/setup-path.sh | 3 |
6 files changed, 215 insertions, 0 deletions
@@ -77,5 +77,41 @@ some console aliases or set up a bind to reload the plugin quickly on-the-fly. Note: some very old (and very new) Source builds don’t have a plugin_load command. For the time being, these versions are unsupported. +════ How to contribute changes ════ + +SST has a somewhat unusual development process. We don’t really take drive-by +changes via the likes of GitHub pull requests or similar, because the project +has very very specific goals and requirements, and also because I find those +workflows annoyingly unwieldy. + +Instead, development takes place in a Discord community known as the Sorse +Tecknoledgy Committy™, which you’re welcome to join: + + https://discord.gg/pC6e7RGQmD + +Do be aware that much of the day-to-day activity there is just rants and memes, +but nonetheless, the best way to get involved in this project is to come and +hang out and talk to people. The #sst-dev channel has plenty of discussion of +what needs done, how to do it, etc. Don’t be shy! Everyone is friendly! + +We have a bot in the Discord called PatchBot which allows Git changes to be +submitted as patch sets, and creates Discord threads for discussion and review. +For convenience, the Git subcommands for working with PatchBot are implemented +inside the SST repository itself. You can use one of the following commands to +set it up for your current terminal session: + + • `tools\patchbot\setup-path.bat` (Windows cmd.exe) + • `. tools/patchbot/setup-path.sh` (Unix-like/POSIX shell) + +This will enable the use of `git grab <number>` to apply a numbered patch series +from a corresponding Discord thread under the #sst-dev channel, as well as +`git submit "description"` to create a new thread from your current WIP. Note +however that the latter requires an authorisation token, both to prevent random +spam and to associate submissions with individuals. Once you’re somewhat +involved in the project I can happily set this up for you. It’s a bit of a +manual process at the moment because there’s nowhere enough people to justify +implementing a proper login system. That’s time that could be spent on SST +itself, or something. + Thanks, and have fun! - Michael Smith <mikesmiffy128@gmail.com> diff --git a/tools/patchbot/bin/git-grab b/tools/patchbot/bin/git-grab new file mode 100755 index 0000000..8dedc4f --- /dev/null +++ b/tools/patchbot/bin/git-grab @@ -0,0 +1,49 @@ +#!/bin/sh +# This file is dedicated to the public domain. + +set -e # windows git doesn't seem to like flags in the shebang!? + +usage() { + printf 'usage: git grab [-p projectid] patchset\n' >&2 + exit 1 +} + +while getopts ":p:" arg; do + case "$arg" in + p) projectid="$OPTARG" ;; + *) usage ;; + esac +done +shift $((OPTIND - 1)) + +if [ $# != 1 ]; then usage; fi +patchset="$1" + +. "`dirname "$0"`/../lib/patchbot-setup.sh" + +doreq() { + flags="-sL" + if [ -n "$token" ]; then flags="-sLHAuthorization: Bearer $token"; fi + "$curl" -XGET "$flags" \ + -H"User-Agent patchbot-client v3" \ + --url-query "projectid=$projectid" \ + --url-query "patchset=$patchset" \ + -w"%{response_code}" \ + -o "$gitdir/PatchBot.$patchset.tmp" \ + "$server/grab" || : +} +dumpresponse() { + printf "Server returned HTTP status $httpcode.\nResponse:\n" >&2 + < "$gitdir/PatchBot.$patchset.tmp" sed 's/^/| /' >&2 # indent it! + rm "$gitdir/PatchBot.$patchset.tmp" +} + +# if we don't have a token we can try an anonymous grab first. if the project +# doesn't allow it we'll get a 401 and can then do the auth setup prompt. +httpcode="`doreq`" +if [ "$httpcode" = 401 ]; then dumpresponse; setupauth; doreq; fi +if [ "$httpcode" != 200 ]; then dumpresponse; exit 2; fi +< "$gitdir/PatchBot.$patchset.tmp" git am --keep-cr +rm "$gitdir/PatchBot.$patchset.tmp" + +# vi: sw=4 ts=4 noet tw=80 cc=80 diff --git a/tools/patchbot/bin/git-submit b/tools/patchbot/bin/git-submit new file mode 100755 index 0000000..70c2efc --- /dev/null +++ b/tools/patchbot/bin/git-submit @@ -0,0 +1,64 @@ +#!/bin/sh +# This file is dedicated to the public domain. + +set -e # windows git doesn't seem to like flags in the shebang!? + +usage() { + printf 'usage: git submit [-p projectid] description [range]\n' >&2 + exit 1 +} + +while getopts ":p:" arg; do + case "$arg" in + p) projectid="$OPTARG" ;; + *) usage ;; + esac +done +shift $((OPTIND - 1)) + +if [ $# -lt 1 -o $# -gt 2 ]; then usage; fi +description="$1" + +. "`dirname "$0"`/../lib/patchbot-setup.sh" + +range="${2:-"$remote_branch"}" + +git format-patch --histogram --stdout "$range" > "$gitdir/PatchBot.req.tmp" + +rmtmp() { + rm -f "$gitdir/PatchBot.req.tmp" "$gitdir/PatchBot.resp.tmp" +} + +doreq() { + "$curl" -sLXPOST -H"Authorization: Bearer $token" \ + -H"Content-Type: application/mbox" \ + -H"User-Agent: patchbot-client v3" \ + --data-binary @"$gitdir/PatchBot.req.tmp" - \ + --url-query "projectid=$projectid" \ + --url-query "description=$description" \ + -o "$gitdir/PatchBot.resp.tmp" \ + "$server/submit" >&2 +} +dumpresponse() { + printf "Server returned HTTP status $httpcode.\nResponse:\n" >&2 + < "$gitdir/PatchBot.resp.tmp" sed 's/^/| /' >&2 # indent it! +} + +# server doesn't allow anonymous submits. make sure we have a token first. +if [ -z "$token" ]; then + printf "error: submitting to PatchBot requires an auth token\n">&2 + setupauth; +fi +httpcode="`doreq`" +if [ "$httpcode" != 200 ]; then + dumpresponse + rmtmp + exit 2 +else + # just cat the response directly, it should be a brief message intended for + # direct display, containing the patchset number. + cat "$gitdir/PatchBot.resp.tmp" + rmtmp +fi + +# vi: sw=4 ts=4 noet tw=80 cc=80 diff --git a/tools/patchbot/lib/patchbot-setup.sh b/tools/patchbot/lib/patchbot-setup.sh new file mode 100644 index 0000000..029502d --- /dev/null +++ b/tools/patchbot/lib/patchbot-setup.sh @@ -0,0 +1,61 @@ +# This file is dedicated to the public domain. + +this_project=sst + +case "`uname`" in + *_NT*) + # make sure we use windows curl because Git's bundled curl might be + # really old + curl="$SYSTEMROOT/System32/curl.exe" + tokendir="$LOCALAPPDATA/PatchBot" + devtty="&0" ;; # /dev/tty doesn't seem to work even with Git's MSYS Bash + *) + curl=curl + # this isn't technically guaranteed to be installed + if ! command -v curl >/dev/null 2>&1; then + printf "patchbot-setup: fatal: curl is not installed\n" >&2 + exit 2 + fi + tokendir="${XDG_STATE_HOME:-~/.local/state}/patchbot" + devtty=/dev/tty ;; +esac + +urltofilename() { + _str="$1" + _ret="" + while [ -n "$_str" ]; do + _next="${_str#?}" + case "$_str" in + [a-z0-0\.,\-+=@\$]*) _ret="$_ret${_str%"$_next"}" ;; + _*) _ret="${_ret}__" ;; + *) _ret="$_ret`printf '_%02x' "'$_str"`" ;; + esac + _str="$_next" + done + echo "$_ret" +} + +gitdir="`git rev-parse --git-dir`" + +token="" +server="`git config --default "https://patchbot.mikes.software" PatchBot.server`" +: "${projectid:="`git config --default $this_project PatchBot.projectid`"}" +remote_branch="`git config --default origin/master PatchBot.remoteBranch`" +tokenfile="$tokendir/token_`urltofilename "$server"`" +if [ -f "$tokenfile" ]; then token="`cat "$tokenfile"`"; fi + +setupauth() { + printf "NOTE: PatchBot auth setup currently has to be done manually.\n" >&2 + printf "Get yourself a token via the Tecknoledgy Committy, and paste it here:\n" >&2 + printf "> " >&2 + eval "read -r token <$devtty" # have to eval for &0 to work + if [ -z "$token" ]; then + printf "No token provided, exiting\n" >&2; + exit 1; + fi + mkdir -p "$tokendir" + printf '%s\n' "$token" > "$tokenfile" + printf 'Note: saved token to %s - please DO NOT share this!\n' "$tokenfile" >&2 +} + +# vi: sw=4 ts=4 noet tw=80 cc=80 diff --git a/tools/patchbot/setup-path.bat b/tools/patchbot/setup-path.bat new file mode 100644 index 0000000..b57f351 --- /dev/null +++ b/tools/patchbot/setup-path.bat @@ -0,0 +1,2 @@ +:: This file is dedicated to the public domain.
+@set Path=%~dp0bin;%Path%
diff --git a/tools/patchbot/setup-path.sh b/tools/patchbot/setup-path.sh new file mode 100644 index 0000000..caaad79 --- /dev/null +++ b/tools/patchbot/setup-path.sh @@ -0,0 +1,3 @@ +# This file is dedicated to the public domain. +PATH="`realpath "$(dirname "$0")"`/bin:$PATH" +export PATH |
