-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: Add CodeQL CLI discovery and auto-installation capabilities #5
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: felickz <[email protected]>
…ntation Co-authored-by: felickz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, will do testing before release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements automatic CodeQL CLI discovery and installation functionality to streamline the setup process for users. The extension now handles CodeQL CLI setup with minimal user intervention while maintaining backward compatibility.
- Enhanced CodeQL CLI detection with automatic discovery from GitHub's CodeQL extension
- Added auto-installation capability with user consent and progress tracking
- Implemented new commands for manual CLI installation and information display
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
File | Description |
---|---|
src/services/codeqlService.ts | Core functionality for CLI discovery, GitHub API integration, and auto-installation logic |
src/extension.ts | New command registration for CLI info display and manual installation |
package.json | Command definitions and configuration options for auto-detection and auto-installation |
README.md | Updated documentation highlighting new auto-discovery and auto-installation features |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
/** | ||
* Get the latest CodeQL release information from GitHub | ||
*/ | ||
public async getLatestCodeQLRelease(): Promise<any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type any
is too broad and makes the API unpredictable. Consider defining a proper interface for the GitHub release response with required fields like assets
, tag_name
, etc.
public async getLatestCodeQLRelease(): Promise<any> { | |
public async getLatestCodeQLRelease(): Promise<GitHubRelease> { |
Copilot uses AI. Check for mistakes.
cancellationToken: vscode.CancellationToken | ||
): Promise<string> { | ||
const platform = this.getCurrentPlatform(); | ||
const asset = releaseInfo.assets.find((asset: any) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The releaseInfo
parameter uses any
type, which lacks type safety. This should use the same proper interface as suggested for getLatestCodeQLRelease()
.
const asset = releaseInfo.assets.find((asset: any) => | |
releaseInfo: CodeQLReleaseInfo, | |
progress: vscode.Progress<{ increment?: number; message?: string }>, | |
cancellationToken: vscode.CancellationToken | |
): Promise<string> { | |
const platform = this.getCurrentPlatform(); | |
const asset = releaseInfo.assets.find((asset: CodeQLReleaseAsset) => |
Copilot uses AI. Check for mistakes.
cancellationToken: vscode.CancellationToken | ||
): Promise<string> { | ||
const platform = this.getCurrentPlatform(); | ||
const asset = releaseInfo.assets.find((asset: any) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using any
type for asset parameter in the find callback removes type safety. The asset should have a proper type with name
and browser_download_url
properties.
const asset = releaseInfo.assets.find((asset: any) => | |
releaseInfo: CodeQLReleaseInfo, | |
progress: vscode.Progress<{ increment?: number; message?: string }>, | |
cancellationToken: vscode.CancellationToken | |
): Promise<string> { | |
const platform = this.getCurrentPlatform(); | |
const asset = releaseInfo.assets.find((asset: CodeQLReleaseAsset) => |
Copilot uses AI. Check for mistakes.
fs.rmSync(extractDir, { recursive: true, force: true }); | ||
} catch { | ||
// Fallback for older Node.js versions | ||
await execAsync(`rm -rf "${extractDir}"`).catch(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback command rm -rf
with user-controlled path could be dangerous if the extractDir contains shell metacharacters. Consider using fs.rmSync
with proper error handling or a more secure alternative like rimraf
library.
Copilot uses AI. Check for mistakes.
await execAsync(`powershell -command "Expand-Archive -Path '${zipPath}' -DestinationPath '${extractDir}' -Force"`); | ||
} else { | ||
// Use unzip on Unix systems | ||
await execAsync(`unzip -o "${zipPath}" -d "${extractDir}"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct string interpolation into shell commands is unsafe if paths contain special characters. Use proper shell escaping or parameterized commands to prevent command injection.
await execAsync(`unzip -o "${zipPath}" -d "${extractDir}"`); | |
await execFileAsync( | |
"powershell", | |
[ | |
"-NoProfile", | |
"-Command", | |
"Expand-Archive -Path '" + zipPath.replace(/'/g, "''") + "' -DestinationPath '" + extractDir.replace(/'/g, "''") + "' -Force" | |
] | |
); | |
} else { | |
// Use unzip on Unix systems | |
await execFileAsync( | |
"unzip", | |
[ | |
"-o", | |
zipPath, | |
"-d", | |
extractDir | |
] | |
); |
Copilot uses AI. Check for mistakes.
await execAsync(`powershell -command "Expand-Archive -Path '${zipPath}' -DestinationPath '${extractDir}' -Force"`); | ||
} else { | ||
// Use unzip on Unix systems | ||
await execAsync(`unzip -o "${zipPath}" -d "${extractDir}"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct string interpolation into shell commands creates command injection risk. Even with double quotes, paths containing special characters or command sequences could be dangerous. Use proper shell escaping or a zip library instead.
Copilot uses AI. Check for mistakes.
} else if (platform === 'darwin') { | ||
return 'osx64'; | ||
} else if (platform === 'linux') { | ||
return arch === 'x64' ? 'linux64' : 'linux'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic assumes only x64 and x86 architectures exist on Windows. ARM64 Windows systems would incorrectly get 'win32' instead of a proper ARM64 identifier. Consider handling additional architectures or documenting the limitation.
return arch === 'x64' ? 'linux64' : 'linux'; | |
/** | |
* Get the current platform identifier for CodeQL CLI downloads | |
* Supported architectures: x64, arm64 (Windows, Linux, macOS) | |
*/ | |
private getCurrentPlatform(): string { | |
const platform = os.platform(); | |
const arch = os.arch(); | |
if (platform === 'win32') { | |
if (arch === 'x64') { | |
return 'win64'; | |
} else if (arch === 'arm64') { | |
return 'winarm64'; | |
} else if (arch === 'ia32') { | |
return 'win32'; | |
} | |
} else if (platform === 'darwin') { | |
if (arch === 'x64') { | |
return 'osx64'; | |
} else if (arch === 'arm64') { | |
return 'osxarm64'; | |
} | |
} else if (platform === 'linux') { | |
if (arch === 'x64') { | |
return 'linux64'; | |
} else if (arch === 'arm64') { | |
return 'linuxarm64'; | |
} |
Copilot uses AI. Check for mistakes.
} else if (platform === 'darwin') { | ||
return 'osx64'; | ||
} else if (platform === 'linux') { | ||
return arch === 'x64' ? 'linux64' : 'linux'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic doesn't handle ARM64 Linux systems correctly. ARM64 architecture would fallback to 'linux' which may not be the correct platform identifier for CodeQL CLI downloads.
return arch === 'x64' ? 'linux64' : 'linux'; | |
if (arch === 'x64') { | |
return 'linux64'; | |
} else if (arch === 'arm64') { | |
return 'linux64-arm'; | |
} else { | |
return 'linux'; | |
} |
Copilot uses AI. Check for mistakes.
@@ -292,21 +293,361 @@ export class CodeQLService { | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot detected a code snippet with 1 occurrences. See search results for more details.
Matched Code Snippet
response.statusCode}`));
return;
}
response.pipe(file);
file.on('finish', () => {
file.close();
resolve();
});
file.on('error', (error)
Copilot uses AI. Check for mistakes.
This PR implements automatic CodeQL CLI discovery and installation functionality to address the requirement for seamless CodeQL setup without manual intervention.
🚀 Features Added
Auto-Discovery
Auto-Installation
New Commands
CodeQL: Install/Update CLI
- Manually trigger CodeQL CLI installationCodeQL: Show CLI Information
- Display current CLI version and pathConfiguration Options
codeql-scanner.autoDetectGitHubExtension
(default: true) - Enable GitHub extension discoverycodeql-scanner.autoInstallCodeQL
(default: true) - Enable automatic installation prompts🔧 Implementation Details
Enhanced CLI Detection Flow
Robust Error Handling
Cross-Platform Support
.exe
on Windows)📚 Documentation Updates
Updated README.md to reflect:
🧪 Testing
Example User Experience
Before: Users had to manually download, extract, and configure CodeQL CLI
After: Seamless automatic setup
Breaking Changes
None. All changes are additive and backward compatible.
Fixes #2.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/github/codeql-cli-binaries/releases/latest
node test-codeql-discovery.js
(http block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.