pr-management.yml 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. name: pr-management
  2. on:
  3. pull_request_target:
  4. types: [opened]
  5. jobs:
  6. check-duplicates:
  7. runs-on: blacksmith-4vcpu-ubuntu-2404
  8. permissions:
  9. contents: read
  10. pull-requests: write
  11. steps:
  12. - name: Check team membership
  13. id: team-check
  14. run: |
  15. LOGIN="${{ github.event.pull_request.user.login }}"
  16. ASSOCIATION="${{ github.event.pull_request.author_association }}"
  17. if [ "$LOGIN" = "opencode-agent[bot]" ] || [ "$ASSOCIATION" = "OWNER" ] || [ "$ASSOCIATION" = "MEMBER" ] || [ "$ASSOCIATION" = "COLLABORATOR" ]; then
  18. echo "is_team=true" >> "$GITHUB_OUTPUT"
  19. echo "Skipping: $LOGIN is a team member or bot"
  20. else
  21. echo "is_team=false" >> "$GITHUB_OUTPUT"
  22. fi
  23. - name: Checkout repository
  24. if: steps.team-check.outputs.is_team != 'true'
  25. uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
  26. with:
  27. fetch-depth: 1
  28. ref: ${{ github.event.pull_request.base.sha }}
  29. - name: Setup Bun
  30. if: steps.team-check.outputs.is_team != 'true'
  31. uses: ./.github/actions/setup-bun
  32. - name: Install dependencies
  33. if: steps.team-check.outputs.is_team != 'true'
  34. run: bun install
  35. - name: Install opencode
  36. if: steps.team-check.outputs.is_team != 'true'
  37. run: curl -fsSL https://opencode.ai/install | bash
  38. - name: Build prompt
  39. if: steps.team-check.outputs.is_team != 'true'
  40. env:
  41. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  42. PR_NUMBER: ${{ github.event.pull_request.number }}
  43. run: |
  44. {
  45. echo "Check for duplicate PRs related to this new PR:"
  46. echo ""
  47. echo "CURRENT_PR_NUMBER: $PR_NUMBER"
  48. echo ""
  49. echo "Title: $(gh pr view "$PR_NUMBER" --json title --jq .title)"
  50. echo ""
  51. echo "Description:"
  52. gh pr view "$PR_NUMBER" --json body --jq .body
  53. } > pr_info.txt
  54. - name: Check for duplicate PRs
  55. if: steps.team-check.outputs.is_team != 'true'
  56. env:
  57. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  58. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  59. PR_NUMBER: ${{ github.event.pull_request.number }}
  60. run: |
  61. COMMENT=$(bun script/duplicate-pr.ts -f pr_info.txt "Check the attached file for PR details and search for duplicates")
  62. if [ "$COMMENT" != "No duplicate PRs found" ]; then
  63. gh pr comment "$PR_NUMBER" --body "_The following comment was made by an LLM, it may be inaccurate:_
  64. $COMMENT"
  65. fi
  66. add-contributor-label:
  67. runs-on: ubuntu-latest
  68. permissions:
  69. pull-requests: write
  70. issues: write
  71. steps:
  72. - name: Add Contributor Label
  73. uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
  74. with:
  75. script: |
  76. const isPR = !!context.payload.pull_request;
  77. const issueNumber = isPR ? context.payload.pull_request.number : context.payload.issue.number;
  78. const authorAssociation = isPR ? context.payload.pull_request.author_association : context.payload.issue.author_association;
  79. if (authorAssociation === 'CONTRIBUTOR') {
  80. await github.rest.issues.addLabels({
  81. owner: context.repo.owner,
  82. repo: context.repo.repo,
  83. issue_number: issueNumber,
  84. labels: ['contributor']
  85. });
  86. }