Add gitea-push and gitea-api wrapper scripts

This commit is contained in:
fedora-bot
2026-04-28 19:55:53 +03:00
parent 705f1f8116
commit 635c6bc075
2 changed files with 54 additions and 0 deletions

31
bin/gitea-api Executable file
View 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
View 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"