Skip to content

Commit cbace0a

Browse files
davanstrienpcuencaWauplin
authored
Add guide for automating code review with OpenCode and Inference Providers (#2023)
* Add guide for automating code review with OpenCode and IP * Add guide for automating code review with GitHub Actions * formatting * Update docs/inference-providers/guides/github-actions-code-review.md Co-authored-by: Pedro Cuenca <[email protected]> * Update docs/inference-providers/guides/github-actions-code-review.md Co-authored-by: Lucain <[email protected]> * Add images for visual examples in GitHub Actions code review guide * Update image URLs in GitHub Actions code review guide to use main branch --------- Co-authored-by: Pedro Cuenca <[email protected]> Co-authored-by: Lucain <[email protected]>
1 parent 449d330 commit cbace0a

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed

docs/inference-providers/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
title: Build an Image Editor
2828
- local: guides/vscode
2929
title: VS Code with GitHub Copilot
30+
- local: guides/github-actions-code-review
31+
title: Automating Code Review with GitHub Actions
3032

3133
- local: tasks/index
3234
title: Inference Tasks
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Automating Code Review with GitHub Actions
2+
3+
[OpenCode](https://opencode.ai) is an AI coding agent that runs in your terminal and can work with open models via Hugging Face Inference Providers.
4+
5+
You can also install OpenCode as a GitHub App to help automate GitHub workflows!
6+
7+
In less than 5 minutes, you can set it up to respond to issues and pull requests using powerful open source language models.
8+
9+
<div class="flex justify-center">
10+
<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/recording-light.gif"/>
11+
<img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/recording-dark.gif"/>
12+
</div>
13+
14+
This guide shows you how to use Hugging Face Inference Providers with OpenCode to power GitHub automation. You'll be able to triage issues, implement features, and review code using models like DeepSeek, GLM-4.5, and Kimi K2.
15+
16+
> [!TIP]
17+
> This guide assumes you have a Hugging Face account and a GitHub repository. You can create a free Hugging Face account at [huggingface.co](https://huggingface.co).
18+
19+
## What the OpenCode GitHub App Does
20+
21+
Once set up, OpenCode will respond to `/oc` or `/opencode` commands in GitHub issues and pull requests:
22+
23+
- **Triage and explain issues** - Ask OpenCode to analyze an issue and explain it
24+
- **Implement features** - Request a fix or feature, and OpenCode creates a PR with the changes
25+
- **Review and modify PRs** - Request changes on pull requests and OpenCode commits them
26+
27+
The entire workflow runs securely in your GitHub Actions runners, and you maintain full control over which repositories you install the OpenCode GitHub app on.
28+
29+
## Step 1: Install OpenCode
30+
31+
First, install OpenCode on your local machine following the [installation instructions](https://opencode.ai/docs/#install).
32+
33+
## Step 2: Configure OpenCode for GitHub
34+
35+
Navigate to your local clone of your GitHub repository and run the setup command:
36+
37+
```bash
38+
cd your-repository
39+
opencode github install
40+
```
41+
42+
This triggers an interactive setup process that will guide you through:
43+
44+
1. **Installing the GitHub app** - Your browser opens to authorize OpenCode for your repositories. You can choose specific repositories or all repositories.
45+
2. **Selecting a provider** - Choose **Hugging Face** from the list
46+
3. **Choosing a model** - Select a model like **GLM-4.5-Air** or **Kimi-K2-Instruct**
47+
4. **Creating the workflow** - Generates `.github/workflows/opencode.yml` automatically
48+
49+
Once the `.github/workflows/opencode.yml` file is created, you'll need to commit and push it to your repository:
50+
51+
```bash
52+
git add .github/workflows/opencode.yml
53+
git commit -m "Add OpenCode workflow"
54+
git push
55+
```
56+
57+
After the setup completes, you'll need to add your Hugging Face token as a repository secret:
58+
59+
1. Get a token from your [Hugging Face settings](https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained). The token needs permissions to `Make calls to Inference Providers`.
60+
2. In your GitHub repository, go to **Settings → Secrets and variables → Actions**
61+
3. Click **New repository secret**
62+
4. Name it `HF_TOKEN` and paste your token
63+
64+
> [!TIP]
65+
> Make sure your Hugging Face token has Inference Providers permissions enabled. We recommend creating a separate token specifically for OpenCode usage.
66+
67+
## Step 3: Try It Out
68+
69+
Once your workflow is set up and your token is configured, test it by commenting on any issue:
70+
71+
```
72+
/oc summarize
73+
```
74+
75+
OpenCode will analyze the issue and provide a summary. Here are other commands you can try:
76+
77+
**Explain an issue:**
78+
79+
```
80+
/opencode explain this issue
81+
```
82+
83+
**Implement a fix:**
84+
85+
OpenCode creates a new branch, implements the changes, and opens a pull request.
86+
87+
**Request changes on a PR:**
88+
89+
```
90+
/oc please add error handling
91+
```
92+
93+
> [!TIP]
94+
> Use `/oc` (short) or `/opencode` (long) to trigger commands. OpenCode understands natural language, so feel free to be specific about what you need.
95+
96+
## Security Considerations
97+
98+
> [!WARNING]
99+
> On public repositories, anyone can trigger the bot by commenting `/oc` or `/opencode`. This could lead to unexpected inference costs or unwanted PRs. Consider:
100+
>
101+
> - **Using a separate Hugging Face token** specifically for OpenCode (not your main token), so you can revoke it if needed without affecting other services
102+
> - Monitoring your Hugging Face usage to track costs
103+
> - Adding workflow conditions to restrict who can trigger the bot (e.g., only repository collaborators)
104+
> - Starting with a private repository or test repo to control access
105+
106+
## Example Workflow in Action
107+
108+
Here's a real example from a [fork of the Hugging Face datasets repository](https://github.com/davanstrien/datasets). The issue requests adding `uv` installation support:
109+
110+
<div class="flex justify-center">
111+
<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/opencode-example-issue-light.png">
112+
<img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/opencode-example-issue-dark.png"/>
113+
</div>
114+
115+
When someone comments `/oc fix this`, OpenCode analyzes the issue, creates a new branch, implements the changes, and opens a pull request:
116+
117+
<div class="flex justify-center">
118+
<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/opencode-bot-created-pr-light.png"/>
119+
<img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/opencode-bot-created-pr-dark.png"/>
120+
</div>
121+
122+
The PR includes all the necessary changes:
123+
124+
<div class="flex justify-center">
125+
<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/opencode-pr-diff-light.png"/>
126+
<img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/inference-providers-github-actions-code/opencode-pr-diff-dark.png"/>
127+
</div>
128+
129+
## Switching Models
130+
131+
Different models offer different trade-offs between speed, cost, and capability. You can experiment with various models by editing the workflow file.
132+
133+
Edit `.github/workflows/opencode.yml` and update the `model` parameter:
134+
135+
```yaml
136+
with:
137+
model: huggingface/deepseek-ai/DeepSeek-V3 # Powerful reasoning
138+
# or
139+
model: huggingface/zai-org/GLM-4.5-Air # Balanced performance
140+
```
141+
142+
Commit and push the changes:
143+
144+
```bash
145+
git add .github/workflows/opencode.yml
146+
git commit -m "Switch to the DeepSeek model"
147+
git push
148+
```
149+
150+
## Understanding the Workflow
151+
152+
The setup wizard generates `.github/workflows/opencode.yml`, which defines when and how OpenCode runs:
153+
154+
```yaml
155+
name: opencode
156+
157+
on:
158+
issue_comment:
159+
types: [created] # Trigger on new comments
160+
161+
jobs:
162+
opencode:
163+
# Only run if comment contains /oc or /opencode
164+
if: |
165+
contains(github.event.comment.body, ' /oc') ||
166+
startsWith(github.event.comment.body, '/oc') ||
167+
contains(github.event.comment.body, ' /opencode') ||
168+
startsWith(github.event.comment.body, '/opencode')
169+
170+
runs-on: ubuntu-latest
171+
172+
permissions:
173+
id-token: write # Required for OpenCode authentication
174+
contents: read # Read repository contents
175+
pull-requests: read # Access PR information
176+
issues: read # Access issue information
177+
178+
steps:
179+
- name: Checkout repository
180+
uses: actions/checkout@v4
181+
182+
- name: Run opencode
183+
uses: sst/opencode/github@latest
184+
env:
185+
HF_TOKEN: ${{ secrets.HF_TOKEN }} # Your Hugging Face token
186+
with:
187+
model: huggingface/zai-org/GLM-4.5-Air # The model to use
188+
```
189+
190+
The workflow triggers whenever someone comments on an issue or PR with `/oc` or `/opencode`, checks out your repository code, and runs OpenCode with your chosen model from Hugging Face Inference Providers.
191+
192+
## Next Steps
193+
194+
- Explore the [OpenCode GitHub documentation](https://opencode.ai/docs/github/) for advanced configuration
195+
- Browse [models available through Inference Providers](https://huggingface.co/models?pipeline_tag=text-generation&inference_provider=cerebras,together,fireworks-ai,nebius,novita,sambanova,groq,hyperbolic,nscale,fal-ai,cohere,replicate,scaleway&sort=trending) to find the best model for your needs
196+
- Try OpenCode in a private repository first to test with controlled access

0 commit comments

Comments
 (0)