Skip to content

Commit fe0c10a

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/find-github-repository
2 parents 5db1f76 + d360815 commit fe0c10a

45 files changed

Lines changed: 478 additions & 190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

extensions/ql-vscode/CHANGELOG.md

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

33
## [UNRELEASED]
44

5+
- Add new CodeQL views for managing databases and queries:
6+
1. A queries panel, to create and run queries in one place.
7+
2. A language selector, to quickly determine the language compatibility of databases and queries.
8+
9+
For more information, see the [documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/analyzing-your-projects/#filtering-databases-and-queries-by-language).
10+
- When adding a CodeQL database, we no longer add the database source folder to the workspace by default (since this caused bugs in single-folder workspaces). [#3047](https://github.com/github/vscode-codeql/pull/3047)
11+
- You can manually add individual database source folders to the workspace with the "Add Database Source to Workspace" right-click command in the databases view.
12+
- To restore the old behavior of adding all database source folders by default, set the `codeQL.addingDatabases.addDatabaseSourceToWorkspace` setting to `true`.
13+
- Rename the `codeQL.databaseDownload.allowHttp` setting to `codeQL.addingDatabases.allowHttp`, so that database-related settings are grouped together in the Settings UI. [#3047](https://github.com/github/vscode-codeql/pull/3047) & [#3069](https://github.com/github/vscode-codeql/pull/3069)
514
- The "Sort by Language" action in the databases view now sorts by name within each language. [#3055](https://github.com/github/vscode-codeql/pull/3055)
615

716
## 1.9.4 - 6 November 2023

extensions/ql-vscode/package-lock.json

Lines changed: 6 additions & 6 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: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,23 @@
374374
},
375375
{
376376
"type": "object",
377-
"title": "Downloading databases",
377+
"title": "Adding databases",
378378
"order": 6,
379379
"properties": {
380+
"codeQL.addingDatabases.allowHttp": {
381+
"type": "boolean",
382+
"default": false,
383+
"description": "Allow databases to be downloaded via HTTP. Warning: enabling this option will allow downloading from insecure servers."
384+
},
380385
"codeQL.databaseDownload.allowHttp": {
386+
"type": "boolean",
387+
"markdownDeprecationMessage": "**Deprecated**: Please use `#codeQL.addingDatabases.allowHttp#` instead.",
388+
"deprecationMessage": "Deprecated: Please use codeQL.addingDatabases.allowHttp instead."
389+
},
390+
"codeQL.addingDatabases.addDatabaseSourceToWorkspace": {
381391
"type": "boolean",
382392
"default": false,
383-
"description": "Allow database to be downloaded via HTTP. Warning: enabling this option will allow downloading from insecure servers."
393+
"markdownDescription": "When adding a CodeQL database, automatically add the database's source folder as a workspace folder. Warning: enabling this option in a single-folder workspace will cause the workspace to reload as a [multi-root workspace](https://code.visualstudio.com/docs/editor/multi-root-workspaces). This may cause query history and database lists to be reset."
384394
}
385395
}
386396
},
@@ -1678,10 +1688,6 @@
16781688
"command": "codeQL.mockGitHubApiServer.unloadScenario",
16791689
"when": "config.codeQL.mockGitHubApiServer.enabled && codeQL.mockGitHubApiServer.scenarioLoaded"
16801690
},
1681-
{
1682-
"command": "codeQL.createQuery",
1683-
"when": "config.codeQL.codespacesTemplate || config.codeQL.canary && config.codeQL.queriesPanel"
1684-
},
16851691
{
16861692
"command": "codeQLTests.acceptOutputContextTestItem",
16871693
"when": "false"
@@ -1766,17 +1772,15 @@
17661772
"ql-container": [
17671773
{
17681774
"id": "codeQLLanguageSelection",
1769-
"name": "Language",
1770-
"when": "config.codeQL.canary && config.codeQL.showLanguageFilter"
1775+
"name": "Language"
17711776
},
17721777
{
17731778
"id": "codeQLDatabases",
17741779
"name": "Databases"
17751780
},
17761781
{
17771782
"id": "codeQLQueries",
1778-
"name": "Queries",
1779-
"when": "config.codeQL.canary && config.codeQL.queriesPanel"
1783+
"name": "Queries"
17801784
},
17811785
{
17821786
"id": "codeQLVariantAnalysisRepositories",

extensions/ql-vscode/src/config.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,12 +641,32 @@ export function isCodespacesTemplate() {
641641
return !!CODESPACES_TEMPLATE.getValue<boolean>();
642642
}
643643

644+
// Deprecated after v1.9.4. Can be removed in a few versions.
644645
const DATABASE_DOWNLOAD_SETTING = new Setting("databaseDownload", ROOT_SETTING);
646+
const DEPRECATED_ALLOW_HTTP_SETTING = new Setting(
647+
"allowHttp",
648+
DATABASE_DOWNLOAD_SETTING,
649+
);
650+
651+
const ADDING_DATABASES_SETTING = new Setting("addingDatabases", ROOT_SETTING);
645652

646-
const ALLOW_HTTP_SETTING = new Setting("allowHttp", DATABASE_DOWNLOAD_SETTING);
653+
const ALLOW_HTTP_SETTING = new Setting("allowHttp", ADDING_DATABASES_SETTING);
647654

648655
export function allowHttp(): boolean {
649-
return ALLOW_HTTP_SETTING.getValue<boolean>() || false;
656+
return (
657+
ALLOW_HTTP_SETTING.getValue<boolean>() ||
658+
DEPRECATED_ALLOW_HTTP_SETTING.getValue<boolean>() ||
659+
false
660+
);
661+
}
662+
663+
const ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING = new Setting(
664+
"addDatabaseSourceToWorkspace",
665+
ADDING_DATABASES_SETTING,
666+
);
667+
668+
export function addDatabaseSourceToWorkspace(): boolean {
669+
return ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING.getValue<boolean>() || false;
650670
}
651671

652672
/**
@@ -690,15 +710,6 @@ export async function setAutogenerateQlPacks(choice: AutogenerateQLPacks) {
690710
);
691711
}
692712

693-
/**
694-
* A flag indicating whether to show the queries panel in the QL view container.
695-
*/
696-
const QUERIES_PANEL = new Setting("queriesPanel", ROOT_SETTING);
697-
698-
export function showQueriesPanel(): boolean {
699-
return !!QUERIES_PANEL.getValue<boolean>();
700-
}
701-
702713
const MODEL_SETTING = new Setting("model", ROOT_SETTING);
703714
const FLOW_GENERATION = new Setting("flowGeneration", MODEL_SETTING);
704715
const LLM_GENERATION = new Setting("llmGeneration", MODEL_SETTING);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Contains models and consts for the data we want to store in the database config.
22
// Changes to these models should be done carefully and account for backwards compatibility of data.
33

4+
import { DatabaseOrigin } from "../local-databases/database-origin";
5+
46
export const DB_CONFIG_VERSION = 1;
57

68
export interface DbConfig {
@@ -88,6 +90,7 @@ export interface LocalDatabase {
8890
name: string;
8991
dateAdded: number;
9092
language: string;
93+
origin: DatabaseOrigin;
9194
storagePath: string;
9295
}
9396

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ import {
2929
} from "../common/github-url-identifier-helper";
3030
import { Credentials } from "../common/authentication";
3131
import { AppCommandManager } from "../common/commands";
32-
import { allowHttp } from "../config";
32+
import { addDatabaseSourceToWorkspace, allowHttp } from "../config";
3333
import { showAndLogInformationMessage } from "../common/logging";
3434
import { AppOctokit } from "../common/octokit";
3535
import { getLanguageDisplayName } from "../common/query-language";
36+
import { DatabaseOrigin } from "./local-databases/database-origin";
3637

3738
/**
3839
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
@@ -62,6 +63,10 @@ export async function promptImportInternetDatabase(
6263
databaseManager,
6364
storagePath,
6465
undefined,
66+
{
67+
type: "url",
68+
url: databaseUrl,
69+
},
6570
progress,
6671
cli,
6772
);
@@ -99,7 +104,7 @@ export async function promptImportGithubDatabase(
99104
cli?: CodeQLCliServer,
100105
language?: string,
101106
makeSelected = true,
102-
addSourceArchiveFolder = true,
107+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
103108
): Promise<DatabaseItem | undefined> {
104109
const githubRepo = await askForGitHubRepo(progress);
105110
if (!githubRepo) {
@@ -178,7 +183,7 @@ export async function downloadGitHubDatabase(
178183
cli?: CodeQLCliServer,
179184
language?: string,
180185
makeSelected = true,
181-
addSourceArchiveFolder = true,
186+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
182187
): Promise<DatabaseItem | undefined> {
183188
const nwo = getNwoFromGitHubUrl(githubRepo) || githubRepo;
184189
if (!isValidGitHubNwo(nwo)) {
@@ -199,7 +204,8 @@ export async function downloadGitHubDatabase(
199204
return;
200205
}
201206

202-
const { databaseUrl, name, owner } = result;
207+
const { databaseUrl, name, owner, databaseId, databaseCreatedAt, commitOid } =
208+
result;
203209

204210
/**
205211
* The 'token' property of the token object returned by `octokit.auth()`.
@@ -221,6 +227,13 @@ export async function downloadGitHubDatabase(
221227
databaseManager,
222228
storagePath,
223229
`${owner}/${name}`,
230+
{
231+
type: "github",
232+
repository: nwo,
233+
databaseId,
234+
databaseCreatedAt,
235+
commitOid,
236+
},
224237
progress,
225238
cli,
226239
makeSelected,
@@ -250,6 +263,10 @@ export async function importArchiveDatabase(
250263
databaseManager,
251264
storagePath,
252265
undefined,
266+
{
267+
type: "archive",
268+
path: databaseUrl,
269+
},
253270
progress,
254271
cli,
255272
);
@@ -282,6 +299,7 @@ export async function importArchiveDatabase(
282299
* @param databaseManager the DatabaseManager
283300
* @param storagePath where to store the unzipped database.
284301
* @param nameOverride a name for the database that overrides the default
302+
* @param origin the origin of the database
285303
* @param progress callback to send progress messages to
286304
* @param makeSelected make the new database selected in the databases panel (default: true)
287305
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
@@ -292,10 +310,11 @@ async function databaseArchiveFetcher(
292310
databaseManager: DatabaseManager,
293311
storagePath: string,
294312
nameOverride: string | undefined,
313+
origin: DatabaseOrigin,
295314
progress: ProgressCallback,
296315
cli?: CodeQLCliServer,
297316
makeSelected = true,
298-
addSourceArchiveFolder = true,
317+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
299318
): Promise<DatabaseItem> {
300319
progress({
301320
message: "Getting database",
@@ -336,6 +355,7 @@ async function databaseArchiveFetcher(
336355

337356
const item = await databaseManager.openDatabase(
338357
Uri.file(dbPath),
358+
origin,
339359
makeSelected,
340360
nameOverride,
341361
{
@@ -476,7 +496,7 @@ async function checkForFailingResponse(
476496
return response;
477497
}
478498

479-
// An error downloading the database. Attempt to extract the resaon behind it.
499+
// An error downloading the database. Attempt to extract the reason behind it.
480500
const text = await response.text();
481501
let msg: string;
482502
try {
@@ -533,16 +553,19 @@ export async function convertGithubNwoToDatabaseUrl(
533553
databaseUrl: string;
534554
owner: string;
535555
name: string;
556+
databaseId: number;
557+
databaseCreatedAt: string;
558+
commitOid: string | null;
536559
}
537560
| undefined
538561
> {
539562
try {
540563
const [owner, repo] = nwo.split("/");
541564

542-
const response = await octokit.request(
543-
"GET /repos/:owner/:repo/code-scanning/codeql/databases",
544-
{ owner, repo },
545-
);
565+
const response = await octokit.rest.codeScanning.listCodeqlDatabases({
566+
owner,
567+
repo,
568+
});
546569

547570
const languages = response.data.map((db: any) => db.language);
548571

@@ -553,10 +576,20 @@ export async function convertGithubNwoToDatabaseUrl(
553576
}
554577
}
555578

579+
const databaseForLanguage = response.data.find(
580+
(db: any) => db.language === language,
581+
);
582+
if (!databaseForLanguage) {
583+
throw new Error(`No database found for language '${language}'`);
584+
}
585+
556586
return {
557-
databaseUrl: `https://api.github.com/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}`,
587+
databaseUrl: databaseForLanguage.url,
558588
owner,
559589
name: repo,
590+
databaseId: databaseForLanguage.id,
591+
databaseCreatedAt: databaseForLanguage.created_at,
592+
commitOid: databaseForLanguage.commit_oid ?? null,
560593
};
561594
} catch (e) {
562595
void extLogger.log(`Error: ${getErrorMessage(e)}`);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// This file contains models that are used to represent the databases.
22

3+
import { DatabaseOrigin } from "./local-databases/database-origin";
4+
35
export enum DbItemKind {
46
RootLocal = "RootLocal",
57
LocalList = "LocalList",
@@ -38,6 +40,7 @@ export interface LocalDatabaseDbItem {
3840
databaseName: string;
3941
dateAdded: number;
4042
language: string;
43+
origin: DatabaseOrigin;
4144
storagePath: string;
4245
parentListName?: string;
4346
}

extensions/ql-vscode/src/databases/db-tree-creator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ function createLocalDb(
197197
databaseName: db.name,
198198
dateAdded: db.dateAdded,
199199
language: db.language,
200+
origin: db.origin,
200201
storagePath: db.storagePath,
201202
selected: !!selected,
202203
parentListName: listName,

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ export class DatabaseUI extends DisposableObject {
367367

368368
await this.databaseManager.openDatabase(
369369
uri,
370+
{
371+
type: "folder",
372+
},
370373
makeSelected,
371374
nameOverride,
372375
{
@@ -704,7 +707,9 @@ export class DatabaseUI extends DisposableObject {
704707
this.queryServer?.cliServer,
705708
);
706709
} else {
707-
await this.databaseManager.openDatabase(uri);
710+
await this.databaseManager.openDatabase(uri, {
711+
type: "folder",
712+
});
708713
}
709714
} catch (e) {
710715
// rethrow and let this be handled by default error handling.
@@ -819,7 +824,9 @@ export class DatabaseUI extends DisposableObject {
819824
if (byFolder) {
820825
const fixedUri = await this.fixDbUri(uri);
821826
// we are selecting a database folder
822-
return await this.databaseManager.openDatabase(fixedUri);
827+
return await this.databaseManager.openDatabase(fixedUri, {
828+
type: "folder",
829+
});
823830
} else {
824831
// we are selecting a database archive. Must unzip into a workspace-controlled area
825832
// before importing.

0 commit comments

Comments
 (0)