Skip to content

Commit c3c9003

Browse files
committed
ci: add pr review
1 parent 921b980 commit c3c9003

2 files changed

Lines changed: 89 additions & 57 deletions

File tree

.github/guidelines-check.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/review.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Guidelines Check
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
issue_comment:
7+
types: [created]
8+
9+
jobs:
10+
check-guidelines:
11+
if: |
12+
github.event_name == 'pull_request_target' ||
13+
(github.event_name == 'issue_comment' &&
14+
github.event.issue.pull_request &&
15+
startsWith(github.event.comment.body, '/review'))
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
steps:
21+
- name: Check if user has write permission
22+
if: github.event_name == 'issue_comment'
23+
run: |
24+
PERMISSION=$(gh api /repos/${{ github.repository }}/collaborators/${{ github.event.comment.user.login }}/permission --jq '.permission')
25+
if [[ "$PERMISSION" != "write" && "$PERMISSION" != "admin" ]]; then
26+
echo "User does not have write permission"
27+
exit 1
28+
fi
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Get PR number
33+
id: pr-number
34+
run: |
35+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
36+
echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
37+
else
38+
echo "number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
39+
fi
40+
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 1
45+
46+
- name: Install opencode
47+
run: curl -fsSL https://opencode.ai/install | bash
48+
49+
- name: Get PR details
50+
id: pr-details
51+
run: |
52+
PR_DATA=$(gh api /repos/${{ github.repository }}/pulls/${{ steps.pr-number.outputs.number }})
53+
echo "title=$(echo "$PR_DATA" | jq -r .title)" >> $GITHUB_OUTPUT
54+
echo "body=$(echo "$PR_DATA" | jq -r .body)" >> $GITHUB_OUTPUT
55+
echo "sha=$(echo "$PR_DATA" | jq -r .head.sha)" >> $GITHUB_OUTPUT
56+
env:
57+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Check PR guidelines compliance
60+
env:
61+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
OPENCODE_PERMISSION: '{ "bash": { "gh*": "allow", "gh pr review*": "deny", "*": "deny" } }'
64+
run: |
65+
opencode run -m anthropic/claude-sonnet-4-5 "A new pull request has been created: '${{ steps.pr-details.outputs.title }}'
66+
67+
<pr-number>
68+
${{ steps.pr-number.outputs.number }}
69+
</pr-number>
70+
71+
<pr-description>
72+
${{ steps.pr-details.outputs.body }}
73+
</pr-description>
74+
75+
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
76+
77+
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.
78+
79+
Command MUST be like this.
80+
```
81+
gh api \
82+
--method POST \
83+
-H "Accept: application/vnd.github+json" \
84+
-H "X-GitHub-Api-Version: 2022-11-28" \
85+
/repos/${{ github.repository }}/pulls/${{ steps.pr-number.outputs.number }}/comments \
86+
-f 'body=[summary of issue]' -f 'commit_id=${{ steps.pr-details.outputs.sha }}' -f 'path=[path-to-file]' -F "line=[line]" -f 'side=RIGHT'
87+
```
88+
89+
Only create comments for actual violations. If the code follows all guidelines, don't run any gh commands."

0 commit comments

Comments
 (0)