@@ -6,33 +6,62 @@ import { App, Octokit } from "octokit";
66
77let graphQlWithAuth : typeof graphql
88
9- export function useGithubGraphQL ( ) {
9+ export function useGithubGraphQL ( event ?: H3Event ) {
1010 if ( ! graphQlWithAuth ) {
11- const { githubToken } = useRuntimeConfig ( )
12- graphQlWithAuth = graphql . defaults ( {
13- headers : {
14- authorization : `token ${ githubToken } ` ,
15- } ,
16- } )
11+ try {
12+ const config = useRuntimeConfig ( event ) ;
13+ const githubToken = config ?. githubToken ;
14+
15+ if ( ! githubToken ) {
16+ console . warn ( "GitHub token is not available in runtime config" ) ;
17+ graphQlWithAuth = graphql . defaults ( { } ) ;
18+ return { graphql : graphQlWithAuth } ;
19+ }
20+
21+ graphQlWithAuth = graphql . defaults ( {
22+ headers : {
23+ authorization : `token ${ githubToken } ` ,
24+ } ,
25+ } ) ;
26+ } catch ( error ) {
27+ console . error ( "Error initializing GitHub GraphQL client:" , error ) ;
28+ graphQlWithAuth = graphql . defaults ( { } ) ;
29+ }
1730 }
1831 return {
1932 graphql : graphQlWithAuth ,
20- }
33+ } ;
2134}
2235
2336export function useOctokitApp ( event : H3Event ) : AppType {
24- const { appId, privateKey, webhookSecret, ghBaseUrl } =
25- useRuntimeConfig ( event ) ;
26-
27- return new App ( {
28- appId,
29- privateKey,
30- webhooks : { secret : webhookSecret } ,
31- Octokit : Octokit . defaults ( {
32- baseUrl : ghBaseUrl ,
33- paginateRest
34- } ) ,
35- } ) as unknown as AppType ;
37+ try {
38+ const config = useRuntimeConfig ( event ) ;
39+ const { appId, privateKey, webhookSecret, ghBaseUrl } = config ;
40+
41+ if ( ! appId || ! privateKey || ! webhookSecret ) {
42+ console . warn ( "Missing required GitHub App credentials in runtime config" ) ;
43+ return {
44+ octokit : { request : async ( ) => ( { data : { id : 0 } } ) } ,
45+ getInstallationOctokit : async ( ) => ( { } )
46+ } as any ;
47+ }
48+
49+ return new App ( {
50+ appId,
51+ privateKey,
52+ webhooks : { secret : webhookSecret } ,
53+ Octokit : Octokit . defaults ( {
54+ baseUrl : ghBaseUrl ,
55+ paginateRest
56+ } ) ,
57+ } ) as unknown as AppType ;
58+ } catch ( error ) {
59+ console . error ( "Error initializing GitHub App:" , error ) ;
60+ return {
61+ octokit : { request : async ( ) => ( { data : { id : 0 } } ) } ,
62+ getInstallationOctokit : async ( ) => ( { } )
63+ } as any ;
64+ }
3665}
3766
3867export async function useOctokitInstallation (
0 commit comments