Add gitea-push and gitea-api wrapper scripts
This commit is contained in:
31
bin/gitea-api
Executable file
31
bin/gitea-api
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
TOKEN_FILE="${GITEA_TOKEN_FILE:-$HOME/.config/timi/gitea-token}"
|
||||
|
||||
if [ ! -f "$TOKEN_FILE" ]; then
|
||||
echo "error: token file not found: $TOKEN_FILE" >&2
|
||||
echo " create it with: mkdir -p '$(dirname "$TOKEN_FILE")' && echo 'YOUR_TOKEN' > '$TOKEN_FILE' && chmod 600 '$TOKEN_FILE'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TOKEN=$(cat "$TOKEN_FILE")
|
||||
|
||||
if [ -z "${1:-}" ]; then
|
||||
echo "usage: gitea-api <method> <endpoint> [curl-args...]" >&2
|
||||
echo " gitea-api POST /org/tami/repos -H Content-Type:application/json -d '{\"name\":\"my-repo\"}'" >&2
|
||||
echo " gitea-api GET /repos/tami/timi" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
METHOD="${1}"
|
||||
ENDPOINT="${2}"
|
||||
shift 2
|
||||
|
||||
BASE_URL="https://git.telavivmakers.space/api/v1"
|
||||
|
||||
exec curl -s -X "$METHOD" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"$@" \
|
||||
"${BASE_URL}${ENDPOINT}"
|
||||
23
bin/gitea-push
Executable file
23
bin/gitea-push
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
TOKEN_FILE="${GITEA_TOKEN_FILE:-$HOME/.config/timi/gitea-token}"
|
||||
|
||||
if [ ! -f "$TOKEN_FILE" ]; then
|
||||
echo "error: token file not found: $TOKEN_FILE" >&2
|
||||
echo " create it with: mkdir -p '$(dirname "$TOKEN_FILE")' && echo 'YOUR_TOKEN' > '$TOKEN_FILE' && chmod 600 '$TOKEN_FILE'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TOKEN=$(cat "$TOKEN_FILE")
|
||||
|
||||
if [ -z "${1:-}" ]; then
|
||||
echo "usage: gitea-push <remote> [branch]" >&2
|
||||
echo " gitea-push origin master" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REMOTE="${1}"
|
||||
BRANCH="${2:-$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo HEAD)}"
|
||||
|
||||
exec git -c http.extraHeader="Authorization: token ${TOKEN}" push "$REMOTE" "$BRANCH"
|
||||
Reference in New Issue
Block a user