This commit is contained in:
Frank 2025-08-27 17:28:14 -04:00
parent 9eb5305f78
commit a366d45a8c
6 changed files with 135 additions and 13 deletions

View file

@ -0,0 +1,43 @@
name: "opencode GitHub Assistant"
description: "Run opencode in GitHub Actions workflows"
branding:
icon: "code"
color: "orange"
inputs:
model:
description: "The model to use with opencode. Takes the format of `provider/model`."
required: true
share:
description: "Whether to share the opencode session. Defaults to true for public repositories."
required: false
token:
description: "Optional GitHub access token for performing operations such as creating comments, committing changes, and opening pull requests. Defaults to the installation access token from the opencode GitHub App."
required: false
runs:
using: "composite"
steps:
- name: Install opencode
shell: bash
run: curl -fsSL https://opencode.ai/install | bash
- name: Install bun
shell: bash
run: npm install -g bun
- name: Install dependencies
shell: bash
run: |
cd ${GITHUB_ACTION_PATH}
bun install
- name: Run opencode
shell: bash
run: bun ${GITHUB_ACTION_PATH}/index.ts
env:
MODEL: ${{ inputs.model }}
SHARE: ${{ inputs.share }}
TOKEN: ${{ inputs.token }}

View file

@ -4,13 +4,13 @@ import * as core from "@actions/core"
import type { IssueCommentEvent, PullRequestReviewCommentCreatedEvent } from "@octokit/webhooks-types"
import { createOpencodeClient } from "@opencode-ai/sdk"
import { spawn } from "node:child_process"
import type { GitHubIssue, GitHubPullRequest, IssueQueryResponse, PullRequestQueryResponse } from "./src/types"
import { Context } from "./src/context"
import { Mock } from "./src/mock"
import { Auth } from "./src/auth"
import { Git } from "./src/git"
import { GitHub } from "./src/github"
import { Opencode } from "./src/opencode"
import type { GitHubIssue, GitHubPullRequest, IssueQueryResponse, PullRequestQueryResponse } from "../src/types"
import { Context } from "../src/context"
import { Mock } from "../src/mock"
import { Auth } from "../src/auth"
import { Git } from "../src/git"
import { GitHub } from "../src/github"
import { Opencode } from "../src/opencode"
const { client, server } = createOpencode()
const mode = Context.eventName() === "pull_request_review_comment" ? defineReviewCommentMode() : defineCommentMode()

View file

@ -1,4 +1,4 @@
name: "opencode GitHub Action"
name: "opencode GitHub Review"
description: "Run opencode in GitHub Actions workflows"
branding:
icon: "code"

View file

@ -2,11 +2,11 @@ import { $ } from "bun"
import os from "node:os"
import * as core from "@actions/core"
import type { PullRequestReviewCommentEditedEvent } from "@octokit/webhooks-types"
import { Context } from "./src/context"
import { Auth } from "./src/auth"
import { Git } from "./src/git"
import { GitHub } from "./src/github"
import { Opencode } from "./src/opencode"
import { Context } from "../src/context"
import { Auth } from "../src/auth"
import { Git } from "../src/git"
import { GitHub } from "../src/github"
import { Opencode } from "../src/opencode"
type Finding = {
file: string

48
github/run/action.yml Normal file
View file

@ -0,0 +1,48 @@
name: "opencode GitHub Run"
description: "Run opencode in GitHub Actions workflows"
branding:
icon: "code"
color: "orange"
inputs:
model:
description: "The model to use with opencode. Takes the format of `provider/model`."
required: true
prompt:
description: "The prompt to use with opencode."
required: true
share:
description: "Whether to share the opencode session. Defaults to true for public repositories."
required: false
token:
description: "Optional GitHub access token for performing operations such as creating comments, committing changes, and opening pull requests. Defaults to the installation access token from the opencode GitHub App."
required: false
runs:
using: "composite"
steps:
- name: Install opencode
shell: bash
run: curl -fsSL https://opencode.ai/install | bash
- name: Install bun
shell: bash
run: npm install -g bun
- name: Install dependencies
shell: bash
run: |
cd ${GITHUB_ACTION_PATH}
bun install
- name: Run opencode
shell: bash
run: bun ${GITHUB_ACTION_PATH}/index.ts
env:
MODEL: ${{ inputs.model }}
PROMPT: ${{ inputs.prompt }}
SHARE: ${{ inputs.share }}
TOKEN: ${{ inputs.token }}

31
github/run/index.ts Normal file
View file

@ -0,0 +1,31 @@
import { $ } from "bun"
import * as core from "@actions/core"
import { Auth } from "../src/auth"
import { Git } from "../src/git"
import { Opencode } from "../src/opencode"
try {
await run()
process.exit(0)
} catch (e: any) {
console.error(e)
let msg = e
if (e instanceof $.ShellError) msg = e.stderr.toString()
else if (e instanceof Error) msg = e.message
core.setFailed(msg)
// Also output the clean error message for the action to capture
//core.setOutput("prepare_error", e.message);
process.exit(1)
}
export async function run() {
try {
await Git.configure()
await Opencode.start()
await Opencode.chat(process.env.PROMPT!)
} finally {
Opencode.closeServer()
await Auth.revoke()
await Git.restore()
}
}