GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore(function): remove exchange_github_app_token_with_pat route (#57… · thomaspapiernik/opencode-fork@17ebb66

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • github
    • README.md
    • index.ts
  • packages/function/src
    • api.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎github/README.md‎

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 numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ To test locally:
119119
MODEL=anthropic/claude-sonnet-4-20250514 \
120120
ANTHROPIC_API_KEY=sk-ant-api03-1234567890 \
121121
GITHUB_RUN_ID=dummy \
122-
MOCK_TOKEN=github_pat_1234567890 \
122+
TOKEN=github_pat_1234567890 \
123123
MOCK_EVENT='{"eventName":"issue_comment",...}' \
124124
bun /path/to/opencode/github/index.ts
125125
```
126126

127127
- `MODEL`: The model used by opencode. Same as the `MODEL` defined in the GitHub workflow.
128128
- `ANTHROPIC_API_KEY`: Your model provider API key. Same as the keys defined in the GitHub workflow.
129129
- `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).
131131
- `MOCK_EVENT`: Mock GitHub event payload (see templates below).
132132
- `/path/to/opencode`: Path to your cloned opencode repo. `bun /path/to/opencode/github/index.ts` runs your local version of `opencode`.
133133

Collapse file

‎github/index.ts‎

Copy file name to clipboardExpand all lines: github/index.ts
+9-23Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ function useEnvShare() {
334334
function useEnvMock() {
335335
return {
336336
mockEvent: process.env["MOCK_EVENT"],
337-
mockToken: process.env["MOCK_TOKEN"],
338337
}
339338
}
340339

@@ -343,8 +342,7 @@ function useEnvGithubToken() {
343342
}
344343

345344
function isMock() {
346-
const { mockEvent, mockToken } = useEnvMock()
347-
return Boolean(mockEvent || mockToken)
345+
return Boolean(useEnvMock().mockEvent)
348346
}
349347

350348
function isPullRequest() {
@@ -367,29 +365,17 @@ function useShareUrl() {
367365
}
368366

369367
async function getAccessToken() {
370-
const { repo } = useContext()
371-
372368
const envToken = useEnvGithubToken()
373369
if (envToken) return envToken
370+
if (isMock()) throw new Error("TOKEN is required when running with MOCK_EVENT")
374371

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+
})
393379

394380
if (!response.ok) {
395381
const responseJson = (await response.json()) as { error?: string }
Collapse file

‎packages/function/src/api.ts‎

Copy file name to clipboardExpand all lines: packages/function/src/api.ts
-50Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -111,54 +111,4 @@ export default new Hono()
111111
)
112112
}
113113
})
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-
})
164114
.all("*", (c) => c.text("Not Found", 404))

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.