fix(route): resume existing ai/issue-N branch on re-trigger #47

Merged
ffaerber merged 1 commits from fix/route-resume-existing-branch into main 2026-07-04 12:21:08 +02:00
Showing only changes of commit d803ee7cf5 - Show all commits
+7 -1
View File
@@ -55,7 +55,13 @@ if [ -n "$IS_PR" ]; then # comment on a PR -> resume its bra
ref=$(curl -s -H "Authorization: token $GT" "$API/pulls/$NUM" | jq -r .head.ref)
git fetch origin "$ref" && git checkout "$ref"
{ echo "branch=$ref"; echo "new=false"; } >> "$GITHUB_OUTPUT"
else # comment on an issue -> new branch
elif git ls-remote --exit-code --heads origin "ai/issue-$NUM" >/dev/null 2>&1; then
# comment on an issue whose branch ALREADY exists (a prior run / open PR) -> RESUME it, so new
# commits fast-forward onto the same branch and update its PR. Branching fresh from main here would
# be rejected on push as non-fast-forward and the new work would be silently lost (see issue #17).
git fetch origin "ai/issue-$NUM" && git checkout "ai/issue-$NUM"
{ echo "branch=ai/issue-$NUM"; echo "new=false"; } >> "$GITHUB_OUTPUT"
else # comment on an issue, no branch yet -> new branch
git checkout -b "ai/issue-$NUM"
{ echo "branch=ai/issue-$NUM"; echo "new=true"; } >> "$GITHUB_OUTPUT"
# For dev agents, publish the branch immediately and tell the maintainer where to watch.