@@ -5,7 +5,7 @@ import { findLanguage, showAndLogErrorMessage, showAndLogInformationMessage, sho
55import { Credentials } from './authentication' ;
66import * as cli from './cli' ;
77import { logger } from './logging' ;
8- import { getRemoteControllerRepo , getRemoteRepositoryLists } from './config' ;
8+ import { getRemoteControllerRepo , getRemoteRepositoryLists , setRemoteControllerRepo } from './config' ;
99interface Config {
1010 repositories : string [ ] ;
1111 ref ?: string ;
@@ -16,6 +16,13 @@ interface RepoListQuickPickItem extends QuickPickItem {
1616 repoList : string [ ] ;
1717}
1818
19+ /**
20+ * This regex matches strings of the form `owner/repo` where:
21+ * - `owner` is made up of alphanumeric characters or single hyphens, starting and ending in an alphanumeric character
22+ * - `repo` is made up of alphanumeric characters, hyphens, or underscores
23+ */
24+ const REPO_REGEX = / ^ (?: [ a - z A - Z 0 - 9 ] + - ) * [ a - z A - Z 0 - 9 ] + \/ [ a - z A - Z 0 - 9 - _ ] + $ / ;
25+
1926/**
2027 * Gets the repositories to run the query against.
2128 */
@@ -43,12 +50,6 @@ export async function getRepositories(): Promise<string[] | undefined> {
4350 }
4451 } else {
4552 void logger . log ( 'No repository lists defined. Displaying text input box.' ) ;
46- /**
47- * This regex matches strings of the form `owner/repo` where:
48- * - `owner` is made up of alphanumeric characters or single hyphens, starting and ending in an alphanumeric character
49- * - `repo` is made up of alphanumeric characters, hyphens, or underscores
50- */
51- const repoRegex = / ^ (?: [ a - z A - Z 0 - 9 ] + - ) * [ a - z A - Z 0 - 9 ] + \/ [ a - z A - Z 0 - 9 - _ ] + $ / ;
5253 const remoteRepo = await window . showInputBox ( {
5354 title : 'Enter a GitHub repository in the format <owner>/<repo> (e.g. github/codeql)' ,
5455 placeHolder : '<owner>/<repo>' ,
@@ -58,7 +59,7 @@ export async function getRepositories(): Promise<string[] | undefined> {
5859 if ( ! remoteRepo ) {
5960 void showAndLogErrorMessage ( 'No repositories entered.' ) ;
6061 return ;
61- } else if ( ! repoRegex . test ( remoteRepo ) ) { // Check if user entered invalid input
62+ } else if ( ! REPO_REGEX . test ( remoteRepo ) ) { // Check if user entered invalid input
6263 void showAndLogErrorMessage ( 'Invalid repository format. Must be in the format <owner>/<repo> (e.g. github/codeql)' ) ;
6364 return ;
6465 }
@@ -103,18 +104,32 @@ export async function runRemoteQuery(cliServer: cli.CodeQLCliServer, credentials
103104 return ; // No error message needed, since `getRepositories` already displays one.
104105 }
105106
106- // Get the controller repo
107- let owner : string ;
108- let repo : string ;
109- const controllerRepo = getRemoteControllerRepo ( ) ;
110- if ( controllerRepo ) {
111- void logger . log ( `Using controller repository: ${ controllerRepo } ` ) ;
112- [ owner , repo ] = controllerRepo . split ( '/' ) ;
113- } else {
114- [ owner , repo ] = [ 'dsp-testing' , 'qc-controller' ] ;
115- void logger . log ( `No controller repository defined in the 'codeQL.remoteQueries.controllerRepo' setting. Using default repository: ${ owner } /${ repo } .` ) ;
107+ // Get the controller repo from the config, if it exists.
108+ // If it doesn't exist, prompt the user to enter it, and save that value to the config.
109+ let controllerRepo : string | undefined ;
110+ controllerRepo = getRemoteControllerRepo ( ) ;
111+ if ( ! controllerRepo ) {
112+ void logger . log ( 'No controller repository defined.' ) ;
113+ controllerRepo = await window . showInputBox ( {
114+ title : 'Controller repository in which to display progress and results of remote queries' ,
115+ placeHolder : '<owner>/<repo>' ,
116+ prompt : 'Enter the name of a GitHub repository in the format <owner>/<repo>' ,
117+ ignoreFocusOut : true ,
118+ } ) ;
119+ if ( ! controllerRepo ) {
120+ void showAndLogErrorMessage ( 'No controller repository entered.' ) ;
121+ return ;
122+ } else if ( ! REPO_REGEX . test ( controllerRepo ) ) { // Check if user entered invalid input
123+ void showAndLogErrorMessage ( 'Invalid repository format. Must be a valid GitHub repository in the format <owner>/<repo>.' ) ;
124+ return ;
125+ }
126+ void logger . log ( `Setting the controller repository as: ${ controllerRepo } ` ) ;
127+ await setRemoteControllerRepo ( controllerRepo ) ;
116128 }
117129
130+ void logger . log ( `Using controller repository: ${ controllerRepo } ` ) ;
131+ const [ owner , repo ] = controllerRepo . split ( '/' ) ;
132+
118133 await runRemoteQueriesApiRequest ( credentials , ref , language , repositories , query , owner , repo ) ;
119134}
120135
0 commit comments