Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/opencode/src/cli/cmd/github.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ export const githubRun = Effect.fn("Cli.github.run")(function* (args: { event?:
let shareId: string | undefined
let exitCode = 0
let githubClientReady = false
let agentUsername = AGENT_USERNAME
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
const triggerCommentId = isCommentEvent
? (payload as IssueCommentEvent | PullRequestReviewCommentEvent).comment.id
Expand Down Expand Up @@ -487,6 +488,17 @@ export const githubRun = Effect.fn("Cli.github.run")(function* (args: { event?:
headers: { authorization: `token ${appToken}` },
})
githubClientReady = true
try {
const { data } = await octoRest.rest.users.getAuthenticated()
if (data.login) agentUsername = data.login
} catch {}
if (agentUsername === AGENT_USERNAME) {
try {
const viewer = await octoGraph<{ viewer: { login: string } }>(`query { viewer { login } }`)
if (viewer.viewer?.login) agentUsername = viewer.viewer.login
} catch {}
}
console.log("Acting as", agentUsername)

const { userPrompt, promptFiles } = await getUserPrompt()
if (!useGithubToken) {
Expand Down Expand Up @@ -1036,8 +1048,8 @@ export const githubRun = Effect.fn("Cli.github.run")(function* (args: { event?:
const newCredentials = Buffer.from(`x-access-token:${appToken}`, "utf8").toString("base64")

await gitRun(["config", "--local", config, `AUTHORIZATION: basic ${newCredentials}`])
await gitRun(["config", "--global", "user.name", AGENT_USERNAME])
await gitRun(["config", "--global", "user.email", `${AGENT_USERNAME}@users.noreply.github.com`])
await gitRun(["config", "--global", "user.name", agentUsername])
await gitRun(["config", "--global", "user.email", `${agentUsername}@users.noreply.github.com`])
}

async function restoreGitConfig() {
Expand Down Expand Up @@ -1223,7 +1235,7 @@ export const githubRun = Effect.fn("Cli.github.run")(function* (args: { event?:
content: AGENT_REACTION,
})

const eyesReaction = reactions.data.find((r) => r.user?.login === AGENT_USERNAME)
const eyesReaction = reactions.data.find((r) => r.user?.login === agentUsername)
if (!eyesReaction) return

return await octoRest.rest.reactions.deleteForPullRequestComment({
Expand All @@ -1241,7 +1253,7 @@ export const githubRun = Effect.fn("Cli.github.run")(function* (args: { event?:
content: AGENT_REACTION,
})

const eyesReaction = reactions.data.find((r) => r.user?.login === AGENT_USERNAME)
const eyesReaction = reactions.data.find((r) => r.user?.login === agentUsername)
if (!eyesReaction) return

return await octoRest.rest.reactions.deleteForIssueComment({
Expand All @@ -1259,7 +1271,7 @@ export const githubRun = Effect.fn("Cli.github.run")(function* (args: { event?:
content: AGENT_REACTION,
})

const eyesReaction = reactions.data.find((r) => r.user?.login === AGENT_USERNAME)
const eyesReaction = reactions.data.find((r) => r.user?.login === agentUsername)
if (!eyesReaction) return

await octoRest.rest.reactions.deleteForIssue({
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/content/docs/github.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Or you can set it up manually.
`id-token: write` is not required in this mode because OIDC exchange is skipped. To use a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) or another GitHub App token, store it as a secret and pass that secret as `GITHUB_TOKEN` instead.

Eyes reactions and git commits use the token owner (`github-actions[bot]`, your GitHub App bot, or the PAT user), not `opencode-agent[bot]`.

---

## Supported Events
Expand Down
Loading