|
2 | 2 |
|
3 | 3 | A GitHub Action that integrates [opencode](https://opencode.ai) directly into your GitHub workflow. |
4 | 4 |
|
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. |
6 | 6 |
|
7 | 7 | ## Features |
8 | 8 |
|
9 | 9 | #### Triage and explain issues |
10 | 10 |
|
11 | | -``` |
12 | | -hey opencode, explain this issue |
| 11 | +```bash |
| 12 | +/opencode explain this issue |
13 | 13 | ``` |
14 | 14 |
|
15 | 15 | #### Fix or implement issues - opencode will create a PR with the changes. |
16 | 16 |
|
17 | | -``` |
18 | | -hi opencode, fix this |
| 17 | +```bash |
| 18 | +/opencode fix this |
19 | 19 | ``` |
20 | 20 |
|
21 | | -- Review PRs and make changes |
| 21 | +#### Review PRs and make changes |
22 | 22 |
|
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 |
25 | 25 | ``` |
26 | 26 |
|
27 | 27 | ## Installation |
28 | 28 |
|
29 | 29 | Run the following command in the terminal from your GitHub repo: |
30 | 30 |
|
31 | | -``` |
| 31 | +```bash |
32 | 32 | opencode github install |
33 | 33 | ``` |
34 | 34 |
|
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. |
36 | 36 |
|
37 | 37 | ### Manual Setup |
38 | 38 |
|
39 | 39 | 1. Install the GitHub app https://github.com/apps/opencode-agent. Make sure it is installed on the target repository. |
40 | 40 | 2. Add the following workflow file to `.github/workflows/opencode.yml` in your repo. Set the appropriate `model` and required API keys in `env`. |
41 | 41 |
|
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 | + ``` |
72 | 70 |
|
73 | 71 | 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. |
74 | 72 |
|
@@ -82,32 +80,32 @@ To test locally: |
82 | 80 |
|
83 | 81 | 1. Navigate to a test repo (e.g. `hello-world`): |
84 | 82 |
|
85 | | -``` |
86 | | -cd hello-world |
87 | | -``` |
| 83 | + ```bash |
| 84 | + cd hello-world |
| 85 | + ``` |
88 | 86 |
|
89 | 87 | 2. Run: |
90 | 88 |
|
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 | + ``` |
99 | 97 |
|
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). |
106 | 104 |
|
107 | | -#### Issue comment event |
| 105 | +### Issue comment event |
108 | 106 |
|
109 | 107 | ``` |
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"}}}' |
111 | 109 | ``` |
112 | 110 |
|
113 | 111 | Replace: |
@@ -118,16 +116,16 @@ Replace: |
118 | 116 | - `"number":4` with the GitHub issue id |
119 | 117 | - `"body":"hey opencode, summarize thread"` with comment body |
120 | 118 |
|
121 | | -#### Issue comment with image attachment. |
| 119 | +### Issue comment with image attachment. |
122 | 120 |
|
123 | 121 | ``` |
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 "}}}' |
| 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 "}}}' |
125 | 123 | ``` |
126 | 124 |
|
127 | 125 | 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). |
128 | 126 |
|
129 | | -#### PR comment event |
| 127 | +### PR comment event |
130 | 128 |
|
131 | 129 | ``` |
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"}}}' |
133 | 131 | ``` |