Update prompts to use GHEC-DR URL

This commit is contained in:
Koen Vlaswinkel
2024-04-24 14:30:59 +02:00
parent c2ddd680c1
commit 086d8e2104
4 changed files with 42 additions and 15 deletions

View File

@@ -155,8 +155,8 @@ export class DatabaseFetcher {
const instanceUrl = getGitHubInstanceUrl();
const options: InputBoxOptions = {
title: `Enter a GitHub repository URL or "name with owner" (e.g. https://github.com/github/codeql or github/codeql)`,
placeHolder: "https://github.com/<owner>/<repo> or <owner>/<repo>",
title: `Enter a GitHub repository URL or "name with owner" (e.g. ${new URL("/github/codeql", instanceUrl).toString()} or github/codeql)`,
placeHolder: `${new URL("/", instanceUrl).toString()}<owner>/<repo> or <owner>/<repo>`,
ignoreFocusOut: true,
};

View File

@@ -147,10 +147,12 @@ export class DbPanel extends DisposableObject {
}
private async addNewRemoteRepo(parentList?: string): Promise<void> {
const instanceUrl = getGitHubInstanceUrl();
const repoName = await window.showInputBox({
title: "Add a repository",
prompt: "Insert a GitHub repository URL or name with owner",
placeHolder: "<owner>/<repo> or https://github.com/<owner>/<repo>",
placeHolder: `<owner>/<repo> or ${new URL("/", instanceUrl).toString()}<owner>/<repo>`,
});
if (!repoName) {
return;
@@ -178,10 +180,12 @@ export class DbPanel extends DisposableObject {
}
private async addNewRemoteOwner(): Promise<void> {
const instanceUrl = getGitHubInstanceUrl();
const ownerName = await window.showInputBox({
title: "Add all repositories of a GitHub org or owner",
prompt: "Insert a GitHub organization or owner name",
placeHolder: "<owner> or https://github.com/<owner>",
placeHolder: `<owner> or ${new URL("/", instanceUrl).toString()}<owner>`,
});
if (!ownerName) {
@@ -414,7 +418,7 @@ export class DbPanel extends DisposableObject {
if (treeViewItem.dbItem === undefined) {
throw new Error("Unable to open on GitHub. Please select a valid item.");
}
const githubUrl = getGitHubUrl(treeViewItem.dbItem);
const githubUrl = getGitHubUrl(treeViewItem.dbItem, getGitHubInstanceUrl());
if (!githubUrl) {
throw new Error(
"Unable to open on GitHub. Please select a variant analysis repository or owner.",

View File

@@ -62,12 +62,15 @@ function canImportCodeSearch(dbItem: DbItem): boolean {
return DbItemKind.RemoteUserDefinedList === dbItem.kind;
}
export function getGitHubUrl(dbItem: DbItem): string | undefined {
export function getGitHubUrl(
dbItem: DbItem,
githubUrl: URL,
): string | undefined {
switch (dbItem.kind) {
case DbItemKind.RemoteOwner:
return `https://github.com/${dbItem.ownerName}`;
return new URL(`/${dbItem.ownerName}`, githubUrl).toString();
case DbItemKind.RemoteRepo:
return `https://github.com/${dbItem.repoFullName}`;
return new URL(`/${dbItem.repoFullName}`, githubUrl).toString();
default:
return undefined;
}

View File

@@ -92,32 +92,52 @@ describe("getDbItemActions", () => {
});
describe("getGitHubUrl", () => {
it("should return the correct url for a remote owner", () => {
const githubUrl = new URL("https://github.com");
it("should return the correct url for a remote owner with github.com", () => {
const dbItem = createRemoteOwnerDbItem();
const actualUrl = getGitHubUrl(dbItem);
const actualUrl = getGitHubUrl(dbItem, githubUrl);
const expectedUrl = `https://github.com/${dbItem.ownerName}`;
expect(actualUrl).toEqual(expectedUrl);
});
it("should return the correct url for a remote repo", () => {
it("should return the correct url for a remote owner with GHEC-DR", () => {
const dbItem = createRemoteOwnerDbItem();
const actualUrl = getGitHubUrl(dbItem, new URL("https://tenant.ghe.com"));
const expectedUrl = `https://tenant.ghe.com/${dbItem.ownerName}`;
expect(actualUrl).toEqual(expectedUrl);
});
it("should return the correct url for a remote repo with github.com", () => {
const dbItem = createRemoteRepoDbItem();
const actualUrl = getGitHubUrl(dbItem);
const actualUrl = getGitHubUrl(dbItem, githubUrl);
const expectedUrl = `https://github.com/${dbItem.repoFullName}`;
expect(actualUrl).toEqual(expectedUrl);
});
it("should return the correct url for a remote repo with GHEC-DR", () => {
const dbItem = createRemoteRepoDbItem();
const actualUrl = getGitHubUrl(dbItem, new URL("https://tenant.ghe.com"));
const expectedUrl = `https://tenant.ghe.com/${dbItem.repoFullName}`;
expect(actualUrl).toEqual(expectedUrl);
});
it("should return undefined for other remote db items", () => {
const dbItem0 = createRootRemoteDbItem();
const dbItem1 = createRemoteSystemDefinedListDbItem();
const dbItem2 = createRemoteUserDefinedListDbItem();
const actualUrl0 = getGitHubUrl(dbItem0);
const actualUrl1 = getGitHubUrl(dbItem1);
const actualUrl2 = getGitHubUrl(dbItem2);
const actualUrl0 = getGitHubUrl(dbItem0, githubUrl);
const actualUrl1 = getGitHubUrl(dbItem1, githubUrl);
const actualUrl2 = getGitHubUrl(dbItem2, githubUrl);
expect(actualUrl0).toBeUndefined();
expect(actualUrl1).toBeUndefined();