GeezerVison is showing github.com — chore(function): remove exchange_github_app_token_with_pat route (#57… · thomaspapiernik/opencode-fork@17ebb66
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: github/README.md +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -119,15 +119,15 @@ To test locally: | 119 | 119 | MODEL=anthropic/claude-sonnet-4-20250514 \ | 120 | 120 | ANTHROPIC_API_KEY=sk-ant-api03-1234567890 \ | 121 | 121 | GITHUB_RUN_ID=dummy \ | 122 | | - MOCK_TOKEN=github_pat_1234567890 \ | | 122 | + TOKEN=github_pat_1234567890 \ | 123 | 123 | MOCK_EVENT='{"eventName":"issue_comment",...}' \ | 124 | 124 | bun /path/to/opencode/github/index.ts | 125 | 125 | ``` | 126 | 126 |
| 127 | 127 | - `MODEL`: The model used by opencode. Same as the `MODEL` defined in the GitHub workflow. | 128 | 128 | - `ANTHROPIC_API_KEY`: Your model provider API key. Same as the keys defined in the GitHub workflow. | 129 | 129 | - `GITHUB_RUN_ID`: Dummy value to emulate GitHub action environment. | 130 | | - - `MOCK_TOKEN`: A GitHub personal access token. This token is used to verify you have `admin` or `write` access to the test repo. Generate a token [here](https://github.com/settings/personal-access-tokens). | | 130 | + - `TOKEN`: A GitHub personal access token with write access to the test repo, used directly for GitHub API calls. Generate a token [here](https://github.com/settings/personal-access-tokens). | 131 | 131 | - `MOCK_EVENT`: Mock GitHub event payload (see templates below). | 132 | 132 | - `/path/to/opencode`: Path to your cloned opencode repo. `bun /path/to/opencode/github/index.ts` runs your local version of `opencode`. | 133 | 133 |
| |
Collapse file Copy file name to clipboardExpand all lines: github/index.ts +9-23Lines changed: 9 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -334,7 +334,6 @@ function useEnvShare() { | 334 | 334 | function useEnvMock() { | 335 | 335 | return { | 336 | 336 | mockEvent: process.env["MOCK_EVENT"], | 337 | | - mockToken: process.env["MOCK_TOKEN"], | 338 | 337 | } | 339 | 338 | } | 340 | 339 |
| @@ -343,8 +342,7 @@ function useEnvGithubToken() { | 343 | 342 | } | 344 | 343 |
| 345 | 344 | function isMock() { | 346 | | - const { mockEvent, mockToken } = useEnvMock() | 347 | | - return Boolean(mockEvent || mockToken) | | 345 | + return Boolean(useEnvMock().mockEvent) | 348 | 346 | } | 349 | 347 |
| 350 | 348 | function isPullRequest() { | @@ -367,29 +365,17 @@ function useShareUrl() { | 367 | 365 | } | 368 | 366 |
| 369 | 367 | async function getAccessToken() { | 370 | | - const { repo } = useContext() | 371 | | - | 372 | 368 | const envToken = useEnvGithubToken() | 373 | 369 | if (envToken) return envToken | | 370 | + if (isMock()) throw new Error("TOKEN is required when running with MOCK_EVENT") | 374 | 371 |
| 375 | | - let response | 376 | | - if (isMock()) { | 377 | | - response = await fetch("https://api.opencode.ai/exchange_github_app_token_with_pat", { | 378 | | - method: "POST", | 379 | | - headers: { | 380 | | - Authorization: `Bearer ${useEnvMock().mockToken}`, | 381 | | - }, | 382 | | - body: JSON.stringify({ owner: repo.owner, repo: repo.repo }), | 383 | | - }) | 384 | | - } else { | 385 | | - const oidcToken = await core.getIDToken("opencode-github-action") | 386 | | - response = await fetch("https://api.opencode.ai/exchange_github_app_token", { | 387 | | - method: "POST", | 388 | | - headers: { | 389 | | - Authorization: `Bearer ${oidcToken}`, | 390 | | - }, | 391 | | - }) | 392 | | - } | | 372 | + const oidcToken = await core.getIDToken("opencode-github-action") | | 373 | + const response = await fetch("https://api.opencode.ai/exchange_github_app_token", { | | 374 | + method: "POST", | | 375 | + headers: { | | 376 | + Authorization: `Bearer ${oidcToken}`, | | 377 | + }, | | 378 | + }) | 393 | 379 |
| 394 | 380 | if (!response.ok) { | 395 | 381 | const responseJson = (await response.json()) as { error?: string } | |
Collapse file Copy file name to clipboardExpand all lines: packages/function/src/api.ts -50Lines changed: 0 additions & 50 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -111,54 +111,4 @@ export default new Hono() | 111 | 111 | ) | 112 | 112 | } | 113 | 113 | }) | 114 | | - /** | 115 | | - * Used by the GitHub action to get GitHub installation access token given user PAT token (used when testing `opencode github run` locally) | 116 | | - */ | 117 | | - .post("/exchange_github_app_token_with_pat", async (c) => { | 118 | | - const body = await c.req.json<{ owner: string; repo: string }>() | 119 | | - const owner = body.owner | 120 | | - const repo = body.repo | 121 | | - | 122 | | - try { | 123 | | - // get Authorization header | 124 | | - const authHeader = c.req.header("Authorization") | 125 | | - const token = authHeader?.replace(/^Bearer /, "") | 126 | | - if (!token) throw new Error("Authorization header is required") | 127 | | - | 128 | | - // Verify permissions | 129 | | - const userClient = new Octokit({ auth: token }) | 130 | | - const { data: repoData } = await userClient.repos.get({ owner, repo }) | 131 | | - if (!repoData.permissions.admin && !repoData.permissions.push && !repoData.permissions.maintain) | 132 | | - throw new Error("User does not have write permissions") | 133 | | - | 134 | | - // Get installation token | 135 | | - const auth = createAppAuth({ | 136 | | - appId: Resource.GITHUB_APP_ID.value, | 137 | | - privateKey: Resource.GITHUB_APP_PRIVATE_KEY.value, | 138 | | - }) | 139 | | - const appAuth = await auth({ type: "app" }) | 140 | | - | 141 | | - // Lookup installation | 142 | | - const appClient = new Octokit({ auth: appAuth.token }) | 143 | | - const { data: installation } = await appClient.apps.getRepoInstallation({ | 144 | | - owner, | 145 | | - repo, | 146 | | - }) | 147 | | - | 148 | | - // Get installation token | 149 | | - const installationAuth = await auth({ | 150 | | - type: "installation", | 151 | | - installationId: installation.id, | 152 | | - }) | 153 | | - | 154 | | - return c.json({ token: installationAuth.token }) | 155 | | - } catch (e: any) { | 156 | | - let error = e | 157 | | - if (e instanceof Error) { | 158 | | - error = e.message | 159 | | - } | 160 | | - | 161 | | - return c.json({ error }, { status: 401 }) | 162 | | - } | 163 | | - }) | 164 | 114 | .all("*", (c) => c.text("Not Found", 404)) |
|