diff options
| author | 2025-12-29 23:04:50 +0000 | |
|---|---|---|
| committer | 2026-04-04 01:37:54 +0100 | |
| commit | cf1a3fd1e4267ec522c10da087262daddc782b20 (patch) | |
| tree | d11b34eafa4301fe08bdf03027cf6ef9e580f189 /tools/patchbot/lib | |
| 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.
Diffstat (limited to 'tools/patchbot/lib')
| -rw-r--r-- | tools/patchbot/lib/patchbot-setup.sh | 61 |
1 files changed, 61 insertions, 0 deletions
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 |
