Skip to content

Commit a007d65

Browse files
author
Frank
committed
wip: github actions
1 parent 2c924b9 commit a007d65

File tree

5 files changed

+164
-82
lines changed

5 files changed

+164
-82
lines changed

.github/workflows/opencode.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ on:
77
jobs:
88
opencode:
99
if: |
10-
startsWith(github.event.comment.body, 'opencode') ||
11-
startsWith(github.event.comment.body, 'hi opencode') ||
12-
startsWith(github.event.comment.body, 'hey opencode') ||
13-
contains(github.event.comment.body, '@opencode-agent')
10+
contains(github.event.comment.body, '/oc') ||
11+
contains(github.event.comment.body, '/opencode')
1412
runs-on: ubuntu-latest
1513
permissions:
1614
id-token: write

github/README.md

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,71 @@
22

33
A GitHub Action that integrates [opencode](https://opencode.ai) directly into your GitHub workflow.
44

5-
Start your comment with `hey opencode`, and opencode will take action via your GitHub Actions runner.
5+
Mention `/opencode` in your comment, and opencode will execute tasks within your GitHub Actions runner.
66

77
## Features
88

99
#### Triage and explain issues
1010

11-
```
12-
hey opencode, explain this issue
11+
```bash
12+
/opencode explain this issue
1313
```
1414

1515
#### Fix or implement issues - opencode will create a PR with the changes.
1616

17-
```
18-
hi opencode, fix this
17+
```bash
18+
/opencode fix this
1919
```
2020

21-
- Review PRs and make changes
21+
#### Review PRs and make changes
2222

23-
```
24-
Delete the attachment from S3 when the note is removed @opencode-agent
23+
```bash
24+
Delete the attachment from S3 when the note is removed /oc
2525
```
2626

2727
## Installation
2828

2929
Run the following command in the terminal from your GitHub repo:
3030

31-
```
31+
```bash
3232
opencode github install
3333
```
3434

35-
This will walk you through installing the GitHub app, configuring the workflow, and setting up secrets.
35+
This will walk you through installing the GitHub app, creating the workflow, and setting up secrets.
3636

3737
### Manual Setup
3838

3939
1. Install the GitHub app https://github.com/apps/opencode-agent. Make sure it is installed on the target repository.
4040
2. Add the following workflow file to `.github/workflows/opencode.yml` in your repo. Set the appropriate `model` and required API keys in `env`.
4141

42-
```yml
43-
name: opencode
44-
45-
on:
46-
issue_comment:
47-
types: [created]
48-
49-
jobs:
50-
opencode:
51-
if: |
52-
startsWith(github.event.comment.body, 'opencode') ||
53-
startsWith(github.event.comment.body, 'hi opencode') ||
54-
startsWith(github.event.comment.body, 'hey opencode') ||
55-
contains(github.event.comment.body, '@opencode-agent')
56-
runs-on: ubuntu-latest
57-
permissions:
58-
id-token: write
59-
steps:
60-
- name: Checkout repository
61-
uses: actions/checkout@v4
62-
with:
63-
fetch-depth: 1
64-
65-
- name: Run opencode
66-
uses: sst/opencode/github@latest
67-
env:
68-
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
69-
with:
70-
model: anthropic/claude-sonnet-4-20250514
71-
```
42+
```yml
43+
name: opencode
44+
45+
on:
46+
issue_comment:
47+
types: [created]
48+
49+
jobs:
50+
opencode:
51+
if: |
52+
contains(github.event.comment.body, '/oc') ||
53+
contains(github.event.comment.body, '/opencode')
54+
runs-on: ubuntu-latest
55+
permissions:
56+
id-token: write
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
with:
61+
fetch-depth: 1
62+
63+
- name: Run opencode
64+
uses: sst/opencode/github@latest
65+
env:
66+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
67+
with:
68+
model: anthropic/claude-sonnet-4-20250514
69+
```
7270
7371
3. Store the API keys in secrets. In your organization or project **settings**, expand **Secrets and variables** on the left and select **Actions**. Add the required API keys.
7472
@@ -82,32 +80,32 @@ To test locally:
8280
8381
1. Navigate to a test repo (e.g. `hello-world`):
8482

85-
```
86-
cd hello-world
87-
```
83+
```bash
84+
cd hello-world
85+
```
8886

8987
2. Run:
9088

91-
```
92-
MODEL=anthropic/claude-sonnet-4-20250514 \
93-
ANTHROPIC_API_KEY=sk-ant-api03-1234567890 \
94-
GITHUB_RUN_ID=dummy \
95-
bun /path/to/opencode/packages/opencode/src/index.ts github run \
96-
--token 'github_pat_1234567890' \
97-
--event '{"eventName":"issue_comment",...}'
98-
```
89+
```bash
90+
MODEL=anthropic/claude-sonnet-4-20250514 \
91+
ANTHROPIC_API_KEY=sk-ant-api03-1234567890 \
92+
GITHUB_RUN_ID=dummy \
93+
bun /path/to/opencode/packages/opencode/src/index.ts github run \
94+
--token 'github_pat_1234567890' \
95+
--event '{"eventName":"issue_comment",...}'
96+
```
9997

100-
- `MODEL`: The model used by opencode. Same as the `MODEL` defined in the GitHub workflow.
101-
- `ANTHROPIC_API_KEY`: Your model provider API key. Same as the keys defined in the GitHub workflow.
102-
- `GITHUB_RUN_ID`: Dummy value to emulate GitHub action environment.
103-
- `/path/to/opencode`: Path to your cloned opencode repo. `bun /path/to/opencode/packages/opencode/src/index.ts` runs your local version of `opencode`.
104-
- `--token`: A GitHub persontal access token. This token is used to verify you have `admin` or `write` access to the test repo. Generate a token [here](https://github.com/settings/personal-access-tokens).
105-
- `--event`: Mock GitHub event payload (see templates below).
98+
- `MODEL`: The model used by opencode. Same as the `MODEL` defined in the GitHub workflow.
99+
- `ANTHROPIC_API_KEY`: Your model provider API key. Same as the keys defined in the GitHub workflow.
100+
- `GITHUB_RUN_ID`: Dummy value to emulate GitHub action environment.
101+
- `/path/to/opencode`: Path to your cloned opencode repo. `bun /path/to/opencode/packages/opencode/src/index.ts` runs your local version of `opencode`.
102+
- `--token`: A GitHub persontal access token. This token is used to verify you have `admin` or `write` access to the test repo. Generate a token [here](https://github.com/settings/personal-access-tokens).
103+
- `--event`: Mock GitHub event payload (see templates below).
106104

107-
#### Issue comment event
105+
### Issue comment event
108106

109107
```
110-
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
108+
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
111109
```
112110
113111
Replace:
@@ -118,16 +116,16 @@ Replace:
118116
- `"number":4` with the GitHub issue id
119117
- `"body":"hey opencode, summarize thread"` with comment body
120118
121-
#### Issue comment with image attachment.
119+
### Issue comment with image attachment.
122120
123121
```
124-
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, what is in my image ![Image](https://github.com/user-attachments/assets/xxxxxxxx)"}}}'
122+
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, what is in my image ![Image](https://github.com/user-attachments/assets/xxxxxxxx)"}}}'
125123
```
126124
127125
Replace the image URL `https://github.com/user-attachments/assets/xxxxxxxx` with a valid GitHub attachment (you can generate one by commenting with an image in any issue).
128126
129-
#### PR comment event
127+
### PR comment event
130128
131129
```
132-
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4,"pull_request":{}},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
130+
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4,"pull_request":{}},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
133131
```

github/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ branding:
77
inputs:
88
model:
99
description: "Model to use"
10-
required: false
10+
required: true
1111

1212
share:
1313
description: "Share the opencode session (defaults to true for public repos)"

packages/opencode/src/cli/cmd/github.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,8 @@ on:
316316
jobs:
317317
opencode:
318318
if: |
319-
startsWith(github.event.comment.body, 'opencode') ||
320-
startsWith(github.event.comment.body, 'hi opencode') ||
321-
startsWith(github.event.comment.body, 'hey opencode') ||
322-
contains(github.event.comment.body, '@opencode-agent')
319+
contains(github.event.comment.body, '/oc') ||
320+
contains(github.event.comment.body, '/opencode')
323321
runs-on: ubuntu-latest
324322
permissions:
325323
id-token: write
@@ -508,16 +506,10 @@ export const GithubRunCommand = cmd({
508506

509507
async function getUserPrompt() {
510508
let prompt = (() => {
511-
const body = payload.comment.body
512-
if (body.match("@opencode-agent")) return body
513-
514-
const match = body.match(/^(?:hey|hi)?\s*opencode(?:-agent)?,?\s*(.*)$/is)
515-
if (match?.[1] === undefined)
516-
throw new Error(
517-
"Command must mention @opencode-agent, or start with `opencode`, `hi opencode`, or `hey opencode` followed by instructions",
518-
)
519-
if (match[1] === "") return "Summarize this thread"
520-
return match[1]
509+
const body = payload.comment.body.trim()
510+
if (body === "/opencode" || body === "/oc") return "Summarize this thread"
511+
if (body.includes("/opencode") || body.includes("/oc")) return body
512+
throw new Error("Comments must mention `/opencode` or `/oc`")
521513
})()
522514

523515
// Handle images
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: GitHub
3+
description: Using opencode within GitHub Issues and Pull-Requests
4+
---
5+
6+
opencode integrates directly into your GitHub workflow. Mention `/opencode` in your comment, and opencode will execute tasks within your GitHub Actions runner.
7+
8+
---
9+
10+
## Features
11+
12+
- **Triage Issues**: Ask opencode to look into an issue and explain it to you
13+
- **Fix and Implement**: Ask opencode to fix an issue or implement a feature. And it will work in a new branch and submits a PR with all the changes.
14+
- **Secure**: opencode runs inside your GitHub's runners.
15+
16+
---
17+
18+
## Installation
19+
20+
Run the following command in the terminal from your GitHub repo:
21+
22+
```bash
23+
opencode github install
24+
```
25+
26+
This will walk you through installing the GitHub app, creating the workflow, and setting up secrets.
27+
28+
---
29+
30+
### Manual Setup
31+
32+
1. Install the GitHub app https://github.com/apps/opencode-agent. Make sure it is installed on the target repository.
33+
2. Add the following workflow file to `.github/workflows/opencode.yml` in your repo. Set the appropriate `model` and required API keys in `env`.
34+
35+
```yml
36+
name: opencode
37+
38+
on:
39+
issue_comment:
40+
types: [created]
41+
42+
jobs:
43+
opencode:
44+
if: |
45+
contains(github.event.comment.body, '/oc') ||
46+
contains(github.event.comment.body, '/opencode')
47+
runs-on: ubuntu-latest
48+
permissions:
49+
id-token: write
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 1
55+
56+
- name: Run opencode
57+
uses: sst/opencode/github@latest
58+
env:
59+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
60+
with:
61+
model: anthropic/claude-sonnet-4-20250514
62+
# share: true
63+
```
64+
65+
3. Store the API keys in secrets. In your organization or project **settings**, expand **Secrets and variables** on the left and select **Actions**. Add the required API keys.
66+
67+
---
68+
69+
### Inputs
70+
71+
- `model`: The model used by opencode. Takes the format of `provider/model` (**required**)
72+
- `share`: Share the session. Sessions are shared by default for public repos.
73+
74+
---
75+
76+
### Usage Examples
77+
78+
- Explain an issue
79+
80+
```bash
81+
/opencode explain this issue
82+
```
83+
84+
- Fix an issue - opencode will create a PR with the changes.
85+
86+
```bash
87+
/opencode fix this
88+
```
89+
90+
- Review PRs and make changes
91+
92+
```bash
93+
Delete the attachment from S3 when the note is removed /oc
94+
```

0 commit comments

Comments
 (0)