Split Gitea SSH host from API host (gitbox.branderson.io is HTTPS-only, gitbox.bradina.localdomain is SSH-only)
This commit is contained in:
+43
-6
@@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
GITEA_HOST="gitbox.bradina.localdomain"
|
||||
GITEA_SSH_HOST="gitbox.bradina.localdomain"
|
||||
# shellcheck disable=SC2034
|
||||
GITEA_API="https://${GITEA_HOST}/api/v1"
|
||||
GITEA_API="https://gitbox.branderson.io/api/v1"
|
||||
|
||||
function usage() {
|
||||
echo "Usage: gitea-pr create [--title TITLE] [--body BODY] [--base BRANCH]"
|
||||
@@ -27,8 +27,8 @@ function gitea_owner_repo() {
|
||||
exit 1
|
||||
}
|
||||
host=$(echo "$remote_url" | sed -E 's#^[^@]+@([^:]+):.*#\1#')
|
||||
if [ "$host" != "$GITEA_HOST" ]; then
|
||||
echo "origin remote ($remote_url) is not on $GITEA_HOST; gitea-pr only supports this host" >&2
|
||||
if [ "$host" != "$GITEA_SSH_HOST" ]; then
|
||||
echo "origin remote ($remote_url) is not on $GITEA_SSH_HOST; gitea-pr only supports this host" >&2
|
||||
exit 1
|
||||
fi
|
||||
owner_repo=$(echo "$remote_url" | sed -E 's#^[^@]+@[^:]+:##; s#\.git$##')
|
||||
@@ -60,8 +60,45 @@ esac
|
||||
|
||||
case "$subcommand" in
|
||||
create)
|
||||
echo "create: not yet implemented" >&2
|
||||
exit 1
|
||||
title=""
|
||||
body=""
|
||||
base=""
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--title) title="$2"; shift 2 ;;
|
||||
--body) body="$2"; shift 2 ;;
|
||||
--base) base="$2"; shift 2 ;;
|
||||
*) echo "Unknown option: $1" >&2; usage; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
if [ "$current_branch" = "HEAD" ]; then
|
||||
echo "Detached HEAD: check out the feature branch before creating a PR" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$base" ]; then
|
||||
base=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's#refs/remotes/origin/##')
|
||||
base="${base:-main}"
|
||||
fi
|
||||
if [ -z "$title" ]; then
|
||||
title="$current_branch"
|
||||
fi
|
||||
|
||||
response=$(curl -sS -w '\n%{http_code}' -X POST "${GITEA_API}/repos/${owner}/${repo}/pulls" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg head "$current_branch" --arg base "$base" --arg title "$title" --arg body "$body" \
|
||||
'{head: $head, base: $base, title: $title, body: $body}')")
|
||||
http_code=$(echo "$response" | tail -1)
|
||||
json=$(echo "$response" | sed '$d')
|
||||
|
||||
if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then
|
||||
echo "Failed to create PR (HTTP $http_code):" >&2
|
||||
echo "$json" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "$json" | jq -r '.html_url'
|
||||
;;
|
||||
comments)
|
||||
echo "comments: not yet implemented" >&2
|
||||
|
||||
Reference in New Issue
Block a user