From c3c9003dbbcff0c93d77ec37897f787b4311416a Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Wed, 3 Dec 2025 12:45:01 -0600 Subject: [PATCH] ci: add pr review --- .github/guidelines-check.yml | 57 ----------------------- .github/workflows/review.yml | 89 ++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 57 deletions(-) delete mode 100644 .github/guidelines-check.yml create mode 100644 .github/workflows/review.yml diff --git a/.github/guidelines-check.yml b/.github/guidelines-check.yml deleted file mode 100644 index 522e52a5b..000000000 --- a/.github/guidelines-check.yml +++ /dev/null @@ -1,57 +0,0 @@ -# -# This file is intentionally in the wrong dir, will move and add later.... -# - -name: Guidelines Check - -on: - # Disabled - uncomment to re-enable - # pull_request_target: - # types: [opened, synchronize] - -jobs: - check-guidelines: - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Install opencode - run: curl -fsSL https://opencode.ai/install | bash - - - name: Check PR guidelines compliance - env: - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - OPENCODE_PERMISSION: '{ "bash": { "gh*": "allow", "gh pr review*": "deny", "*": "deny" } }' - run: | - opencode run -m anthropic/claude-sonnet-4-20250514 "A new pull request has been created: '${{ github.event.pull_request.title }}' - - - ${{ github.event.pull_request.number }} - - - - ${{ github.event.pull_request.body }} - - - Please check all the code changes in this pull request against the guidelines in AGENTS.md file in this repository. 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 - - 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. - - Command MUST be like this. - ``` - gh api \ - --method POST \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/comments \ - -f 'body=[summary of issue]' -f 'commit_id=${{ github.event.pull_request.head.sha }}' -f 'path=[path-to-file]' -F "line=[line]" -f 'side=RIGHT' - ``` - - Only create comments for actual violations. If the code follows all guidelines, don't run any gh commands." diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml new file mode 100644 index 000000000..7bee92d10 --- /dev/null +++ b/.github/workflows/review.yml @@ -0,0 +1,89 @@ +name: Guidelines Check + +on: + pull_request_target: + types: [opened] + issue_comment: + types: [created] + +jobs: + check-guidelines: + if: | + github.event_name == 'pull_request_target' || + (github.event_name == 'issue_comment' && + github.event.issue.pull_request && + startsWith(github.event.comment.body, '/review')) + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Check if user has write permission + if: github.event_name == 'issue_comment' + run: | + PERMISSION=$(gh api /repos/${{ github.repository }}/collaborators/${{ github.event.comment.user.login }}/permission --jq '.permission') + if [[ "$PERMISSION" != "write" && "$PERMISSION" != "admin" ]]; then + echo "User does not have write permission" + exit 1 + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get PR number + id: pr-number + run: | + if [ "${{ github.event_name }}" = "pull_request_target" ]; then + echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT + else + echo "number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT + fi + + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Install opencode + run: curl -fsSL https://opencode.ai/install | bash + + - name: Get PR details + id: pr-details + run: | + PR_DATA=$(gh api /repos/${{ github.repository }}/pulls/${{ steps.pr-number.outputs.number }}) + echo "title=$(echo "$PR_DATA" | jq -r .title)" >> $GITHUB_OUTPUT + echo "body=$(echo "$PR_DATA" | jq -r .body)" >> $GITHUB_OUTPUT + echo "sha=$(echo "$PR_DATA" | jq -r .head.sha)" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check PR guidelines compliance + env: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OPENCODE_PERMISSION: '{ "bash": { "gh*": "allow", "gh pr review*": "deny", "*": "deny" } }' + run: | + opencode run -m anthropic/claude-sonnet-4-5 "A new pull request has been created: '${{ steps.pr-details.outputs.title }}' + + + ${{ steps.pr-number.outputs.number }} + + + + ${{ steps.pr-details.outputs.body }} + + + 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 + + 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. + + Command MUST be like this. + ``` + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ github.repository }}/pulls/${{ steps.pr-number.outputs.number }}/comments \ + -f 'body=[summary of issue]' -f 'commit_id=${{ steps.pr-details.outputs.sha }}' -f 'path=[path-to-file]' -F "line=[line]" -f 'side=RIGHT' + ``` + + Only create comments for actual violations. If the code follows all guidelines, don't run any gh commands."