mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-07 00:51:34 +00:00
refactor(cli): convert github subcommands to effectCmd (#25522)
This commit is contained in:
parent
be88cd5cb9
commit
af9fdf0a1c
1 changed files with 21 additions and 20 deletions
|
|
@ -18,10 +18,9 @@ import type {
|
||||||
} from "@octokit/webhooks-types"
|
} from "@octokit/webhooks-types"
|
||||||
import { UI } from "../ui"
|
import { UI } from "../ui"
|
||||||
import { cmd } from "./cmd"
|
import { cmd } from "./cmd"
|
||||||
|
import { effectCmd } from "../effect-cmd"
|
||||||
import { ModelsDev } from "@/provider/models"
|
import { ModelsDev } from "@/provider/models"
|
||||||
import { Instance } from "@/project/instance"
|
import { InstanceRef } from "@/effect/instance-ref"
|
||||||
import { WithInstance } from "@/project/with-instance"
|
|
||||||
import { bootstrap } from "../bootstrap"
|
|
||||||
import { SessionShare } from "@/share/session"
|
import { SessionShare } from "@/share/session"
|
||||||
import { Session } from "@/session/session"
|
import { Session } from "@/session/session"
|
||||||
import type { SessionID } from "../../session/schema"
|
import type { SessionID } from "../../session/schema"
|
||||||
|
|
@ -200,13 +199,14 @@ export const GithubCommand = cmd({
|
||||||
async handler() {},
|
async handler() {},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const GithubInstallCommand = cmd({
|
export const GithubInstallCommand = effectCmd({
|
||||||
command: "install",
|
command: "install",
|
||||||
describe: "install the GitHub agent",
|
describe: "install the GitHub agent",
|
||||||
async handler() {
|
handler: Effect.fn("Cli.github.install")(function* () {
|
||||||
await WithInstance.provide({
|
const maybeCtx = yield* InstanceRef
|
||||||
directory: process.cwd(),
|
if (!maybeCtx) return yield* Effect.die("InstanceRef not provided")
|
||||||
async fn() {
|
const ctx = maybeCtx
|
||||||
|
yield* Effect.promise(async () => {
|
||||||
{
|
{
|
||||||
UI.empty()
|
UI.empty()
|
||||||
prompts.intro("Install GitHub agent")
|
prompts.intro("Install GitHub agent")
|
||||||
|
|
@ -254,7 +254,7 @@ export const GithubInstallCommand = cmd({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAppInfo() {
|
async function getAppInfo() {
|
||||||
const project = Instance.project
|
const project = ctx.project
|
||||||
if (project.vcs !== "git") {
|
if (project.vcs !== "git") {
|
||||||
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
|
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
|
||||||
throw new UI.CancelledError()
|
throw new UI.CancelledError()
|
||||||
|
|
@ -262,14 +262,14 @@ export const GithubInstallCommand = cmd({
|
||||||
|
|
||||||
// Get repo info
|
// Get repo info
|
||||||
const info = await AppRuntime.runPromise(
|
const info = await AppRuntime.runPromise(
|
||||||
Git.Service.use((git) => git.run(["remote", "get-url", "origin"], { cwd: Instance.worktree })),
|
Git.Service.use((git) => git.run(["remote", "get-url", "origin"], { cwd: ctx.worktree })),
|
||||||
).then((x) => x.text().trim())
|
).then((x) => x.text().trim())
|
||||||
const parsed = parseGitHubRemote(info)
|
const parsed = parseGitHubRemote(info)
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
|
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
|
||||||
throw new UI.CancelledError()
|
throw new UI.CancelledError()
|
||||||
}
|
}
|
||||||
return { owner: parsed.owner, repo: parsed.repo, root: Instance.worktree }
|
return { owner: parsed.owner, repo: parsed.repo, root: ctx.worktree }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function promptProvider() {
|
async function promptProvider() {
|
||||||
|
|
@ -420,12 +420,11 @@ jobs:
|
||||||
prompts.log.success(`Added workflow file: "${WORKFLOW_FILE}"`)
|
prompts.log.success(`Added workflow file: "${WORKFLOW_FILE}"`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
})
|
})
|
||||||
},
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const GithubRunCommand = cmd({
|
export const GithubRunCommand = effectCmd({
|
||||||
command: "run",
|
command: "run",
|
||||||
describe: "run the GitHub agent",
|
describe: "run the GitHub agent",
|
||||||
builder: (yargs) =>
|
builder: (yargs) =>
|
||||||
|
|
@ -438,8 +437,10 @@ export const GithubRunCommand = cmd({
|
||||||
type: "string",
|
type: "string",
|
||||||
describe: "GitHub personal access token (github_pat_********)",
|
describe: "GitHub personal access token (github_pat_********)",
|
||||||
}),
|
}),
|
||||||
async handler(args) {
|
handler: Effect.fn("Cli.github.run")(function* (args) {
|
||||||
await bootstrap(process.cwd(), async () => {
|
const ctx = yield* InstanceRef
|
||||||
|
if (!ctx) return yield* Effect.die("InstanceRef not provided")
|
||||||
|
yield* Effect.promise(async () => {
|
||||||
const isMock = args.token || args.event
|
const isMock = args.token || args.event
|
||||||
|
|
||||||
const context = isMock ? (JSON.parse(args.event!) as Context) : github.context
|
const context = isMock ? (JSON.parse(args.event!) as Context) : github.context
|
||||||
|
|
@ -502,21 +503,21 @@ export const GithubRunCommand = cmd({
|
||||||
: "issue"
|
: "issue"
|
||||||
: undefined
|
: undefined
|
||||||
const gitText = async (args: string[]) => {
|
const gitText = async (args: string[]) => {
|
||||||
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: Instance.worktree })))
|
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree })))
|
||||||
if (result.exitCode !== 0) {
|
if (result.exitCode !== 0) {
|
||||||
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
|
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
|
||||||
}
|
}
|
||||||
return result.text().trim()
|
return result.text().trim()
|
||||||
}
|
}
|
||||||
const gitRun = async (args: string[]) => {
|
const gitRun = async (args: string[]) => {
|
||||||
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: Instance.worktree })))
|
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree })))
|
||||||
if (result.exitCode !== 0) {
|
if (result.exitCode !== 0) {
|
||||||
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
|
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
const gitStatus = (args: string[]) =>
|
const gitStatus = (args: string[]) =>
|
||||||
AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: Instance.worktree })))
|
AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree })))
|
||||||
const commitChanges = async (summary: string, actor?: string) => {
|
const commitChanges = async (summary: string, actor?: string) => {
|
||||||
const args = ["commit", "-m", summary]
|
const args = ["commit", "-m", summary]
|
||||||
if (actor) args.push("-m", `Co-authored-by: ${actor} <${actor}@users.noreply.github.com>`)
|
if (actor) args.push("-m", `Co-authored-by: ${actor} <${actor}@users.noreply.github.com>`)
|
||||||
|
|
@ -1646,5 +1647,5 @@ query($owner: String!, $repo: String!, $number: Int!) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
}),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue