Skip to content

Commit 39db168

Browse files
vdemeesterclaude
andcommitted
feat: Detect and skip duplicate cherry-pick PRs
- Prevent redundant cherry-picks when PR already exists - Provide clear feedback with link to existing PR - Save CI resources by avoiding duplicate operations Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent fcc5f78 commit 39db168

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

‎.github/workflows/chatops_cherrypick.yaml‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,27 @@ jobs:
119119
exit 1
120120
fi
121121
122-
# Create new branch for cherry-pick
122+
# Check if a cherry-pick PR already exists
123123
CHERRY_PICK_BRANCH="cherry-pick-$PR_NUMBER-to-$TARGET_BRANCH"
124+
echo "Checking for existing cherry-pick PR..."
125+
EXISTING_PR=$(gh pr list \
126+
--repo ${{ github.repository }} \
127+
--head "$CHERRY_PICK_BRANCH" \
128+
--base "$TARGET_BRANCH" \
129+
--json number,url \
130+
--jq '.[0] | select(. != null)')
131+
132+
if [ -n "$EXISTING_PR" ]; then
133+
PR_URL=$(echo "$EXISTING_PR" | jq -r '.url')
134+
PR_NUM=$(echo "$EXISTING_PR" | jq -r '.number')
135+
echo "ℹ️ Cherry-pick PR already exists: #$PR_NUM"
136+
echo "URL: $PR_URL"
137+
echo "existing_pr_url=$PR_URL" >> $GITHUB_OUTPUT
138+
echo "existing_pr_number=$PR_NUM" >> $GITHUB_OUTPUT
139+
exit 0
140+
fi
141+
142+
# Create new branch for cherry-pick
124143
echo "Creating cherry-pick branch: $CHERRY_PICK_BRANCH..."
125144
git checkout -b "$CHERRY_PICK_BRANCH" "origin/$TARGET_BRANCH"
126145
@@ -159,8 +178,22 @@ jobs:
159178
rm -f "$OUTPUT_FILE"
160179
exit $EXIT_CODE
161180
181+
- name: Comment on existing PR
182+
if: steps.cherry-pick.outcome == 'success' && steps.cherry-pick.outputs.existing_pr_url != ''
183+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
184+
with:
185+
token: ${{ secrets.SBR_BOT_TOKEN }}
186+
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
187+
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
188+
body: |
189+
ℹ️ **Cherry-pick to `${{ matrix.branch }}` already exists!**
190+
191+
A pull request for this cherry-pick already exists: #${{ steps.cherry-pick.outputs.existing_pr_number }}
192+
193+
**PR**: ${{ steps.cherry-pick.outputs.existing_pr_url }}
194+
162195
- name: Comment on success
163-
if: steps.cherry-pick.outcome == 'success'
196+
if: steps.cherry-pick.outcome == 'success' && steps.cherry-pick.outputs.existing_pr_url == ''
164197
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
165198
with:
166199
token: ${{ secrets.SBR_BOT_TOKEN }}

0 commit comments

Comments
 (0)