mark-duplicate-dependabot-prs.yml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. DEPENDENCY_NAME: ${{ steps.extract.outputs.dependency_name }}
  22. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  23. run: |
  24. PRS=$(gh pr list --search 'milestone:${{ github.event.pull_request.milestone.title }} is:merged in:title "$DEPENDENCY_NAME"' --json number --jq 'map(.number) | join(",")')
  25. echo "prs=$PRS" >> $GITHUB_OUTPUT
  26. - name: Label Duplicate PRs
  27. if: steps.find_duplicates.outputs.prs != ''
  28. env:
  29. PRS: ${{ steps.find_duplicates.outputs.prs }}
  30. CURRENT_PR_NUMBER: ${{ github.event.pull_request.number }}
  31. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  32. shell: bash
  33. run: |
  34. for i in ${PRS//,/ }
  35. do
  36. if [ ! $i -eq "$CURRENT_PR_NUMBER" ]; then
  37. echo "Marking PR $i as duplicate"
  38. gh pr edit "$i" --add-label "status: duplicate"
  39. gh pr comment "$i" --body "Duplicate of #$CURRENT_PR_NUMBER"
  40. fi
  41. done