# opencode Forgejo Action A Forgejo Action that integrates [opencode](https://opencode.ai) directly into your Forgejo Actions workflow. Mention `/opencode` or `/oc` in your comment, and opencode will execute tasks within your Forgejo Actions runner. ## Features ### Explain an issue Leave the following comment on a Forgejo issue. `opencode` will read the entire thread, including all comments, and reply with a clear explanation. ``` /opencode explain this issue ``` ### Fix an issue Leave the following comment on a Forgejo issue. opencode will create a new branch, implement the changes, and open a merge request with the changes. ``` /opencode fix this ``` ### Review MRs and make changes Leave the following comment on a Forgejo MR. opencode will implement the requested change and commit it to the same MR. ``` Delete the attachment from S3 when the note is removed /oc ``` ### Review specific code lines Leave a comment directly on code lines in the MR's "Files" tab. opencode will automatically detect the file, line numbers, and diff context to provide precise responses. ``` [Comment on specific lines in Files tab] /oc add error handling here ``` When commenting on specific lines, opencode receives: - The exact file being reviewed - The specific lines of code - The surrounding diff context - Line number information ## Installation ### Quick setup Add the following workflow file to `.forgejo/workflows/opencode.yml` in your repo. ### Manual setup 1. **Create a PAT** Go to your Forgejo instance → Settings → Applications → Generate Token. Give it `repo` scope (contents, pull-requests, issues). 2. **Add the PAT as a secret** Go to your repository → Settings → Actions → Secrets → New Repository Secret. Add: | Secret name | Value | |---|---| | `FORGEJO_TOKEN` | Your PAT | | `NOMYO_API_KEY` | Your Nomyo API key | 3. **Add the workflow file** Create `.forgejo/workflows/opencode.yml`: ```yaml name: opencode on: issue_comment: types: [created] pull_request_review_comment: types: [created] jobs: opencode: if: | contains(github.event.comment.body, '/oc') || contains(github.event.comment.body, '/opencode') runs-on: ubuntu-latest permissions: id-token: write contents: write pull-requests: write issues: write steps: - uses: actions/checkout@v6 with: fetch-depth: 1 persist-credentials: false - name: Run opencode uses: bitfreedom/opencode/forgejo@latest env: NOMYO_API_KEY: ${{ secrets.NOMYO_API_KEY }} with: model: anthropic/claude-sonnet-4-20250514 forgejo_api_url: https://git.your-instance.com forgejo_token: ${{ secrets.FORGEJO_TOKEN }} ``` 4. **Set the model** Replace `anthropic/claude-sonnet-4-20250514` with your preferred model format: `provider/model`. ## Configuration | Input | Required | Description | |---|---|---| | `model` | Yes | Model to use (format: `provider/model`) | | `forgejo_api_url` | No | Forgejo instance API URL (e.g., `https://git.example.com`). Defaults to `https://git.bitfreedom.at` | | `forgejo_token` | No | Forgejo PAT with repo scope | | `agent` | No | Agent to use (must be a primary agent) | | `share` | No | Share the opencode session (defaults to true for public repos) | | `prompt` | No | Custom prompt to override default behavior | | `mentions` | No | Comma-separated trigger phrases. Defaults to `/opencode,/oc` | | `variant` | No | Model variant (e.g., `high`, `max`, `minimal`) | ## Supported Events | Event Type | Triggered By | Details | |---|---|---| | `issue_comment` | Comment on an issue or MR | Mention `/opencode` or `/oc` in your comment | | `pull_request_review_comment` | Comment on specific PR/MR code lines | Mention `/opencode` or `/oc` when reviewing code | ## Examples ### Explain an issue ``` /opencode explain this issue ``` ### Fix an issue ``` /opencode fix this ``` ### Review MRs ``` /opencode review this merge request ``` ## Development To test locally: 1. Set up environment: ```bash export FORGEJO_API_URL="https://git.your-instance.com" export FORGEJO_TOKEN="your-pat-here" export MODEL="anthropic/claude-sonnet-4-20250514" export GITHUB_RUN_ID="test" export GITHUB_REPOSITORY="owner/repo" export GITHUB_ACTOR="testuser" export GITHUB_EVENT_NAME="issue_comment" export GITHUB_EVENT_PATH="/tmp/event.json" ``` 2. Create a mock event payload in `/tmp/event.json`: ```json { "eventName": "issue_comment", "repo": { "owner": "owner", "repo": "repo" }, "actor": "testuser", "payload": { "issue": { "number": 1, "index": 1, "title": "Test issue", "body": "Test body" }, "comment": { "id": 1, "body": "/opencode fix this" } } } ``` 3. Run: ```bash bun index.ts ``` ## License MIT