Merge pull request #2027 from github/elena/select-db-in-codespace

Introduce command to set default Code Tour database
This commit is contained in:
Elena Tanasoiu 2023-02-02 12:05:27 +00:00 коммит произвёл GitHub
Родитель 302091f2c5 99d794c2a8
Коммит c493425046
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 44 добавлений и 0 удалений

Просмотреть файл

@ -12,6 +12,7 @@ import {
CancellationToken,
ThemeIcon,
ThemeColor,
workspace,
} from "vscode";
import { pathExists, stat, readdir, remove } from "fs-extra";
@ -218,6 +219,15 @@ export class DatabaseUI extends DisposableObject {
},
),
);
this.push(
commandRunnerWithProgress(
"codeQL.setDefaultTourDatabase",
this.handleSetDefaultTourDatabase,
{
title: "Set Default Database for Codespace CodeQL Tour",
},
),
);
this.push(
commandRunnerWithProgress(
"codeQL.upgradeCurrentDatabase",
@ -348,6 +358,40 @@ export class DatabaseUI extends DisposableObject {
}
};
private handleSetDefaultTourDatabase = async (
progress: ProgressCallback,
token: CancellationToken,
): Promise<void> => {
try {
if (!workspace.workspaceFolders?.length) {
throw new Error("No workspace folder is open.");
} else {
// This specifically refers to the database folder in
// https://github.com/github/codespaces-codeql
const uri = Uri.parse(
`${workspace.workspaceFolders[0].uri}/codeql-tutorial-database`,
);
let databaseItem = this.databaseManager.findDatabaseItem(uri);
if (databaseItem === undefined) {
databaseItem = await this.databaseManager.openDatabase(
progress,
token,
uri,
);
}
await this.databaseManager.setCurrentDatabaseItem(databaseItem);
}
} catch (e) {
// rethrow and let this be handled by default error handling.
throw new Error(
`Could not set the database for the Code Tour. Please make sure you are using the default workspace in your codespace: ${getErrorMessage(
e,
)}`,
);
}
};
handleRemoveOrphanedDatabases = async (): Promise<void> => {
void extLogger.log("Removing orphaned databases from workspace storage.");
let dbDirs = undefined;