@@ -78,6 +78,10 @@ export async function promptImportInternetDatabase(
7878 *
7979 * @param databaseManager the DatabaseManager
8080 * @param storagePath where to store the unzipped database.
81+ * @param credentials the credentials to use to authenticate with GitHub
82+ * @param progress the progress callback
83+ * @param token the cancellation token
84+ * @param cli the CodeQL CLI server
8185 */
8286export async function promptImportGithubDatabase (
8387 commandManager : AppCommandManager ,
@@ -103,6 +107,47 @@ export async function promptImportGithubDatabase(
103107 return ;
104108 }
105109
110+ const databaseItem = await downloadGitHubDatabase (
111+ githubRepo ,
112+ databaseManager ,
113+ storagePath ,
114+ credentials ,
115+ progress ,
116+ token ,
117+ cli ,
118+ ) ;
119+
120+ if ( databaseItem ) {
121+ await commandManager . execute ( "codeQLDatabases.focus" ) ;
122+ void showAndLogInformationMessage (
123+ "Database downloaded and imported successfully." ,
124+ ) ;
125+ return databaseItem ;
126+ }
127+
128+ return ;
129+ }
130+
131+ /**
132+ * Downloads a database from GitHub
133+ *
134+ * @param githubRepo the GitHub repository to download the database from
135+ * @param databaseManager the DatabaseManager
136+ * @param storagePath where to store the unzipped database.
137+ * @param credentials the credentials to use to authenticate with GitHub
138+ * @param progress the progress callback
139+ * @param token the cancellation token
140+ * @param cli the CodeQL CLI server
141+ **/
142+ export async function downloadGitHubDatabase (
143+ githubRepo : string ,
144+ databaseManager : DatabaseManager ,
145+ storagePath : string ,
146+ credentials : Credentials | undefined ,
147+ progress : ProgressCallback ,
148+ token : CancellationToken ,
149+ cli ?: CodeQLCliServer ,
150+ ) : Promise < DatabaseItem | undefined > {
106151 const nwo = getNwoFromGitHubUrl ( githubRepo ) || githubRepo ;
107152 if ( ! isValidGitHubNwo ( nwo ) ) {
108153 throw new Error ( `Invalid GitHub repository: ${ githubRepo } ` ) ;
@@ -130,7 +175,7 @@ export async function promptImportGithubDatabase(
130175 * We only need the actual token string.
131176 */
132177 const octokitToken = ( ( await octokit . auth ( ) ) as { token : string } ) ?. token ;
133- const item = await databaseArchiveFetcher (
178+ return await databaseArchiveFetcher (
134179 databaseUrl ,
135180 {
136181 Accept : "application/zip" ,
@@ -143,14 +188,6 @@ export async function promptImportGithubDatabase(
143188 token ,
144189 cli ,
145190 ) ;
146- if ( item ) {
147- await commandManager . execute ( "codeQLDatabases.focus" ) ;
148- void showAndLogInformationMessage (
149- "Database downloaded and imported successfully." ,
150- ) ;
151- return item ;
152- }
153- return ;
154191}
155192
156193/**
0 commit comments