Skip to content

Commit 22d9487

Browse files
committed
Be able to specify language when downloading github database
We offer `github/codeql` as a repo to use for downloading databases for our skeleton pack. Once the repo is specified, the user is prompted to choose a language. At this point, we already know what language the user wants, so let's change the `downloadGitHubDatabase` and `convertGithubNwoToDatabaseUrl` methods to accept a language parameter. We check if the language is in the list of languages received in the response. If it isn't, we still prompt the user.
1 parent 91c4c91 commit 22d9487

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

extensions/ql-vscode/src/databaseFetcher.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export async function downloadGitHubDatabase(
147147
progress: ProgressCallback,
148148
token: CancellationToken,
149149
cli?: CodeQLCliServer,
150+
language?: string,
150151
): Promise<DatabaseItem | undefined> {
151152
const nwo = getNwoFromGitHubUrl(githubRepo) || githubRepo;
152153
if (!isValidGitHubNwo(nwo)) {
@@ -157,7 +158,12 @@ export async function downloadGitHubDatabase(
157158
? await credentials.getOctokit()
158159
: new Octokit.Octokit({ retry });
159160

160-
const result = await convertGithubNwoToDatabaseUrl(nwo, octokit, progress);
161+
const result = await convertGithubNwoToDatabaseUrl(
162+
nwo,
163+
octokit,
164+
progress,
165+
language,
166+
);
161167
if (!result) {
162168
return;
163169
}
@@ -487,6 +493,7 @@ export async function convertGithubNwoToDatabaseUrl(
487493
nwo: string,
488494
octokit: Octokit.Octokit,
489495
progress: ProgressCallback,
496+
language?: string,
490497
): Promise<
491498
| {
492499
databaseUrl: string;
@@ -505,16 +512,24 @@ export async function convertGithubNwoToDatabaseUrl(
505512

506513
const languages = response.data.map((db: any) => db.language);
507514

508-
const language = await promptForLanguage(languages, progress);
509-
if (!language) {
510-
return;
515+
if (language && languages.includes(language)) {
516+
return {
517+
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
518+
owner,
519+
name: repo,
520+
};
521+
} else {
522+
const language = await promptForLanguage(languages, progress);
523+
if (!language) {
524+
return;
525+
}
526+
527+
return {
528+
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
529+
owner,
530+
name: repo,
531+
};
511532
}
512-
513-
return {
514-
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
515-
owner,
516-
name: repo,
517-
};
518533
} catch (e) {
519534
void extLogger.log(`Error: ${getErrorMessage(e)}`);
520535
throw new Error(`Unable to get database for '${nwo}'`);

extensions/ql-vscode/src/skeleton-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export class SkeletonQueryWizard {
2626
ruby: "github/codeql",
2727
javascript: "github/codeql",
2828
go: "github/codeql",
29-
ql: "github/codeql",
3029
};
3130

3231
constructor(
@@ -186,6 +185,7 @@ export class SkeletonQueryWizard {
186185
this.progress,
187186
this.token,
188187
this.cliServer,
188+
this.language,
189189
);
190190
}
191191

0 commit comments

Comments
 (0)