From abbd889e30ee91401d2822ec8b92e9e9b2c40571 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Tue, 26 May 2026 14:29:42 -0500 Subject: [PATCH] fix(mosaic-tools): pass explicit Gitea repo args --- .../framework/tools/git/detect-platform.sh | 10 ++++ .../framework/tools/git/issue-comment.sh | 2 +- .../framework/tools/git/issue-create.sh | 3 +- .../mosaic/framework/tools/git/issue-list.sh | 3 +- .../framework/tools/git/issue-reopen.sh | 4 +- .../mosaic/framework/tools/git/issue-view.sh | 2 +- .../mosaic/framework/tools/git/pr-close.sh | 4 +- .../mosaic/framework/tools/git/pr-create.sh | 53 +++++++++++++++++-- .../mosaic/framework/tools/git/pr-list.sh | 3 +- .../mosaic/framework/tools/git/pr-review.sh | 6 +-- .../mosaic/framework/tools/git/pr-view.sh | 2 +- 11 files changed, 76 insertions(+), 16 deletions(-) diff --git a/packages/mosaic/framework/tools/git/detect-platform.sh b/packages/mosaic/framework/tools/git/detect-platform.sh index c53e0af..fa97492 100755 --- a/packages/mosaic/framework/tools/git/detect-platform.sh +++ b/packages/mosaic/framework/tools/git/detect-platform.sh @@ -74,6 +74,16 @@ get_repo_name() { echo "${repo_info##*/}" } +get_repo_slug() { + get_repo_info +} + +get_gitea_repo_args() { + local repo + repo=$(get_repo_slug) || return 1 + printf -- '--repo %q --login %q' "$repo" "${GITEA_LOGIN:-mosaicstack}" +} + get_remote_host() { local remote_url remote_url=$(git remote get-url origin 2>/dev/null || true) diff --git a/packages/mosaic/framework/tools/git/issue-comment.sh b/packages/mosaic/framework/tools/git/issue-comment.sh index 3edd64b..b1cc4ad 100755 --- a/packages/mosaic/framework/tools/git/issue-comment.sh +++ b/packages/mosaic/framework/tools/git/issue-comment.sh @@ -53,7 +53,7 @@ if [[ "$PLATFORM" == "github" ]]; then gh issue comment "$ISSUE_NUMBER" --body "$COMMENT" echo "Added comment to GitHub issue #$ISSUE_NUMBER" elif [[ "$PLATFORM" == "gitea" ]]; then - tea issue comment "$ISSUE_NUMBER" "$COMMENT" + tea issue comment "$ISSUE_NUMBER" "$COMMENT" $(get_gitea_repo_args) echo "Added comment to Gitea issue #$ISSUE_NUMBER" else echo "Error: Unknown platform" diff --git a/packages/mosaic/framework/tools/git/issue-create.sh b/packages/mosaic/framework/tools/git/issue-create.sh index c658506..fce5271 100755 --- a/packages/mosaic/framework/tools/git/issue-create.sh +++ b/packages/mosaic/framework/tools/git/issue-create.sh @@ -120,7 +120,8 @@ case "$PLATFORM" in ;; gitea) if command -v tea >/dev/null 2>&1; then - CMD="tea issue create --title \"$TITLE\"" + REPO_ARGS=$(get_gitea_repo_args) + CMD="tea issue create $REPO_ARGS --title \"$TITLE\"" [[ -n "$BODY" ]] && CMD="$CMD --description \"$BODY\"" [[ -n "$LABELS" ]] && CMD="$CMD --labels \"$LABELS\"" # tea accepts milestone by name directly (verified 2026-02-05) diff --git a/packages/mosaic/framework/tools/git/issue-list.sh b/packages/mosaic/framework/tools/git/issue-list.sh index 37e00c5..540f728 100755 --- a/packages/mosaic/framework/tools/git/issue-list.sh +++ b/packages/mosaic/framework/tools/git/issue-list.sh @@ -80,7 +80,8 @@ case "$PLATFORM" in eval "$CMD" ;; gitea) - CMD="tea issues list --state $STATE --limit $LIMIT" + REPO_ARGS=$(get_gitea_repo_args) + CMD="tea issues list $REPO_ARGS --state $STATE --limit $LIMIT" [[ -n "$LABEL" ]] && CMD="$CMD --labels \"$LABEL\"" [[ -n "$MILESTONE" ]] && CMD="$CMD --milestones \"$MILESTONE\"" # Note: tea may not support assignee filter directly diff --git a/packages/mosaic/framework/tools/git/issue-reopen.sh b/packages/mosaic/framework/tools/git/issue-reopen.sh index 136af4b..734fe34 100755 --- a/packages/mosaic/framework/tools/git/issue-reopen.sh +++ b/packages/mosaic/framework/tools/git/issue-reopen.sh @@ -52,9 +52,9 @@ if [[ "$PLATFORM" == "github" ]]; then echo "Reopened GitHub issue #$ISSUE_NUMBER" elif [[ "$PLATFORM" == "gitea" ]]; then if [[ -n "$COMMENT" ]]; then - tea issue comment "$ISSUE_NUMBER" "$COMMENT" + tea issue comment "$ISSUE_NUMBER" "$COMMENT" $(get_gitea_repo_args) fi - tea issue reopen "$ISSUE_NUMBER" + tea issue reopen "$ISSUE_NUMBER" $(get_gitea_repo_args) echo "Reopened Gitea issue #$ISSUE_NUMBER" else echo "Error: Unknown platform" diff --git a/packages/mosaic/framework/tools/git/issue-view.sh b/packages/mosaic/framework/tools/git/issue-view.sh index 419107d..18460e5 100755 --- a/packages/mosaic/framework/tools/git/issue-view.sh +++ b/packages/mosaic/framework/tools/git/issue-view.sh @@ -67,7 +67,7 @@ if [[ "$PLATFORM" == "github" ]]; then gh issue view "$ISSUE_NUMBER" elif [[ "$PLATFORM" == "gitea" ]]; then if command -v tea >/dev/null 2>&1; then - if tea issue "$ISSUE_NUMBER"; then + if tea issue "$ISSUE_NUMBER" $(get_gitea_repo_args); then exit 0 fi echo "Warning: tea issue view failed, trying Gitea API fallback..." >&2 diff --git a/packages/mosaic/framework/tools/git/pr-close.sh b/packages/mosaic/framework/tools/git/pr-close.sh index 4d06580..afdfd3e 100755 --- a/packages/mosaic/framework/tools/git/pr-close.sh +++ b/packages/mosaic/framework/tools/git/pr-close.sh @@ -52,9 +52,9 @@ if [[ "$PLATFORM" == "github" ]]; then echo "Closed GitHub PR #$PR_NUMBER" elif [[ "$PLATFORM" == "gitea" ]]; then if [[ -n "$COMMENT" ]]; then - tea pr comment "$PR_NUMBER" "$COMMENT" + tea pr comment "$PR_NUMBER" "$COMMENT" $(get_gitea_repo_args) fi - tea pr close "$PR_NUMBER" + tea pr close "$PR_NUMBER" $(get_gitea_repo_args) echo "Closed Gitea PR #$PR_NUMBER" else echo "Error: Unknown platform" diff --git a/packages/mosaic/framework/tools/git/pr-create.sh b/packages/mosaic/framework/tools/git/pr-create.sh index 6c3c666..ea68271 100755 --- a/packages/mosaic/framework/tools/git/pr-create.sh +++ b/packages/mosaic/framework/tools/git/pr-create.sh @@ -17,6 +17,51 @@ MILESTONE="" DRAFT=false ISSUE="" +# get_remote_host, get_gitea_token, get_repo_info, and get_gitea_repo_args are provided by detect-platform.sh + +gitea_pr_create_api() { + local host repo token url payload + host=$(get_remote_host) || { + echo "Error: could not determine remote host for API fallback" >&2 + return 1 + } + repo=$(get_repo_info) || { + echo "Error: could not determine repo owner/name for API fallback" >&2 + return 1 + } + token=$(get_gitea_token "$host") || { + echo "Error: Gitea token not found for API fallback (set GITEA_TOKEN or configure ~/.git-credentials)" >&2 + return 1 + } + + if [[ -n "$LABELS" || -n "$MILESTONE" || "$DRAFT" == true ]]; then + echo "Warning: API fallback applies title/body/head/base only; labels/milestone/draft require authenticated tea setup." >&2 + fi + + payload=$(TITLE="$TITLE" BODY="$BODY" HEAD_BRANCH="$HEAD_BRANCH" BASE_BRANCH="$BASE_BRANCH" python3 - <<'PY' +import json +import os + +payload = { + "title": os.environ["TITLE"], + "head": os.environ["HEAD_BRANCH"], + "base": os.environ["BASE_BRANCH"] or "main", +} +body = os.environ.get("BODY", "") +if body: + payload["body"] = body +print(json.dumps(payload)) +PY +) + + url="https://${host}/api/v1/repos/${repo}/pulls" + curl -fsS -X POST \ + -H "Authorization: token ${token}" \ + -H "Content-Type: application/json" \ + -d "$payload" \ + "$url" +} + usage() { cat </dev/null | grep -E "^\s*[0-9]+" | grep "$MILESTONE" | awk '{print $1}' | head -1) + MILESTONE_ID=$(tea milestones list $REPO_ARGS 2>/dev/null | grep -E "^\s*[0-9]+" | grep "$MILESTONE" | awk '{print $1}' | head -1) if [[ -n "$MILESTONE_ID" ]]; then CMD="$CMD --milestone $MILESTONE_ID" else diff --git a/packages/mosaic/framework/tools/git/pr-list.sh b/packages/mosaic/framework/tools/git/pr-list.sh index 27a03cd..48bf760 100755 --- a/packages/mosaic/framework/tools/git/pr-list.sh +++ b/packages/mosaic/framework/tools/git/pr-list.sh @@ -74,7 +74,8 @@ case "$PLATFORM" in ;; gitea) # tea pr list - note: tea uses 'pulls' subcommand in some versions - CMD="tea pr list --state $STATE --limit $LIMIT" + REPO_ARGS=$(get_gitea_repo_args) + CMD="tea pr list $REPO_ARGS --state $STATE --limit $LIMIT" # tea filtering may be limited if [[ -n "$LABEL" ]]; then diff --git a/packages/mosaic/framework/tools/git/pr-review.sh b/packages/mosaic/framework/tools/git/pr-review.sh index 0ef97f9..51c2bb4 100755 --- a/packages/mosaic/framework/tools/git/pr-review.sh +++ b/packages/mosaic/framework/tools/git/pr-review.sh @@ -85,7 +85,7 @@ if [[ "$PLATFORM" == "github" ]]; then elif [[ "$PLATFORM" == "gitea" ]]; then case $ACTION in approve) - tea pr approve "$PR_NUMBER" ${COMMENT:+--comment "$COMMENT"} + tea pr approve "$PR_NUMBER" $(get_gitea_repo_args) ${COMMENT:+--comment "$COMMENT"} echo "Approved Gitea PR #$PR_NUMBER" ;; request-changes) @@ -93,7 +93,7 @@ elif [[ "$PLATFORM" == "gitea" ]]; then echo "Error: Comment required for request-changes" exit 1 fi - tea pr reject "$PR_NUMBER" --comment "$COMMENT" + tea pr reject "$PR_NUMBER" $(get_gitea_repo_args) --comment "$COMMENT" echo "Requested changes on Gitea PR #$PR_NUMBER" ;; comment) @@ -101,7 +101,7 @@ elif [[ "$PLATFORM" == "gitea" ]]; then echo "Error: Comment required" exit 1 fi - tea pr comment "$PR_NUMBER" "$COMMENT" + tea pr comment "$PR_NUMBER" "$COMMENT" $(get_gitea_repo_args) echo "Added comment to Gitea PR #$PR_NUMBER" ;; *) diff --git a/packages/mosaic/framework/tools/git/pr-view.sh b/packages/mosaic/framework/tools/git/pr-view.sh index 7836e09..064f54e 100755 --- a/packages/mosaic/framework/tools/git/pr-view.sh +++ b/packages/mosaic/framework/tools/git/pr-view.sh @@ -41,7 +41,7 @@ detect_platform if [[ "$PLATFORM" == "github" ]]; then gh pr view "$PR_NUMBER" elif [[ "$PLATFORM" == "gitea" ]]; then - tea pr "$PR_NUMBER" + tea pr "$PR_NUMBER" $(get_gitea_repo_args) else echo "Error: Unknown platform" exit 1