@@ -51,6 +51,7 @@ export async function promptImportInternetDatabase(
5151 { } ,
5252 databaseManager ,
5353 storagePath ,
54+ undefined ,
5455 progress ,
5556 token ,
5657 cli
@@ -98,11 +99,13 @@ export async function promptImportGithubDatabase(
9899 throw new Error ( `Invalid GitHub repository: ${ githubRepo } ` ) ;
99100 }
100101
101- const databaseUrl = await convertGithubNwoToDatabaseUrl ( githubRepo , credentials , progress ) ;
102- if ( ! databaseUrl ) {
102+ const result = await convertGithubNwoToDatabaseUrl ( githubRepo , credentials , progress ) ;
103+ if ( ! result ) {
103104 return ;
104105 }
105106
107+ const { databaseUrl, name, owner } = result ;
108+
106109 const octokit = await credentials . getOctokit ( ) ;
107110 /**
108111 * The 'token' property of the token object returned by `octokit.auth()`.
@@ -125,6 +128,7 @@ export async function promptImportGithubDatabase(
125128 { 'Accept' : 'application/zip' , 'Authorization' : `Bearer ${ octokitToken } ` } ,
126129 databaseManager ,
127130 storagePath ,
131+ `${ owner } /${ name } ` ,
128132 progress ,
129133 token ,
130134 cli
@@ -173,6 +177,7 @@ export async function promptImportLgtmDatabase(
173177 { } ,
174178 databaseManager ,
175179 storagePath ,
180+ undefined ,
176181 progress ,
177182 token ,
178183 cli
@@ -220,6 +225,7 @@ export async function importArchiveDatabase(
220225 { } ,
221226 databaseManager ,
222227 storagePath ,
228+ undefined ,
223229 progress ,
224230 token ,
225231 cli
@@ -247,6 +253,7 @@ export async function importArchiveDatabase(
247253 * @param requestHeaders Headers to send with the request
248254 * @param databaseManager the DatabaseManager
249255 * @param storagePath where to store the unzipped database.
256+ * @param nameOverride a name for the database that overrides the default
250257 * @param progress callback to send progress messages to
251258 * @param token cancellation token
252259 */
@@ -255,6 +262,7 @@ async function databaseArchiveFetcher(
255262 requestHeaders : { [ key : string ] : string } ,
256263 databaseManager : DatabaseManager ,
257264 storagePath : string ,
265+ nameOverride : string | undefined ,
258266 progress : ProgressCallback ,
259267 token : CancellationToken ,
260268 cli ?: CodeQLCliServer ,
@@ -296,7 +304,7 @@ async function databaseArchiveFetcher(
296304 } ) ;
297305 await ensureZippedSourceLocation ( dbPath ) ;
298306
299- const item = await databaseManager . openDatabase ( progress , token , Uri . file ( dbPath ) ) ;
307+ const item = await databaseManager . openDatabase ( progress , token , Uri . file ( dbPath ) , nameOverride ) ;
300308 await databaseManager . setCurrentDatabaseItem ( item ) ;
301309 return item ;
302310 } else {
@@ -409,7 +417,6 @@ async function fetchAndUnzip(
409417
410418 await readAndUnzip ( Uri . file ( archivePath ) . toString ( true ) , unzipPath , cli , progress ) ;
411419
412-
413420 // remove archivePath eagerly since these archives can be large.
414421 await fs . remove ( archivePath ) ;
415422}
@@ -517,7 +524,11 @@ function convertGitHubUrlToNwo(githubUrl: string): string | undefined {
517524export async function convertGithubNwoToDatabaseUrl (
518525 githubRepo : string ,
519526 credentials : Credentials ,
520- progress : ProgressCallback ) : Promise < string | undefined > {
527+ progress : ProgressCallback ) : Promise < {
528+ databaseUrl : string ,
529+ owner : string ,
530+ name : string
531+ } | undefined > {
521532 try {
522533 const nwo = convertGitHubUrlToNwo ( githubRepo ) || githubRepo ;
523534 const [ owner , repo ] = nwo . split ( '/' ) ;
@@ -532,7 +543,11 @@ export async function convertGithubNwoToDatabaseUrl(
532543 return ;
533544 }
534545
535- return `https://api.github.com/repos/${ owner } /${ repo } /code-scanning/codeql/databases/${ language } ` ;
546+ return {
547+ databaseUrl : `https://api.github.com/repos/${ owner } /${ repo } /code-scanning/codeql/databases/${ language } ` ,
548+ owner,
549+ name : repo
550+ } ;
536551
537552 } catch ( e ) {
538553 void logger . log ( `Error: ${ getErrorMessage ( e ) } ` ) ;
0 commit comments