mark-duplicate-dependabot-prs.yml 1.8 KB

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