-
Notifications
You must be signed in to change notification settings - Fork 226
Add "pack install" and "pack download" commands #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
74ae0bc
c3c422f
da59c42
9efa7ae
9a780c4
3c4838d
7a04ff0
5c5a1b2
c46ace4
0185c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import { CodeQLCliServer } from './cli'; | ||
| import * as fs from 'fs-extra'; | ||
| import * as path from 'path'; | ||
| import { | ||
| getOnDiskWorkspaceFolders, | ||
| showAndLogErrorMessage, | ||
| showAndLogInformationMessage, | ||
| } from './helpers'; | ||
| import { window } from 'vscode'; | ||
| import { ProgressCallback } from './commandRunner'; | ||
|
|
||
| const CORE_PACKS = [ | ||
| 'codeql/cpp-all', | ||
| 'codeql/csharp-all', | ||
| 'codeql/go-all', | ||
| 'codeql/java-all', | ||
| 'codeql/javascript-all', | ||
| 'codeql/python-all', | ||
| 'codeql/ruby-all', | ||
| ]; | ||
|
shati-patel marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * Lists all workspace folders that contain a qlpack.yml file. | ||
| * | ||
| * Note: This currently only finds packs at the root of a workspace folder. | ||
| * TODO: Add support for packs in subfolders. | ||
| */ | ||
| function getWorkspacePacks(): string[] { | ||
| const packs: string[] = []; | ||
| const workspaceFolders = getOnDiskWorkspaceFolders(); | ||
| for (const folder of workspaceFolders) { | ||
| const qlpackYml = path.join(folder, 'qlpack.yml'); | ||
| if (fs.pathExistsSync(qlpackYml)) { | ||
| packs.push(folder); | ||
| } | ||
| } | ||
| return packs; | ||
| } | ||
|
shati-patel marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * Prompts user to choose packs to download, and downloads them. | ||
| * | ||
| * @param cliServer The CLI server. | ||
| * @param progress A progress callback. | ||
| */ | ||
| export async function handleDownloadPacks( | ||
| cliServer: CodeQLCliServer, | ||
| progress: ProgressCallback, | ||
| ): Promise<void> { | ||
| progress({ | ||
| message: 'Choose packs to download', | ||
| step: 1, | ||
| maxStep: 2, | ||
| }); | ||
| let packsToDownload: string[] = []; | ||
| const corePackOption = 'Download core CodeQL packs'; | ||
| const customPackOption = 'Download custom specified pack'; | ||
| const quickpick = await window.showQuickPick( | ||
| [corePackOption, customPackOption], | ||
| { ignoreFocusOut: true } | ||
| ); | ||
| if (quickpick === corePackOption) { | ||
| packsToDownload = CORE_PACKS; | ||
| } else if (quickpick === customPackOption) { | ||
| const customPack = await window.showInputBox({ | ||
| prompt: | ||
| 'Enter the <package-scope/name[@version]> of the pack to download', | ||
| ignoreFocusOut: true, | ||
| }); | ||
| if (customPack) { | ||
| packsToDownload.push(customPack); | ||
| } else { | ||
| void showAndLogErrorMessage('No pack specified.'); | ||
| } | ||
| } | ||
| if (packsToDownload && packsToDownload.length > 0) { | ||
|
shati-patel marked this conversation as resolved.
Outdated
|
||
| progress({ | ||
| message: `Downloading ${packsToDownload.join(', ')}`, | ||
| step: 2, | ||
| maxStep: 2, | ||
| }); | ||
| for (const pack of packsToDownload) { | ||
| try { | ||
| await cliServer.packDownload(pack); | ||
|
shati-patel marked this conversation as resolved.
Outdated
|
||
| } catch (error) { | ||
| void showAndLogErrorMessage(`Unable to download pack ${pack}. See logs for more details.`); | ||
| } | ||
| } | ||
| void showAndLogInformationMessage('Finished downloading packs.'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Prompts user to choose packs to install, and installs them. | ||
| * | ||
| * @param cliServer The CLI server. | ||
| * @param progress A progress callback. | ||
| */ | ||
| export async function handleInstallPacks( | ||
| cliServer: CodeQLCliServer, | ||
| progress: ProgressCallback, | ||
| ): Promise<void> { | ||
| progress({ | ||
| message: 'Choose packs to install', | ||
| step: 1, | ||
| maxStep: 2, | ||
| }); | ||
| let packsToInstall: string[] = []; | ||
| const workspacePackOption = 'Install workspace packs'; | ||
| const customPackOption = 'Install custom specified pack'; | ||
|
shati-patel marked this conversation as resolved.
Outdated
|
||
| const quickpick = await window.showQuickPick( | ||
| [workspacePackOption, customPackOption], | ||
| { ignoreFocusOut: true } | ||
| ); | ||
| if (quickpick === workspacePackOption) { | ||
| packsToInstall = getWorkspacePacks(); | ||
| } else if (quickpick === customPackOption) { | ||
| const customPack = await window.showInputBox({ | ||
| prompt: | ||
| 'Enter the root directory of the pack to install (as an absolute path)', | ||
| ignoreFocusOut: true, | ||
| }); | ||
| if (customPack) { | ||
| packsToInstall.push(customPack); | ||
| } else { | ||
| void showAndLogErrorMessage('No pack specified.'); | ||
| } | ||
| } | ||
| if (packsToInstall && packsToInstall.length > 0) { | ||
| progress({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: You know the total number of root packs, so you could make the progress monitor actually reflect the progress through the root packs. Save that for a future PR though :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! I will try that in a follow-up PR 🔄 |
||
| message: `Installing ${packsToInstall.join(', ')}`, | ||
| step: 2, | ||
| maxStep: 2, | ||
| }); | ||
| for (const pack of packsToInstall) { | ||
| try { | ||
| await cliServer.packInstall(pack); | ||
| } catch (error) { | ||
| void showAndLogErrorMessage(`Unable to install pack ${pack}. See logs for more details.`); | ||
| } | ||
| } | ||
| void showAndLogInformationMessage('Finished installing packs.'); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.