mark-duplicate-dependabot-prs.yml 1.8 KB

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