|
13 | 13 | jobs: |
14 | 14 | opencode: |
15 | 15 | if: | |
16 | | - (github.event_name == 'issue_comment' && contains(github.event.comment.body, '/opencode')) || |
17 | | - (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '/opencode')) || |
18 | | - (github.event_name == 'pull_request_review' && contains(github.event.review.body, '/opencode')) || |
19 | | - (github.event_name == 'issues' && contains(github.event.issue.body, '/opencode')) |
| 16 | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '/opencode:')) || |
| 17 | + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '/opencode:')) || |
| 18 | + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '/opencode:')) || |
| 19 | + (github.event_name == 'issues' && contains(github.event.issue.body, '/opencode:')) |
20 | 20 | runs-on: ubuntu-latest |
21 | 21 | permissions: |
22 | 22 | id-token: write |
23 | | - contents: read |
24 | | - pull-requests: read |
25 | | - issues: read |
| 23 | + contents: write |
| 24 | + pull-requests: write |
| 25 | + issues: write |
26 | 26 | steps: |
27 | 27 | - name: Checkout repository |
28 | 28 | uses: actions/checkout@v6 |
29 | 29 | with: |
30 | 30 | fetch-depth: 1 |
31 | 31 | persist-credentials: false |
32 | 32 |
|
| 33 | + - name: Extract agent name |
| 34 | + id: agent |
| 35 | + env: |
| 36 | + COMMENT_BODY: ${{ github.event.comment.body || github.event.review.body || github.event.issue.body }} |
| 37 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + run: | |
| 39 | + AGENT=$(echo "$COMMENT_BODY" | grep -oP '/opencode:\K[A-Za-z]+' | head -1) |
| 40 | + if [[ ! "$AGENT" =~ ^(Build|Plan)$ ]]; then |
| 41 | + ERROR_MSG="Error: Invalid agent '$AGENT'. Must be Build or Plan" |
| 42 | + echo "$ERROR_MSG" |
| 43 | +
|
| 44 | + # Post comment with error |
| 45 | + if [ "${{ github.event_name }}" = "issues" ]; then |
| 46 | + NUMBER=${{ github.event.issue.number }} |
| 47 | + else |
| 48 | + NUMBER=${{ github.event.issue.number || github.event.pull_request.number }} |
| 49 | + fi |
| 50 | +
|
| 51 | + curl -s -X POST \ |
| 52 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 53 | + -H "Accept: application/vnd.github.v3+json" \ |
| 54 | + "https://api.github.com/repos/${{ github.repository }}/issues/$NUMBER/comments" \ |
| 55 | + -d "{\"body\": \"❌ $ERROR_MSG\"}" |
| 56 | +
|
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + echo "agent=$AGENT" >> $GITHUB_OUTPUT |
| 60 | +
|
33 | 61 | - name: Run opencode |
34 | 62 | uses: anomalyco/opencode/github@latest |
35 | 63 | env: |
36 | 64 | OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }} |
| 65 | + OPENCODE_PERMISSION: '{"bash": "deny"}' |
37 | 66 | with: |
38 | 67 | model: opencode-go/glm-5 |
| 68 | + agent: ${{ steps.agent.outputs.agent }} |
0 commit comments