pr-management.yml 3.1 KB

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