@@ -5,7 +5,7 @@ import { findLanguage, showAndLogErrorMessage, showAndLogInformationMessage, sho
5
5
import { Credentials } from './authentication' ;
6
6
import * as cli from './cli' ;
7
7
import { logger } from './logging' ;
8
- import { getRemoteControllerRepo , getRemoteRepositoryLists } from './config' ;
8
+ import { getRemoteControllerRepo , getRemoteRepositoryLists , setRemoteControllerRepo } from './config' ;
9
9
interface Config {
10
10
repositories : string [ ] ;
11
11
ref ?: string ;
@@ -16,6 +16,13 @@ interface RepoListQuickPickItem extends QuickPickItem {
16
16
repoList : string [ ] ;
17
17
}
18
18
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
+
19
26
/**
20
27
* Gets the repositories to run the query against.
21
28
*/
@@ -43,12 +50,6 @@ export async function getRepositories(): Promise<string[] | undefined> {
43
50
}
44
51
} else {
45
52
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 - _ ] + $ / ;
52
53
const remoteRepo = await window . showInputBox ( {
53
54
title : 'Enter a GitHub repository in the format <owner>/<repo> (e.g. github/codeql)' ,
54
55
placeHolder : '<owner>/<repo>' ,
@@ -58,7 +59,7 @@ export async function getRepositories(): Promise<string[] | undefined> {
58
59
if ( ! remoteRepo ) {
59
60
void showAndLogErrorMessage ( 'No repositories entered.' ) ;
60
61
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
62
63
void showAndLogErrorMessage ( 'Invalid repository format. Must be in the format <owner>/<repo> (e.g. github/codeql)' ) ;
63
64
return ;
64
65
}
@@ -103,18 +104,32 @@ export async function runRemoteQuery(cliServer: cli.CodeQLCliServer, credentials
103
104
return ; // No error message needed, since `getRepositories` already displays one.
104
105
}
105
106
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 ) ;
116
128
}
117
129
130
+ void logger . log ( `Using controller repository: ${ controllerRepo } ` ) ;
131
+ const [ owner , repo ] = controllerRepo . split ( '/' ) ;
132
+
118
133
await runRemoteQueriesApiRequest ( credentials , ref , language , repositories , query , owner , repo ) ;
119
134
}
120
135
0 commit comments