Merge pull request #1900 from github/nora/add-repo-to-list
Add new repositories to a highlighted user defined list
This commit is contained in:
@@ -94,7 +94,10 @@ export class DbConfigStore extends DisposableObject {
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
public async addRemoteRepo(repoNwo: string): Promise<void> {
|
||||
public async addRemoteRepo(
|
||||
repoNwo: string,
|
||||
parentList?: string,
|
||||
): Promise<void> {
|
||||
if (!this.config) {
|
||||
throw Error("Cannot add remote repo if config is not loaded");
|
||||
}
|
||||
@@ -110,8 +113,18 @@ export class DbConfigStore extends DisposableObject {
|
||||
}
|
||||
|
||||
const config: DbConfig = cloneDbConfig(this.config);
|
||||
config.databases.remote.repositories.push(repoNwo);
|
||||
|
||||
if (parentList) {
|
||||
const parent = config.databases.remote.repositoryLists.find(
|
||||
(list) => list.name === parentList,
|
||||
);
|
||||
if (!parent) {
|
||||
throw Error(`Cannot find parent list '${parentList}'`);
|
||||
} else {
|
||||
parent.repositories.push(repoNwo);
|
||||
}
|
||||
} else {
|
||||
config.databases.remote.repositories.push(repoNwo);
|
||||
}
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,11 @@ export class DbManager {
|
||||
await this.dbConfigStore.updateExpandedState(newExpandedItems);
|
||||
}
|
||||
|
||||
public async addNewRemoteRepo(nwo: string): Promise<void> {
|
||||
await this.dbConfigStore.addRemoteRepo(nwo);
|
||||
public async addNewRemoteRepo(
|
||||
nwo: string,
|
||||
parentList?: string,
|
||||
): Promise<void> {
|
||||
await this.dbConfigStore.addRemoteRepo(nwo, parentList);
|
||||
}
|
||||
|
||||
public async addNewRemoteOwner(owner: string): Promise<void> {
|
||||
|
||||
@@ -82,40 +82,54 @@ export class DbPanel extends DisposableObject {
|
||||
}
|
||||
|
||||
private async addNewRemoteDatabase(): Promise<void> {
|
||||
const quickPickItems = [
|
||||
{
|
||||
label: "$(repo) From a GitHub repository",
|
||||
detail: "Add a remote repository from GitHub",
|
||||
alwaysShow: true,
|
||||
kind: "repo",
|
||||
},
|
||||
{
|
||||
label: "$(organization) All repositories of a GitHub org or owner",
|
||||
detail:
|
||||
"Add a remote list of repositories from a GitHub organization/owner",
|
||||
alwaysShow: true,
|
||||
kind: "owner",
|
||||
},
|
||||
];
|
||||
const databaseKind =
|
||||
await window.showQuickPick<RemoteDatabaseQuickPickItem>(quickPickItems, {
|
||||
title: "Add a remote repository",
|
||||
placeHolder: "Select an option",
|
||||
ignoreFocusOut: true,
|
||||
});
|
||||
if (!databaseKind) {
|
||||
// We don't need to display a warning pop-up in this case, since the user just escaped out of the operation.
|
||||
// We set 'true' to make this a silent exception.
|
||||
throw new UserCancellationException("No repository selected", true);
|
||||
}
|
||||
if (databaseKind.kind === "repo") {
|
||||
await this.addNewRemoteRepo();
|
||||
} else if (databaseKind.kind === "owner") {
|
||||
await this.addNewRemoteOwner();
|
||||
const highlightedItem = await this.getHighlightedDbItem();
|
||||
|
||||
if (highlightedItem?.kind === DbItemKind.RemoteUserDefinedList) {
|
||||
await this.addNewRemoteRepo(highlightedItem.listName);
|
||||
} else if (
|
||||
highlightedItem?.kind === DbItemKind.RemoteRepo &&
|
||||
highlightedItem.parentListName
|
||||
) {
|
||||
await this.addNewRemoteRepo(highlightedItem.parentListName);
|
||||
} else {
|
||||
const quickPickItems = [
|
||||
{
|
||||
label: "$(repo) From a GitHub repository",
|
||||
detail: "Add a remote repository from GitHub",
|
||||
alwaysShow: true,
|
||||
kind: "repo",
|
||||
},
|
||||
{
|
||||
label: "$(organization) All repositories of a GitHub org or owner",
|
||||
detail:
|
||||
"Add a remote list of repositories from a GitHub organization/owner",
|
||||
alwaysShow: true,
|
||||
kind: "owner",
|
||||
},
|
||||
];
|
||||
const databaseKind =
|
||||
await window.showQuickPick<RemoteDatabaseQuickPickItem>(
|
||||
quickPickItems,
|
||||
{
|
||||
title: "Add a remote repository",
|
||||
placeHolder: "Select an option",
|
||||
ignoreFocusOut: true,
|
||||
},
|
||||
);
|
||||
if (!databaseKind) {
|
||||
// We don't need to display a warning pop-up in this case, since the user just escaped out of the operation.
|
||||
// We set 'true' to make this a silent exception.
|
||||
throw new UserCancellationException("No repository selected", true);
|
||||
}
|
||||
if (databaseKind.kind === "repo") {
|
||||
await this.addNewRemoteRepo();
|
||||
} else if (databaseKind.kind === "owner") {
|
||||
await this.addNewRemoteOwner();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async addNewRemoteRepo(): Promise<void> {
|
||||
private async addNewRemoteRepo(parentList?: string): Promise<void> {
|
||||
const repoName = await window.showInputBox({
|
||||
title: "Add a remote repository",
|
||||
prompt: "Insert a GitHub repository URL or name with owner",
|
||||
@@ -136,7 +150,7 @@ export class DbPanel extends DisposableObject {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.dbManager.addNewRemoteRepo(nwo);
|
||||
await this.dbManager.addNewRemoteRepo(nwo, parentList);
|
||||
}
|
||||
|
||||
private async addNewRemoteOwner(): Promise<void> {
|
||||
|
||||
@@ -447,6 +447,91 @@ describe("db panel", () => {
|
||||
}
|
||||
});
|
||||
|
||||
describe("addNewRemoteRepo", () => {
|
||||
it("should add a new remote repo", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
remoteRepos: ["owner1/repo1"],
|
||||
});
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
|
||||
const dbTreeItems = await dbTreeDataProvider.getChildren();
|
||||
|
||||
expect(dbTreeItems).toBeTruthy();
|
||||
const items = dbTreeItems!;
|
||||
|
||||
const remoteRootNode = items[0];
|
||||
const remoteRepos = remoteRootNode.children.filter(
|
||||
(c) => c.dbItem?.kind === DbItemKind.RemoteRepo,
|
||||
);
|
||||
const repo1 = remoteRootNode.children.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteRepo &&
|
||||
c.dbItem?.repoFullName === "owner1/repo1",
|
||||
);
|
||||
|
||||
expect(remoteRepos.length).toBe(1);
|
||||
expect(remoteRepos[0]).toBe(repo1);
|
||||
|
||||
await dbManager.addNewRemoteRepo("owner2/repo2");
|
||||
|
||||
// Read the workspace databases JSON file directly to check that the new repo has been added.
|
||||
// We can't use the dbConfigStore's `read` function here because it depends on the file watcher
|
||||
// picking up changes, and we don't control the timing of that.
|
||||
const dbConfigFileContents = await readJSON(dbConfigFilePath);
|
||||
expect(dbConfigFileContents.databases.remote.repositories.length).toBe(2);
|
||||
expect(dbConfigFileContents.databases.remote.repositories[1]).toEqual(
|
||||
"owner2/repo2",
|
||||
);
|
||||
});
|
||||
|
||||
it("should add a new remote repo to a user defined list", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "my-list-1",
|
||||
repositories: ["owner1/repo1"],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
|
||||
const dbTreeItems = await dbTreeDataProvider.getChildren();
|
||||
|
||||
expect(dbTreeItems).toBeTruthy();
|
||||
const items = dbTreeItems!;
|
||||
|
||||
const remoteRootNode = items[0];
|
||||
const remoteUserDefinedLists = remoteRootNode.children.filter(
|
||||
(c) => c.dbItem?.kind === DbItemKind.RemoteUserDefinedList,
|
||||
);
|
||||
const list1 = remoteRootNode.children.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteUserDefinedList &&
|
||||
c.dbItem?.listName === "my-list-1",
|
||||
);
|
||||
|
||||
expect(remoteUserDefinedLists.length).toBe(1);
|
||||
expect(remoteUserDefinedLists[0]).toBe(list1);
|
||||
|
||||
await dbManager.addNewRemoteRepo("owner2/repo2", "my-list-1");
|
||||
|
||||
// Read the workspace databases JSON file directly to check that the new repo has been added.
|
||||
// We can't use the dbConfigStore's `read` function here because it depends on the file watcher
|
||||
// picking up changes, and we don't control the timing of that.
|
||||
const dbConfigFileContents = await readJSON(dbConfigFilePath);
|
||||
expect(dbConfigFileContents.databases.remote.repositoryLists.length).toBe(
|
||||
1,
|
||||
);
|
||||
|
||||
expect(dbConfigFileContents.databases.remote.repositoryLists[0]).toEqual({
|
||||
name: "my-list-1",
|
||||
repositories: ["owner1/repo1", "owner2/repo2"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("addNewList", () => {
|
||||
it("should add a new remote list", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
|
||||
Reference in New Issue
Block a user