Skip to content

Commit 4c411ac

Browse files
authored
Merge branch 'main' into aeisenberg/open-query-logger
2 parents d25db48 + ddc941f commit 4c411ac

14 files changed

Lines changed: 133 additions & 69 deletions

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix a bug where database upgrades could not be resolved if some of the target pack's dependencies are outside of the workspace. [#1138](https://github.com/github/vscode-codeql/pull/1138)
66
- Open the query server logs for query errors (instead of the extension log). This will make it easier to track down query errors. [#1158](https://github.com/github/vscode-codeql/pull/1158)
7+
- Fix a bug where queries took a long time to run if there are no folders in the workspace. [#1157](https://github.com/github/vscode-codeql/pull/1157)
78

89
## 1.5.11 - 10 February 2022
910

extensions/ql-vscode/src/cli.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ export class CodeQLCliServer implements Disposable {
514514
async resolveLibraryPath(workspaces: string[], queryPath: string): Promise<QuerySetup> {
515515
const subcommandArgs = [
516516
'--query', queryPath,
517-
'--additional-packs',
518-
workspaces.join(path.delimiter)
517+
...this.getAdditionalPacksArg(workspaces)
519518
];
520519
return await this.runJsonCodeQlCliCommand<QuerySetup>(['resolve', 'library-path'], subcommandArgs, 'Resolving library paths');
521520
}
@@ -528,8 +527,7 @@ export class CodeQLCliServer implements Disposable {
528527
const subcommandArgs = [
529528
'--format', 'bylanguage',
530529
queryUri.fsPath,
531-
'--additional-packs',
532-
workspaces.join(path.delimiter)
530+
...this.getAdditionalPacksArg(workspaces)
533531
];
534532
return JSON.parse(await this.runCodeQlCliCommand(['resolve', 'queries'], subcommandArgs, 'Resolving query by language'));
535533
}
@@ -584,7 +582,7 @@ export class CodeQLCliServer implements Disposable {
584582
): AsyncGenerator<TestCompleted, void, unknown> {
585583

586584
const subcommandArgs = this.cliConfig.additionalTestArguments.concat([
587-
'--additional-packs', workspaces.join(path.delimiter),
585+
...this.getAdditionalPacksArg(workspaces),
588586
'--threads',
589587
this.cliConfig.numberTestThreads.toString(),
590588
...testPaths
@@ -606,8 +604,12 @@ export class CodeQLCliServer implements Disposable {
606604

607605
/** Resolves the ML models that should be available when evaluating a query. */
608606
async resolveMlModels(additionalPacks: string[]): Promise<MlModelsInfo> {
609-
return await this.runJsonCodeQlCliCommand<MlModelsInfo>(['resolve', 'ml-models'], ['--additional-packs',
610-
additionalPacks.join(path.delimiter)], 'Resolving ML models', false);
607+
return await this.runJsonCodeQlCliCommand<MlModelsInfo>(
608+
['resolve', 'ml-models'],
609+
this.getAdditionalPacksArg(additionalPacks),
610+
'Resolving ML models',
611+
false
612+
);
611613
}
612614

613615
/**
@@ -772,7 +774,7 @@ export class CodeQLCliServer implements Disposable {
772774
* @returns A list of database upgrade script directories
773775
*/
774776
async resolveUpgrades(dbScheme: string, searchPath: string[], allowDowngradesIfPossible: boolean, targetDbScheme?: string): Promise<UpgradesInfo> {
775-
const args = ['--additional-packs', searchPath.join(path.delimiter), '--dbscheme', dbScheme];
777+
const args = [...this.getAdditionalPacksArg(searchPath), '--dbscheme', dbScheme];
776778
if (targetDbScheme) {
777779
args.push('--target-dbscheme', targetDbScheme);
778780
if (allowDowngradesIfPossible && await this.cliConstraints.supportsDowngrades()) {
@@ -794,7 +796,7 @@ export class CodeQLCliServer implements Disposable {
794796
* @returns A dictionary mapping qlpack name to the directory it comes from
795797
*/
796798
resolveQlpacks(additionalPacks: string[], searchPath?: string[]): Promise<QlpacksInfo> {
797-
const args = ['--additional-packs', additionalPacks.join(path.delimiter)];
799+
const args = this.getAdditionalPacksArg(additionalPacks);
798800
if (searchPath?.length) {
799801
args.push('--search-path', path.join(...searchPath));
800802
}
@@ -840,7 +842,7 @@ export class CodeQLCliServer implements Disposable {
840842
* @returns A list of query files found.
841843
*/
842844
async resolveQueriesInSuite(suite: string, additionalPacks: string[], searchPath?: string[]): Promise<string[]> {
843-
const args = ['--additional-packs', additionalPacks.join(path.delimiter)];
845+
const args = this.getAdditionalPacksArg(additionalPacks);
844846
if (searchPath !== undefined) {
845847
args.push('--search-path', path.join(...searchPath));
846848
}
@@ -873,8 +875,7 @@ export class CodeQLCliServer implements Disposable {
873875
'-o',
874876
outputPath,
875877
dir,
876-
'--additional-packs',
877-
workspaceFolders.join(path.delimiter)
878+
...this.getAdditionalPacksArg(workspaceFolders)
878879
];
879880
if (!precompile && await this.cliConstraints.supportsNoPrecompile()) {
880881
args.push('--no-precompile');
@@ -929,6 +930,12 @@ export class CodeQLCliServer implements Disposable {
929930
throw new Error('No distribution found');
930931
}
931932
}
933+
934+
private getAdditionalPacksArg(paths: string[]): string[] {
935+
return paths.length
936+
? ['--additional-packs', paths.join(path.delimiter)]
937+
: [];
938+
}
932939
}
933940

934941
/**

extensions/ql-vscode/src/remote-queries/gh-actions-api-client.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@ import { logger } from '../logging';
77
import { RemoteQueryWorkflowResult } from './remote-query-workflow-result';
88
import { DownloadLink } from './download-link';
99
import { RemoteQuery } from './remote-query';
10-
import { RemoteQueryResultIndex, RemoteQueryResultIndexItem } from './remote-query-result-index';
10+
import { RemoteQueryFailureIndexItem, RemoteQueryResultIndex, RemoteQuerySuccessIndexItem } from './remote-query-result-index';
1111

12-
interface ApiResultIndexItem {
12+
interface ApiSuccessIndexItem {
1313
nwo: string;
1414
id: string;
1515
results_count: number;
1616
bqrs_file_size: number;
1717
sarif_file_size?: number;
1818
}
1919

20+
interface ApiFailureIndexItem {
21+
nwo: string;
22+
id: string;
23+
error: string;
24+
}
25+
26+
interface ApiResultIndex {
27+
successes: ApiSuccessIndexItem[];
28+
failures: ApiFailureIndexItem[];
29+
}
30+
2031
export async function getRemoteQueryIndex(
2132
credentials: Credentials,
2233
remoteQuery: RemoteQuery
@@ -31,9 +42,9 @@ export async function getRemoteQueryIndex(
3142

3243
const artifactList = await listWorkflowRunArtifacts(credentials, owner, repoName, workflowRunId);
3344
const resultIndexArtifactId = getArtifactIDfromName('result-index', workflowUri, artifactList);
34-
const resultIndexItems = await getResultIndexItems(credentials, owner, repoName, resultIndexArtifactId);
45+
const resultIndex = await getResultIndex(credentials, owner, repoName, resultIndexArtifactId);
3546

36-
const items = resultIndexItems.map(item => {
47+
const successes = resultIndex?.successes.map(item => {
3748
const artifactId = getArtifactIDfromName(item.id, workflowUri, artifactList);
3849

3950
return {
@@ -42,13 +53,22 @@ export async function getRemoteQueryIndex(
4253
nwo: item.nwo,
4354
resultCount: item.results_count,
4455
bqrsFileSize: item.bqrs_file_size,
45-
sarifFileSize: item.sarif_file_size,
46-
} as RemoteQueryResultIndexItem;
56+
sarifFileSize: item.sarif_file_size
57+
} as RemoteQuerySuccessIndexItem;
58+
});
59+
60+
const failures = resultIndex?.failures.map(item => {
61+
return {
62+
id: item.id.toString(),
63+
nwo: item.nwo,
64+
error: item.error
65+
} as RemoteQueryFailureIndexItem;
4766
});
4867

4968
return {
5069
artifactsUrlPath,
51-
items
70+
successes: successes || [],
71+
failures: failures || []
5272
};
5373
}
5474

@@ -81,17 +101,17 @@ export async function downloadArtifactFromLink(
81101
* @param workflowRunId The ID of the workflow run to get the result index for.
82102
* @returns An object containing the result index.
83103
*/
84-
async function getResultIndexItems(
104+
async function getResultIndex(
85105
credentials: Credentials,
86106
owner: string,
87107
repo: string,
88108
artifactId: number
89-
): Promise<ApiResultIndexItem[]> {
109+
): Promise<ApiResultIndex | undefined> {
90110
const artifactPath = await downloadArtifact(credentials, owner, repo, artifactId);
91111
const indexFilePath = path.join(artifactPath, 'index.json');
92112
if (!(await fs.pathExists(indexFilePath))) {
93113
void showAndLogWarningMessage('Could not find an `index.json` file in the result artifact.');
94-
return [];
114+
return undefined;
95115
}
96116
const resultIndex = await fs.readFile(path.join(artifactPath, 'index.json'), 'utf8');
97117

extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export class RemoteQueriesInterfaceManager {
8282
totalResultCount: totalResultCount,
8383
executionTimestamp: this.formatDate(query.executionStartTime),
8484
executionDuration: executionDuration,
85-
analysisSummaries: analysisSummaries
85+
analysisSummaries: analysisSummaries,
86+
analysisFailures: queryResult.analysisFailures,
8687
};
8788
}
8889

extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export class RemoteQueriesManager {
128128
}
129129

130130
private mapQueryResult(executionEndTime: Date, resultIndex: RemoteQueryResultIndex, queryId: string): RemoteQueryResult {
131-
const analysisSummaries = resultIndex.items.map(item => ({
131+
132+
const analysisSummaries = resultIndex.successes.map(item => ({
132133
nwo: item.nwo,
133134
resultCount: item.resultCount,
134135
fileSizeInBytes: item.sarifFileSize ? item.sarifFileSize : item.bqrsFileSize,
@@ -139,10 +140,15 @@ export class RemoteQueriesManager {
139140
queryId,
140141
} as DownloadLink
141142
}));
143+
const analysisFailures = resultIndex.failures.map(item => ({
144+
nwo: item.nwo,
145+
error: item.error
146+
}));
142147

143148
return {
144149
executionEndTime,
145150
analysisSummaries,
151+
analysisFailures
146152
};
147153
}
148154

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
export interface RemoteQueryResultIndex {
22
artifactsUrlPath: string;
3-
items: RemoteQueryResultIndexItem[];
3+
successes: RemoteQuerySuccessIndexItem[];
4+
failures: RemoteQueryFailureIndexItem[];
45
}
56

6-
export interface RemoteQueryResultIndexItem {
7+
export interface RemoteQuerySuccessIndexItem {
78
id: string;
89
artifactId: number;
910
nwo: string;
1011
resultCount: number;
1112
bqrsFileSize: number;
1213
sarifFileSize?: number;
1314
}
15+
16+
export interface RemoteQueryFailureIndexItem {
17+
id: string;
18+
artifactId: number;
19+
nwo: string;
20+
error: string;
21+
}

extensions/ql-vscode/src/remote-queries/remote-query-result.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { DownloadLink } from './download-link';
2+
import { AnalysisFailure } from './shared/analysis-failure';
23

34
export interface RemoteQueryResult {
45
executionEndTime: Date;
56
analysisSummaries: AnalysisSummary[];
7+
analysisFailures: AnalysisFailure[];
68
}
79

810
export interface AnalysisSummary {

extensions/ql-vscode/src/remote-queries/sample-data.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ export const sampleRemoteQueryResult: RemoteQueryResult = {
8383
queryId: 'query.ql-123-xyz'
8484
}
8585
}
86+
],
87+
analysisFailures: [
88+
{
89+
nwo: 'big-corp/repo5',
90+
error: 'Error message'
91+
},
92+
{
93+
nwo: 'big-corp/repo6',
94+
error: 'Error message'
95+
},
8696
]
8797
};
8898

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface AnalysisFailure {
2+
nwo: string,
3+
error: string
4+
}

extensions/ql-vscode/src/remote-queries/shared/remote-query-result.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DownloadLink } from '../download-link';
2+
import { AnalysisFailure } from './analysis-failure';
23

34
export interface RemoteQueryResult {
45
queryTitle: string;
@@ -10,7 +11,8 @@ export interface RemoteQueryResult {
1011
totalResultCount: number;
1112
executionTimestamp: string;
1213
executionDuration: string;
13-
analysisSummaries: AnalysisSummary[]
14+
analysisSummaries: AnalysisSummary[],
15+
analysisFailures: AnalysisFailure[];
1416
}
1517

1618
export interface AnalysisSummary {

0 commit comments

Comments
 (0)