review.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. name: Guidelines Check
  2. on:
  3. issue_comment:
  4. types: [created]
  5. jobs:
  6. check-guidelines:
  7. if: |
  8. github.event.issue.pull_request &&
  9. startsWith(github.event.comment.body, '/review') &&
  10. contains(fromJson('["OWNER","MEMBER"]'), github.event.comment.author_association)
  11. runs-on: blacksmith-4vcpu-ubuntu-2404
  12. permissions:
  13. contents: read
  14. pull-requests: write
  15. steps:
  16. - name: Get PR number
  17. id: pr-number
  18. run: |
  19. if [ "${{ github.event_name }}" = "pull_request_target" ]; then
  20. echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
  21. else
  22. echo "number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
  23. fi
  24. - name: Checkout repository
  25. uses: actions/checkout@v4
  26. with:
  27. fetch-depth: 1
  28. - uses: ./.github/actions/setup-bun
  29. - name: Install opencode
  30. run: curl -fsSL https://opencode.ai/install | bash
  31. - name: Get PR details
  32. id: pr-details
  33. run: |
  34. gh api /repos/${{ github.repository }}/pulls/${{ steps.pr-number.outputs.number }} > pr_data.json
  35. echo "title=$(jq -r .title pr_data.json)" >> $GITHUB_OUTPUT
  36. echo "sha=$(jq -r .head.sha pr_data.json)" >> $GITHUB_OUTPUT
  37. env:
  38. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  39. - name: Check PR guidelines compliance
  40. env:
  41. ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
  42. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  43. OPENCODE_PERMISSION: '{ "bash": { "gh*": "allow", "gh pr review*": "deny", "*": "deny" } }'
  44. PR_TITLE: ${{ steps.pr-details.outputs.title }}
  45. run: |
  46. PR_BODY=$(jq -r .body pr_data.json)
  47. opencode run -m anthropic/claude-opus-4-5 "A new pull request has been created: '${PR_TITLE}'
  48. <pr-number>
  49. ${{ steps.pr-number.outputs.number }}
  50. </pr-number>
  51. <pr-description>
  52. $PR_BODY
  53. </pr-description>
  54. Please check all the code changes in this pull request against the style guide, also look for any bugs if they exist. Diffs are important but make sure you read the entire file to get proper context. Make it clear the suggestions are merely suggestions and the human can decide what to do
  55. When critiquing code against the style guide, be sure that the code is ACTUALLY in violation, don't complain about else statements if they already use early returns there. You may complain about excessive nesting though, regardless of else statement usage.
  56. When critiquing code style don't be a zealot, we don't like "let" statements but sometimes they are the simpliest option, if someone does a bunch of nesting with let, they should consider using iife (see packages/opencode/src/util.iife.ts)
  57. Use the gh cli to create comments on the files for the violations. Try to leave the comment on the exact line number. If you have a suggested fix include it in a suggestion code block.
  58. Command MUST be like this.
  59. \`\`\`
  60. gh api \
  61. --method POST \
  62. -H \"Accept: application/vnd.github+json\" \
  63. -H \"X-GitHub-Api-Version: 2022-11-28\" \
  64. /repos/${{ github.repository }}/pulls/${{ steps.pr-number.outputs.number }}/comments \
  65. -f 'body=[summary of issue]' -f 'commit_id=${{ steps.pr-details.outputs.sha }}' -f 'path=[path-to-file]' -F \"line=[line]\" -f 'side=RIGHT'
  66. \`\`\`
  67. Only create comments for actual violations. If the code follows all guidelines, comment on the issue using gh cli: 'lgtm' AND NOTHING ELSE!!!!."