File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,17 +137,29 @@ jobs:
137137 # longer replication lag against new branches (>30s observed).
138138 # REST /pulls accepts the head SHA directly and works immediately.
139139 PR_TITLE="Sync upstream $TAG (merge conflicts)"
140+
141+ # Check if PR already exists for this branch — skip if so
142+ EXISTING_PR=$(gh api "repos/${GITHUB_REPOSITORY}/pulls?state=open" --jq ".[] | select(.head.ref==\"$BRANCH\") | .number" 2>/dev/null | head -1)
143+ if [ -n "$EXISTING_PR" ]; then
144+ echo "PR #$EXISTING_PR already exists for $BRANCH, skipping creation"
145+ exit 0
146+ fi
147+
140148 for attempt in 1 2 3 4 5 6; do
141- HTTP_CODE =$(jq -n --arg t "$PR_TITLE" --arg b "$PR_BODY" --arg h "$BRANCH" \
149+ HTTP_RESPONSE =$(jq -n --arg t "$PR_TITLE" --arg b "$PR_BODY" --arg h "$BRANCH" \
142150 '{title:$t, body:$b, head:$h, base:"main"}' | \
143151 gh api -X POST "repos/${GITHUB_REPOSITORY}/pulls" \
144- --input - \
145- --silent 2>&1)
146- if [ $? -eq 0 ]; then
152+ --input - 2>&1)
153+ EXIT_CODE=$?
154+ if [ $EXIT_CODE -eq 0 ]; then
147155 echo "PR created successfully on attempt $attempt"
148156 exit 0
149157 fi
150- echo "PR creation failed (attempt $attempt): $HTTP_CODE"
158+ if echo "$HTTP_RESPONSE" | grep -q "A pull request already exists"; then
159+ echo "PR already exists for $BRANCH"
160+ exit 0
161+ fi
162+ echo "PR creation failed (attempt $attempt): $HTTP_RESPONSE"
151163 echo "Retrying in 5s..."
152164 sleep 5
153165 done
You can’t perform that action at this time.
0 commit comments