mark-duplicate-dependabot-prs.yml 1.6 KB

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