Skip to content

Conversation

GeekMasher
Copy link
Contributor

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:

  • Added 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 the getPacks 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 to findQueryPack in the runAnalysis method was updated to support its new asynchronous implementation.

@GeekMasher GeekMasher marked this pull request as ready for review July 22, 2025 14:38
@Copilot Copilot AI review requested due to automatic review settings July 22, 2025 14:38
Copy link
Contributor

@Copilot Copilot AI left a 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 new getPacks method for pack discovery
  • Updated runAnalysis method to handle the async findQueryPack call


public async getPacks(): Promise<string[]> {
this.logger.logServiceCall("CodeQLService", "getPacks", "started");
var packs: string[] = [];
Copy link
Preview

Copilot AI Jul 22, 2025

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.

Suggested change
var packs: string[] = [];
const packs: string[] = [];

Copilot uses AI. Check for mistakes.

Comment on lines +450 to +451
if (!packs.includes(packName)) {
packs.push(packName);
Copy link
Preview

Copilot AI Jul 22, 2025

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.

Suggested change
if (!packs.includes(packName)) {
packs.push(packName);
if (!packs.has(packName)) {
packs.add(packName);

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant