~kris/dots

srice

ref: 512b7381d0155d6247fad64b640b0704496a8035 srice/.local/bin/srht-mirror -rwxr-xr-x 745 bytes
512b7381 — Kris Yotam mksh: port bashisms to mksh-safe (process subs, DEBUG-trap history hook, direnv, cd- alias) 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
# srht-mirror -- import a GitHub repo to sr.ht
set -eu

if [ -z "${1:-}" ]; then
    echo "Usage: srht-mirror <github-url-or-user/repo> [srht-name]" >&2
    exit 1
fi

GITHUB="$1"
case "$GITHUB" in
    https://*) URL="$GITHUB" ;;
    *) URL="https://github.com/$GITHUB" ;;
esac

NAME="${2:-$(basename "$URL" .git)}"
TOKEN=$(cat ~/.config/srht/token)

echo "[*] Importing $URL as $NAME..."
curl -s --oauth2-bearer "$TOKEN" -H 'Content-Type: application/json' \
  -d "{\"query\": \"mutation { createRepository(name: \\\"$NAME\\\", visibility: PUBLIC, cloneUrl: \\\"$URL\\\") { id name } }\"}" \
  https://git.sr.ht/query | jq -r '.data.createRepository | "    \(.name) (id: \(.id))"'

echo "[+] Done: https://git.sr.ht/~krisyotam/$NAME"