MCPcopy Index your code
hub / github.com/anomalyco/opencode / getAccessToken

Function getAccessToken

github/index.ts:369–401  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

367}
368
369async function getAccessToken() {
370 const { repo } = useContext()
371
372 const envToken = useEnvGithubToken()
373 if (envToken) return envToken
374
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 }
393
394 if (!response.ok) {
395 const responseJson = (await response.json()) as { error?: string }
396 throw new Error(`App token exchange failed: ${response.status} ${response.statusText} - ${responseJson.error}`)
397 }
398
399 const responseJson = (await response.json()) as { token: string }
400 return responseJson.token
401}
402
403async function createComment() {
404 const { repo } = useContext()

Callers 1

index.tsFile · 0.85

Calls 6

useContextFunction · 0.85
useEnvGithubTokenFunction · 0.85
isMockFunction · 0.85
useEnvMockFunction · 0.85
jsonMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected