Skip to content

Commit 1d195cb

Browse files
author
Dave Bartolomeo
committed
Merge remote-tracking branch 'origin/main' into dbartol/join-order
2 parents 8d8ed28 + e12bf63 commit 1d195cb

39 files changed

Lines changed: 1542 additions & 215 deletions

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ jobs:
135135
strategy:
136136
matrix:
137137
os: [ubuntu-latest, windows-latest]
138-
version: ['v2.3.3', 'v2.4.6', 'v2.5.9', 'v2.6.3', 'v2.7.6', 'v2.8.5', 'nightly']
138+
version: ['v2.3.3', 'v2.4.6', 'v2.5.9', 'v2.6.3', 'v2.7.6', 'v2.8.5', 'v2.9.0', 'nightly']
139139
env:
140140
CLI_VERSION: ${{ matrix.version }}
141141
NIGHTLY_URL: ${{ needs.find-nightly.outputs.url }}

extensions/ql-vscode/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [UNRELEASED]
44

5+
## 1.6.5 - 25 April 2022
6+
57
- Re-enable publishing to open-vsx. [#1285](https://github.com/github/vscode-codeql/pull/1285)
68

79
## 1.6.4 - 6 April 2022

extensions/ql-vscode/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "CodeQL for Visual Studio Code",
55
"author": "GitHub",
66
"private": true,
7-
"version": "1.6.5",
7+
"version": "1.6.6",
88
"publisher": "GitHub",
99
"license": "MIT",
1010
"icon": "media/VS-marketplace-CodeQL-icon.png",
@@ -739,12 +739,12 @@
739739
{
740740
"command": "codeQLQueryHistory.showEvalLog",
741741
"group": "9_qlCommands",
742-
"when": "codeql.supportsEvalLog && (viewItem == rawResultsItem || viewItem == interpretedResultsItem || viewItem == cancelledResultsItem)"
742+
"when": "codeql.supportsEvalLog && viewItem == rawResultsItem || codeql.supportsEvalLog && viewItem == interpretedResultsItem || codeql.supportsEvalLog && viewItem == cancelledResultsItem"
743743
},
744744
{
745745
"command": "codeQLQueryHistory.showEvalLogSummary",
746746
"group": "9_qlCommands",
747-
"when": "codeql.supportsEvalLog && (viewItem == rawResultsItem || viewItem == interpretedResultsItem || viewItem == cancelledResultsItem)"
747+
"when": "codeql.supportsEvalLog && viewItem == rawResultsItem || codeql.supportsEvalLog && viewItem == interpretedResultsItem || codeql.supportsEvalLog && viewItem == cancelledResultsItem"
748748
},
749749
{
750750
"command": "codeQLQueryHistory.scanEvalLog",

extensions/ql-vscode/src/databaseFetcher.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export async function promptImportInternetDatabase(
5151
{},
5252
databaseManager,
5353
storagePath,
54+
undefined,
5455
progress,
5556
token,
5657
cli
@@ -98,11 +99,13 @@ export async function promptImportGithubDatabase(
9899
throw new Error(`Invalid GitHub repository: ${githubRepo}`);
99100
}
100101

101-
const databaseUrl = await convertGithubNwoToDatabaseUrl(githubRepo, credentials, progress);
102-
if (!databaseUrl) {
102+
const result = await convertGithubNwoToDatabaseUrl(githubRepo, credentials, progress);
103+
if (!result) {
103104
return;
104105
}
105106

107+
const { databaseUrl, name, owner } = result;
108+
106109
const octokit = await credentials.getOctokit();
107110
/**
108111
* The 'token' property of the token object returned by `octokit.auth()`.
@@ -125,6 +128,7 @@ export async function promptImportGithubDatabase(
125128
{ 'Accept': 'application/zip', 'Authorization': `Bearer ${octokitToken}` },
126129
databaseManager,
127130
storagePath,
131+
`${owner}/${name}`,
128132
progress,
129133
token,
130134
cli
@@ -173,6 +177,7 @@ export async function promptImportLgtmDatabase(
173177
{},
174178
databaseManager,
175179
storagePath,
180+
undefined,
176181
progress,
177182
token,
178183
cli
@@ -220,6 +225,7 @@ export async function importArchiveDatabase(
220225
{},
221226
databaseManager,
222227
storagePath,
228+
undefined,
223229
progress,
224230
token,
225231
cli
@@ -247,6 +253,7 @@ export async function importArchiveDatabase(
247253
* @param requestHeaders Headers to send with the request
248254
* @param databaseManager the DatabaseManager
249255
* @param storagePath where to store the unzipped database.
256+
* @param nameOverride a name for the database that overrides the default
250257
* @param progress callback to send progress messages to
251258
* @param token cancellation token
252259
*/
@@ -255,6 +262,7 @@ async function databaseArchiveFetcher(
255262
requestHeaders: { [key: string]: string },
256263
databaseManager: DatabaseManager,
257264
storagePath: string,
265+
nameOverride: string | undefined,
258266
progress: ProgressCallback,
259267
token: CancellationToken,
260268
cli?: CodeQLCliServer,
@@ -296,7 +304,7 @@ async function databaseArchiveFetcher(
296304
});
297305
await ensureZippedSourceLocation(dbPath);
298306

299-
const item = await databaseManager.openDatabase(progress, token, Uri.file(dbPath));
307+
const item = await databaseManager.openDatabase(progress, token, Uri.file(dbPath), nameOverride);
300308
await databaseManager.setCurrentDatabaseItem(item);
301309
return item;
302310
} else {
@@ -409,7 +417,6 @@ async function fetchAndUnzip(
409417

410418
await readAndUnzip(Uri.file(archivePath).toString(true), unzipPath, cli, progress);
411419

412-
413420
// remove archivePath eagerly since these archives can be large.
414421
await fs.remove(archivePath);
415422
}
@@ -517,7 +524,11 @@ function convertGitHubUrlToNwo(githubUrl: string): string | undefined {
517524
export async function convertGithubNwoToDatabaseUrl(
518525
githubRepo: string,
519526
credentials: Credentials,
520-
progress: ProgressCallback): Promise<string | undefined> {
527+
progress: ProgressCallback): Promise<{
528+
databaseUrl: string,
529+
owner: string,
530+
name: string
531+
} | undefined> {
521532
try {
522533
const nwo = convertGitHubUrlToNwo(githubRepo) || githubRepo;
523534
const [owner, repo] = nwo.split('/');
@@ -532,7 +543,11 @@ export async function convertGithubNwoToDatabaseUrl(
532543
return;
533544
}
534545

535-
return `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`;
546+
return {
547+
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
548+
owner,
549+
name: repo
550+
};
536551

537552
} catch (e) {
538553
void logger.log(`Error: ${getErrorMessage(e)}`);

extensions/ql-vscode/src/databases.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export async function findSourceArchive(
148148
}
149149

150150
async function resolveDatabase(
151-
databasePath: string
151+
databasePath: string,
152152
): Promise<DatabaseContents> {
153153

154154
const name = path.basename(databasePath);
@@ -170,7 +170,9 @@ async function getDbSchemeFiles(dbDirectory: string): Promise<string[]> {
170170
return await glob('*.dbscheme', { cwd: dbDirectory });
171171
}
172172

173-
async function resolveDatabaseContents(uri: vscode.Uri): Promise<DatabaseContents> {
173+
async function resolveDatabaseContents(
174+
uri: vscode.Uri,
175+
): Promise<DatabaseContents> {
174176
if (uri.scheme !== 'file') {
175177
throw new Error(`Database URI scheme '${uri.scheme}' not supported; only 'file' URIs are supported.`);
176178
}
@@ -569,14 +571,15 @@ export class DatabaseManager extends DisposableObject {
569571
progress: ProgressCallback,
570572
token: vscode.CancellationToken,
571573
uri: vscode.Uri,
574+
displayName?: string
572575
): Promise<DatabaseItem> {
573576
const contents = await resolveDatabaseContents(uri);
574577
// Ignore the source archive for QLTest databases by default.
575578
const isQLTestDatabase = path.extname(uri.fsPath) === '.testproj';
576579
const fullOptions: FullDatabaseOptions = {
577580
ignoreSourceArchive: isQLTestDatabase,
578-
// displayName is only set if a user explicitly renames a database
579-
displayName: undefined,
581+
// If a displayName is not passed in, the basename of folder containing the database is used.
582+
displayName,
580583
dateAdded: Date.now(),
581584
language: await this.getPrimaryLanguage(uri.fsPath)
582585
};

extensions/ql-vscode/src/helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ export async function showAndLogWarningMessage(message: string, {
7676
*/
7777
export async function showAndLogInformationMessage(message: string, {
7878
outputLogger = logger,
79-
items = [] as string[]
79+
items = [] as string[],
80+
fullMessage = ''
8081
} = {}): Promise<string | undefined> {
81-
return internalShowAndLog(message, items, outputLogger, Window.showInformationMessage);
82+
return internalShowAndLog(message, items, outputLogger, Window.showInformationMessage, fullMessage);
8283
}
8384

8485
type ShowMessageFn = (message: string, ...items: string[]) => Thenable<string | undefined>;

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export async function getRemoteQueryIndex(
4242
const artifactsUrlPath = `/repos/${owner}/${repoName}/actions/artifacts`;
4343

4444
const artifactList = await listWorkflowRunArtifacts(credentials, owner, repoName, workflowRunId);
45-
const resultIndexArtifactId = getArtifactIDfromName('result-index', workflowUri, artifactList);
45+
const resultIndexArtifactId = tryGetArtifactIDfromName('result-index', artifactList);
46+
if (!resultIndexArtifactId) {
47+
return undefined;
48+
}
4649
const resultIndex = await getResultIndex(credentials, owner, repoName, resultIndexArtifactId);
4750

4851
const successes = resultIndex?.successes.map(item => {
@@ -223,15 +226,29 @@ function getArtifactIDfromName(
223226
workflowUri: string,
224227
artifacts: Array<{ id: number, name: string }>
225228
): number {
226-
const artifact = artifacts.find(a => a.name === artifactName);
229+
const artifactId = tryGetArtifactIDfromName(artifactName, artifacts);
227230

228-
if (!artifact) {
231+
if (!artifactId) {
229232
const errorMessage =
230233
`Could not find artifact with name ${artifactName} in workflow ${workflowUri}.
231234
Please check whether the workflow run has successfully completed.`;
232235
throw Error(errorMessage);
233236
}
234237

238+
return artifactId;
239+
}
240+
241+
/**
242+
* @param artifactName The artifact name, as a string.
243+
* @param artifacts An array of artifact details (from the "list workflow run artifacts" API response).
244+
* @returns The artifact ID corresponding to the given artifact name, if it exists.
245+
*/
246+
function tryGetArtifactIDfromName(
247+
artifactName: string,
248+
artifacts: Array<{ id: number, name: string }>
249+
): number | undefined {
250+
const artifact = artifacts.find(a => a.name === artifactName);
251+
235252
return artifact?.id;
236253
}
237254

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { AnalysisResults } from './shared/analysis-result';
3030
export class RemoteQueriesInterfaceManager {
3131
private panel: WebviewPanel | undefined;
3232
private panelLoaded = false;
33+
private currentQueryId: string | undefined;
3334
private panelLoadedCallBacks: (() => void)[] = [];
3435

3536
constructor(
@@ -47,6 +48,8 @@ export class RemoteQueriesInterfaceManager {
4748

4849
await this.waitForPanelLoaded();
4950
const model = this.buildViewModel(query, queryResult);
51+
this.currentQueryId = queryResult.queryId;
52+
5053
await this.postMessage({
5154
t: 'setRemoteQueryResult',
5255
queryResult: model
@@ -55,7 +58,7 @@ export class RemoteQueriesInterfaceManager {
5558
// Ensure all pre-downloaded artifacts are loaded into memory
5659
await this.analysesResultsManager.loadDownloadedAnalyses(model.analysisSummaries);
5760

58-
await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId));
61+
await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId), queryResult.queryId);
5962
}
6063

6164
/**
@@ -111,6 +114,7 @@ export class RemoteQueriesInterfaceManager {
111114
this.panel.onDidDispose(
112115
() => {
113116
this.panel = undefined;
117+
this.currentQueryId = undefined;
114118
},
115119
null,
116120
ctx.subscriptions
@@ -212,23 +216,25 @@ export class RemoteQueriesInterfaceManager {
212216
}
213217

214218
private async downloadAnalysisResults(msg: RemoteQueryDownloadAnalysisResultsMessage): Promise<void> {
219+
const queryId = this.currentQueryId;
215220
await this.analysesResultsManager.downloadAnalysisResults(
216221
msg.analysisSummary,
217-
results => this.setAnalysisResults(results));
222+
results => this.setAnalysisResults(results, queryId));
218223
}
219224

220225
private async downloadAllAnalysesResults(msg: RemoteQueryDownloadAllAnalysesResultsMessage): Promise<void> {
226+
const queryId = this.currentQueryId;
221227
await this.analysesResultsManager.loadAnalysesResults(
222228
msg.analysisSummaries,
223229
undefined,
224-
results => this.setAnalysisResults(results));
230+
results => this.setAnalysisResults(results, queryId));
225231
}
226232

227-
public async setAnalysisResults(analysesResults: AnalysisResults[]): Promise<void> {
228-
if (this.panel?.active) {
233+
public async setAnalysisResults(analysesResults: AnalysisResults[], queryId: string | undefined): Promise<void> {
234+
if (this.panel?.active && this.currentQueryId === queryId) {
229235
await this.postMessage({
230236
t: 'setAnalysesResults',
231-
analysesResults: analysesResults
237+
analysesResults
232238
});
233239
}
234240
}

0 commit comments

Comments
 (0)