-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add getPacks method to retrieve installed CodeQL packs #9
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
…te findQueryPack to use async
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 enhances the CodeQL service by adding a new getPacks
method to retrieve installed CodeQL packs and refactoring the query pack selection logic to use this new method instead of filesystem-based pack discovery.
- Added
getPacks
method that uses CodeQL CLI to retrieve installed packs with JSON parsing - Refactored
findQueryPack
method to be async and use the newgetPacks
method for pack discovery - Updated
runAnalysis
method to handle the asyncfindQueryPack
call
|
||
public async getPacks(): Promise<string[]> { | ||
this.logger.logServiceCall("CodeQLService", "getPacks", "started"); | ||
var packs: string[] = []; |
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.
Use 'const' instead of 'var' for block-scoped variable declaration. Since 'packs' is reassigned through array methods rather than variable reassignment, it can be declared as const.
var packs: string[] = []; | |
const packs: string[] = []; |
Copilot uses AI. Check for mistakes.
if (!packs.includes(packName)) { | ||
packs.push(packName); |
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 Array.includes() for duplicate checking has O(n) complexity for each insertion, resulting in O(n²) overall complexity. Consider using a Set for O(1) lookups and convert to array at the end.
if (!packs.includes(packName)) { | |
packs.push(packName); | |
if (!packs.has(packName)) { | |
packs.add(packName); |
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <[email protected]>
This pull request introduces enhancements to the
CodeQLService
class, focusing on improving the handling of CodeQL packs and query pack selection. The changes include the addition of a new method to retrieve installed CodeQL packs, refactoring of the query pack selection logic to leverage this new method, and improved error handling and logging.Enhancements to CodeQL pack handling:
getPacks
method: This new method retrieves a list of installed CodeQL packs using the CodeQL CLI, with detailed logging and error handling. It parses the CLI output to extract pack names and ensures no duplicates are included.Refactoring of query pack selection:
Refactored
findQueryPack
method: The method was converted to an asynchronous function that now uses thegetPacks
method to identify the appropriate query pack for a given language. It prioritizes language-specific packs and falls back to a default pack if none are found. Enhanced logging provides better visibility into the selection process.Updated usage of
findQueryPack
: The call tofindQueryPack
in therunAnalysis
method was updated to support its new asynchronous implementation.