diff --git a/packages/opencode/src/cli/cmd/github.handler.ts b/packages/opencode/src/cli/cmd/github.handler.ts index fcf44279ce7f..75411efbf003 100644 --- a/packages/opencode/src/cli/cmd/github.handler.ts +++ b/packages/opencode/src/cli/cmd/github.handler.ts @@ -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>["promptFiles"] const triggerCommentId = isCommentEvent ? (payload as IssueCommentEvent | PullRequestReviewCommentEvent).comment.id @@ -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) { @@ -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() { @@ -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({ @@ -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({ @@ -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({ diff --git a/packages/web/src/content/docs/github.mdx b/packages/web/src/content/docs/github.mdx index 08cb27fff019..30f9b3d7f6f1 100644 --- a/packages/web/src/content/docs/github.mdx +++ b/packages/web/src/content/docs/github.mdx @@ -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