@@ -80,9 +80,9 @@ export const getAsBase64 = async (url: string): Promise<string | null> => {
8080
8181interface GithubResponse {
8282 repository : {
83- content : {
83+ object : {
8484 text : string ;
85- } ;
85+ } | null ;
8686 } ;
8787}
8888interface GitlabResponse {
@@ -115,26 +115,13 @@ export const getOrFetchGmodFile = async (path: PathLike) => {
115115 const provider = url . match ( / ( [ ^ \. \/ ] + ) \. c o m / ) ;
116116 if ( ! provider ) return ;
117117 const isGithub = provider [ 1 ] === "github" ;
118- const endpoint = isGithub
119- ? "https://api.github.com/graphql"
120- : "https://gitlab.com/api/graphql" ;
118+ const gitlabEndpoint = "https://gitlab.com/api/graphql" ;
121119 const repo = addon ;
122120 const owner = url . match ( / \. c o m \/ ( .+ ?) \/ / ) ;
123121 const branch = url . split ( "/" ) . at ( - 2 ) ;
124122
125123 if ( ! owner ) return ;
126- const query = isGithub
127- ? gql `{
128- repository(owner:"${ owner [ 1 ] } ", name:"${ repo } ") {
129- content: object(expression:"${ branch } :${ path } ") {
130- ... on Blob {
131- text
132- }
133- }
134- }
135- }
136- `
137- : gql `{
124+ const query = gql `{
138125 project(fullPath:"${ url . match ( / \. c o m \/ ( .+ ?) \/ \- / ) ?. [ 1 ] } ") {
139126 repository {
140127 blobs(paths:"${ path } "){
@@ -145,23 +132,40 @@ export const getOrFetchGmodFile = async (path: PathLike) => {
145132 }
146133 ` ;
147134 try {
148- const data = await request < GithubResponse | GitlabResponse > (
149- endpoint ,
150- query ,
151- { } ,
152- {
153- authorization : `Bearer ${ isGithub ? apikeys . github : apikeys . gitlab } ` ,
135+ if ( isGithub ) {
136+ const github = await globalThis . MetaConcord . container . getService ( "Github" ) ;
137+ const request : { data : GithubResponse } = await github . octokit . graphql (
138+ `query text($owner: String!, $repo: String!) {
139+ repository(owner: $owner, name: $repo) {
140+ object(expression: "${ branch ?? "HEAD" } :${ path } ") {
141+ ... on Blob {
142+ text
143+ }
144+ }
145+ }` ,
146+ { owner, repo }
147+ ) ;
148+ if ( request . data . repository . object ?. text )
149+ return request . data . repository . object . text ;
150+ return ;
151+ } else {
152+ const data = await request < GithubResponse | GitlabResponse > (
153+ gitlabEndpoint ,
154+ query ,
155+ { } ,
156+ {
157+ authorization : `Bearer ${ apikeys . gitlab } ` ,
158+ }
159+ ) ;
160+ if ( data ) {
161+ const filecontent = ( data as GitlabResponse ) . project . repository . blobs
162+ . nodes [ 0 ] . rawTextBlob ;
163+ return linenos
164+ ? getStackLines ( filecontent , Number ( linenos ) , Number ( linenoe ) )
165+ : filecontent ;
154166 }
155- ) ;
156- if ( data ) {
157- const filecontent = isGithub
158- ? ( data as GithubResponse ) . repository . content . text
159- : ( data as GitlabResponse ) . project . repository . blobs . nodes [ 0 ] . rawTextBlob ;
160- return linenos
161- ? getStackLines ( filecontent , Number ( linenos ) , Number ( linenoe ) )
162- : filecontent ;
167+ return ;
163168 }
164- return ;
165169 } catch ( err ) {
166170 console . error ( JSON . stringify ( err , undefined , 2 ) ) ;
167171 return ;
0 commit comments