File tree Expand file tree Collapse file tree 7 files changed +53
-96
lines changed
Expand file tree Collapse file tree 7 files changed +53
-96
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ export const GITHUB_WEB_API_CONFIG = {
2929 baseURL : "https://github.com" ,
3030} as const
3131
32+ export const GITHUB_API_BASE_URL = "https://api.github.com"
33+
3234export const GITHUB_BASE_URL = "https://github.com"
3335export const GITHUB_CLIENT_ID = "01ab8ac9400c4e429b23"
3436export const GITHUB_APP_SCOPES = [
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import fs from "node:fs/promises"
44import { PATHS } from "~/lib/paths"
55import { getCopilotToken } from "~/services/copilot/get-token/copilot-token"
66import { getDeviceCode } from "~/services/github/get-device-code"
7- import { getGitHubUser } from "~/services/github/get-user/service "
7+ import { getGitHubUser } from "~/services/github/get-user"
88import { pollAccessToken } from "~/services/github/poll-access-token"
99
1010import { state } from "./state"
Original file line number Diff line number Diff line change 11import consola from "consola"
22import { FetchError , ofetch } from "ofetch"
33
4- import {
5- COPILOT_API_CONFIG ,
6- GITHUB_API_CONFIG ,
7- GITHUB_WEB_API_CONFIG ,
8- } from "~/lib/constants"
4+ import { COPILOT_API_CONFIG } from "~/lib/constants"
95import { modelsCache } from "~/lib/models"
106import { tokenService } from "~/lib/token"
117
@@ -41,17 +37,3 @@ export const copilot = ofetch.create({
4137 }
4238 } ,
4339} )
44-
45- export const github = ofetch . create ( {
46- baseURL : GITHUB_API_CONFIG . baseURL ,
47-
48- async onRequest ( { options } ) {
49- const token = await tokenService . getGithubToken ( )
50- options . headers . set ( "authorization" , `token ${ token } ` )
51- } ,
52- } )
53-
54- // Only used for device flow auth
55- export const _github = ofetch . create ( {
56- baseURL : GITHUB_WEB_API_CONFIG . baseURL ,
57- } )
Original file line number Diff line number Diff line change 1- import type { GetCopilotTokenResponse } from "./types"
1+ import { GITHUB_API_BASE_URL } from "~/lib/constants"
2+ import { state } from "~/lib/state"
23
3- import { github } from "../../api-instance"
4+ export const getCopilotToken = async ( ) => {
5+ const response = await fetch (
6+ `${ GITHUB_API_BASE_URL } /copilot_internal/v2/token` ,
7+ {
8+ headers : {
9+ authorization : `token ${ state . githubToken } ` ,
10+ } ,
11+ } ,
12+ )
413
5- export const getCopilotToken = async ( ) =>
6- github < GetCopilotTokenResponse > ( "/copilot_internal/v2/token" , {
7- method : "GET" ,
8- } )
14+ if ( ! response . ok ) {
15+ throw new Error ( "Failed to get Copilot token" , {
16+ cause : await response . json ( ) ,
17+ } )
18+ }
19+
20+ return ( await response . json ( ) ) as GetCopilotTokenResponse
21+ }
22+
23+ // Trimmed for the sake of simplicity
24+ interface GetCopilotTokenResponse {
25+ expires_at : number
26+ refresh_in : number
27+ token : string
28+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { GITHUB_API_BASE_URL } from "~/lib/constants"
2+ import { state } from "~/lib/state"
3+
4+ export async function getGitHubUser ( ) {
5+ const response = await fetch ( `${ GITHUB_API_BASE_URL } /user` , {
6+ headers : {
7+ authorization : `token ${ state . githubToken } ` ,
8+ } ,
9+ } )
10+
11+ if ( ! response . ok ) {
12+ throw new Error ( "Failed to get GitHub user" , {
13+ cause : await response . json ( ) ,
14+ } )
15+ }
16+
17+ return ( await response . json ( ) ) as GithubUser
18+ }
19+
20+ // Trimmed for the sake of simplicity
21+ interface GithubUser {
22+ login : string
23+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments