Skip to content

Commit a309552

Browse files
Label superseded dependabot updates as duplicates
Issue gh-14484
1 parent 9189916 commit a309552

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Mark Duplicate PRs
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
check_duplicate_prs:
9+
runs-on: ubuntu-latest
10+
if: github.event.pull_request.merged == 'true' && github.event.pull_request.user.login == 'dependabot[bot]'
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v4
14+
15+
- name: Extract Dependency Name from PR Title
16+
id: extract
17+
run: |
18+
PR_TITLE="${{ github.event.pull_request.title }}"
19+
DEPENDENCY_NAME=$(echo "$PR_TITLE" | awk -F ' from ' '{print $1}')
20+
echo "dependency_name=$DEPENDENCY_NAME" >> $GITHUB_OUTPUT
21+
22+
- name: Find PRs
23+
id: find_duplicates
24+
env:
25+
DEPENDENCY_NAME: ${{ steps.extract.outputs.dependency_name }}
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
run: |
28+
PRS=$(gh pr list --search "milestone:${{ github.event.pull_request.milestone.title }} is:merged $DEPENDENCY_NAME" --json number --jq 'map(.number) | join(",")')
29+
echo "prs=$PRS" >> $GITHUB_OUTPUT
30+
31+
- name: Label Duplicate PRs
32+
if: steps.find_duplicates.outputs.prs != ''
33+
env:
34+
PRS: ${{ steps.find_duplicates.outputs.prs }}
35+
CURRENT_PR_NUMBER: ${{ github.event.pull_request.number }}
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
shell: bash
38+
run: |
39+
for i in ${PRS//,/ }
40+
do
41+
if [ ! $i -eq "$CURRENT_PR_NUMBER" ]; then
42+
echo "Marking PR $i as duplicate"
43+
gh pr edit "$i" --add-label "status: duplicate"
44+
gh pr comment "$i" --body "Duplicate of #$CURRENT_PR_NUMBER"
45+
fi
46+
done

0 commit comments

Comments
 (0)