Skip to content

Commit 50cd82f

Browse files
ci: Add agents Build and Plan to opencode on GitHub (#607)
Usage: type `/opencode:Plan` or `/opencode:Build` followed by a prompt.
1 parent 08e1b41 commit 50cd82f

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

.github/workflows/opencode.yml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,56 @@ on:
1313
jobs:
1414
opencode:
1515
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:'))
2020
runs-on: ubuntu-latest
2121
permissions:
2222
id-token: write
23-
contents: read
24-
pull-requests: read
25-
issues: read
23+
contents: write
24+
pull-requests: write
25+
issues: write
2626
steps:
2727
- name: Checkout repository
2828
uses: actions/checkout@v6
2929
with:
3030
fetch-depth: 1
3131
persist-credentials: false
3232

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+
3361
- name: Run opencode
3462
uses: anomalyco/opencode/github@latest
3563
env:
3664
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
65+
OPENCODE_PERMISSION: '{"bash": "deny"}'
3766
with:
3867
model: opencode-go/glm-5
68+
agent: ${{ steps.agent.outputs.agent }}

0 commit comments

Comments
 (0)