From 7436311022c1bf998cef6ef0332196c242135c2b Mon Sep 17 00:00:00 2001 From: Brad Anderson Date: Sun, 12 Jul 2026 22:04:33 -0700 Subject: [PATCH] Skip creating a duplicate PR when one is already open for the branch gitea-pr create now checks for an existing open PR on the current branch first and returns its URL instead of creating a new one. Only matches open PRs by design -- once merged, new commits on the same branch correctly get a new PR. --- bin/gitea-pr | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/gitea-pr b/bin/gitea-pr index 634eced..b8a4662 100755 --- a/bin/gitea-pr +++ b/bin/gitea-pr @@ -95,6 +95,23 @@ case "$subcommand" in echo "Detached HEAD: check out the feature branch before creating a PR" >&2 exit 1 fi + + response=$(curl -sS -w '\n%{http_code}' "${GITEA_API}/repos/${owner}/${repo}/pulls?state=open" \ + -H "Authorization: token ${GITEA_TOKEN}") + http_code=$(echo "$response" | tail -1) + json=$(echo "$response" | sed '$d') + if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then + echo "Failed to check for an existing PR (HTTP $http_code):" >&2 + echo "$json" >&2 + exit 1 + fi + existing_url=$(echo "$json" | jq -r --arg head "$current_branch" \ + '.[] | select(.head.ref == $head) | .html_url' | head -1) + if [ -n "$existing_url" ]; then + echo "$existing_url" + exit 0 + fi + if [ -z "$base" ]; then base=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's#refs/remotes/origin/##' || true) base="${base:-main}"