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.
This commit is contained in:
@@ -147,6 +147,7 @@ export async function downloadGitHubDatabase(
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken,
|
||||
cli?: CodeQLCliServer,
|
||||
language?: string,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
const nwo = getNwoFromGitHubUrl(githubRepo) || githubRepo;
|
||||
if (!isValidGitHubNwo(nwo)) {
|
||||
@@ -157,7 +158,12 @@ export async function downloadGitHubDatabase(
|
||||
? await credentials.getOctokit()
|
||||
: new Octokit.Octokit({ retry });
|
||||
|
||||
const result = await convertGithubNwoToDatabaseUrl(nwo, octokit, progress);
|
||||
const result = await convertGithubNwoToDatabaseUrl(
|
||||
nwo,
|
||||
octokit,
|
||||
progress,
|
||||
language,
|
||||
);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
@@ -487,6 +493,7 @@ export async function convertGithubNwoToDatabaseUrl(
|
||||
nwo: string,
|
||||
octokit: Octokit.Octokit,
|
||||
progress: ProgressCallback,
|
||||
language?: string,
|
||||
): Promise<
|
||||
| {
|
||||
databaseUrl: string;
|
||||
@@ -505,16 +512,24 @@ export async function convertGithubNwoToDatabaseUrl(
|
||||
|
||||
const languages = response.data.map((db: any) => db.language);
|
||||
|
||||
const language = await promptForLanguage(languages, progress);
|
||||
if (!language) {
|
||||
return;
|
||||
}
|
||||
if (language && languages.includes(language)) {
|
||||
return {
|
||||
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
|
||||
owner,
|
||||
name: repo,
|
||||
};
|
||||
} else {
|
||||
const language = await promptForLanguage(languages, progress);
|
||||
if (!language) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
|
||||
owner,
|
||||
name: repo,
|
||||
};
|
||||
return {
|
||||
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
|
||||
owner,
|
||||
name: repo,
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
void extLogger.log(`Error: ${getErrorMessage(e)}`);
|
||||
throw new Error(`Unable to get database for '${nwo}'`);
|
||||
|
||||
@@ -26,7 +26,6 @@ export class SkeletonQueryWizard {
|
||||
ruby: "github/codeql",
|
||||
javascript: "github/codeql",
|
||||
go: "github/codeql",
|
||||
ql: "github/codeql",
|
||||
};
|
||||
|
||||
constructor(
|
||||
@@ -186,6 +185,7 @@ export class SkeletonQueryWizard {
|
||||
this.progress,
|
||||
this.token,
|
||||
this.cliServer,
|
||||
this.language,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user