Skip to content

Commit c9f0d1b

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/mocked-config
2 parents bc181c6 + 66fd8ad commit c9f0d1b

15 files changed

Lines changed: 129 additions & 42 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## [UNRELEASED]
44

5-
- Renamed command "CodeQL: Run Query" to "CodeQL: Run Query on Selected Dababase".
5+
## 1.7.8 - 2 February 2023
6+
7+
- Renamed command "CodeQL: Run Query" to "CodeQL: Run Query on Selected Database". [#1962](https://github.com/github/vscode-codeql/pull/1962)
68
- Remove support for CodeQL CLI versions older than 2.7.6. [#1788](https://github.com/github/vscode-codeql/pull/1788)
79

810
## 1.7.7 - 13 December 2022

extensions/ql-vscode/databases-schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"$schema": {
55
"type": "string"
66
},
7+
"version": {
8+
"type": "integer"
9+
},
710
"databases": {
811
"type": "object",
912
"properties": {
@@ -119,6 +122,6 @@
119122
]
120123
}
121124
},
122-
"required": ["databases"],
125+
"required": ["databases", "version"],
123126
"additionalProperties": false
124127
}

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: 1 addition & 1 deletion
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.7.8",
7+
"version": "1.7.9",
88
"publisher": "GitHub",
99
"license": "MIT",
1010
"icon": "media/VS-marketplace-CodeQL-icon.png",

extensions/ql-vscode/src/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,16 @@ export class MockGitHubApiConfigListener
638638
export function getMockGitHubApiServerScenariosPath(): string | undefined {
639639
return MOCK_GH_API_SERVER_SCENARIOS_PATH.getValue<string>();
640640
}
641+
642+
/**
643+
* Enables features that are specific to the codespaces-codeql template workspace from
644+
* https://github.com/github/codespaces-codeql.
645+
*/
646+
export const CODESPACES_TEMPLATE = new Setting(
647+
"codespacesTemplate",
648+
ROOT_SETTING,
649+
);
650+
651+
export function isCodespacesTemplate() {
652+
return !!CODESPACES_TEMPLATE.getValue<boolean>();
653+
}

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
CancellationToken,
1313
ThemeIcon,
1414
ThemeColor,
15+
workspace,
1516
} from "vscode";
1617
import { pathExists, stat, readdir, remove } from "fs-extra";
1718

@@ -218,6 +219,15 @@ export class DatabaseUI extends DisposableObject {
218219
},
219220
),
220221
);
222+
this.push(
223+
commandRunnerWithProgress(
224+
"codeQL.setDefaultTourDatabase",
225+
this.handleSetDefaultTourDatabase,
226+
{
227+
title: "Set Default Database for Codespace CodeQL Tour",
228+
},
229+
),
230+
);
221231
this.push(
222232
commandRunnerWithProgress(
223233
"codeQL.upgradeCurrentDatabase",
@@ -348,6 +358,40 @@ export class DatabaseUI extends DisposableObject {
348358
}
349359
};
350360

361+
private handleSetDefaultTourDatabase = async (
362+
progress: ProgressCallback,
363+
token: CancellationToken,
364+
): Promise<void> => {
365+
try {
366+
if (!workspace.workspaceFolders?.length) {
367+
throw new Error("No workspace folder is open.");
368+
} else {
369+
// This specifically refers to the database folder in
370+
// https://github.com/github/codespaces-codeql
371+
const uri = Uri.parse(
372+
`${workspace.workspaceFolders[0].uri}/codeql-tutorial-database`,
373+
);
374+
375+
let databaseItem = this.databaseManager.findDatabaseItem(uri);
376+
if (databaseItem === undefined) {
377+
databaseItem = await this.databaseManager.openDatabase(
378+
progress,
379+
token,
380+
uri,
381+
);
382+
}
383+
await this.databaseManager.setCurrentDatabaseItem(databaseItem);
384+
}
385+
} catch (e) {
386+
// rethrow and let this be handled by default error handling.
387+
throw new Error(
388+
`Could not set the database for the Code Tour. Please make sure you are using the default workspace in your codespace: ${getErrorMessage(
389+
e,
390+
)}`,
391+
);
392+
}
393+
};
394+
351395
handleRemoveOrphanedDatabases = async (): Promise<void> => {
352396
void extLogger.log("Removing orphaned databases from workspace storage.");
353397
let dbDirs = undefined;

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
renameLocalList,
1515
renameRemoteList,
1616
SelectedDbItem,
17+
DB_CONFIG_VERSION,
1718
} from "./db-config";
1819
import * as chokidar from "chokidar";
1920
import { DisposableObject, DisposeHandler } from "../../pure/disposable-object";
@@ -459,6 +460,7 @@ export class DbConfigStore extends DisposableObject {
459460

460461
private createEmptyConfig(): DbConfig {
461462
return {
463+
version: DB_CONFIG_VERSION,
462464
databases: {
463465
variantAnalysis: {
464466
repositoryLists: [],

extensions/ql-vscode/src/databases/config/db-config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
// Contains models for the data we want to store in the database config
1+
// Contains models and consts for the data we want to store in the database config.
2+
// Changes to these models should be done carefully and account for backwards compatibility of data.
3+
4+
export const DB_CONFIG_VERSION = 1;
25

36
export interface DbConfig {
7+
version: number;
48
databases: DbConfigDatabases;
59
selected?: SelectedDbItem;
610
}
@@ -89,6 +93,7 @@ export interface LocalDatabase {
8993

9094
export function cloneDbConfig(config: DbConfig): DbConfig {
9195
return {
96+
version: config.version,
9297
databases: {
9398
variantAnalysis: {
9499
repositoryLists: config.databases.variantAnalysis.repositoryLists.map(

extensions/ql-vscode/test/factories/db-config-factories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
LocalList,
66
RemoteRepositoryList,
77
SelectedDbItem,
8+
DB_CONFIG_VERSION,
89
} from "../../src/databases/config/db-config";
910

1011
export function createDbConfig({
@@ -23,6 +24,7 @@ export function createDbConfig({
2324
selected?: SelectedDbItem;
2425
} = {}): DbConfig {
2526
return {
27+
version: DB_CONFIG_VERSION,
2628
databases: {
2729
variantAnalysis: {
2830
repositoryLists: remoteLists,

extensions/ql-vscode/test/unit-tests/databases/config/data/databases.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"version": 1,
23
"databases": {
34
"variantAnalysis": {
45
"repositoryLists": [

0 commit comments

Comments
 (0)