Skip to content

Commit 086d8e2

Browse files
committed
Update prompts to use GHEC-DR URL
1 parent c2ddd68 commit 086d8e2

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ export class DatabaseFetcher {
155155
const instanceUrl = getGitHubInstanceUrl();
156156

157157
const options: InputBoxOptions = {
158-
title: `Enter a GitHub repository URL or "name with owner" (e.g. https://github.com/github/codeql or github/codeql)`,
159-
placeHolder: "https://github.com/<owner>/<repo> or <owner>/<repo>",
158+
title: `Enter a GitHub repository URL or "name with owner" (e.g. ${new URL("/github/codeql", instanceUrl).toString()} or github/codeql)`,
159+
placeHolder: `${new URL("/", instanceUrl).toString()}<owner>/<repo> or <owner>/<repo>`,
160160
ignoreFocusOut: true,
161161
};
162162

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ export class DbPanel extends DisposableObject {
147147
}
148148

149149
private async addNewRemoteRepo(parentList?: string): Promise<void> {
150+
const instanceUrl = getGitHubInstanceUrl();
151+
150152
const repoName = await window.showInputBox({
151153
title: "Add a repository",
152154
prompt: "Insert a GitHub repository URL or name with owner",
153-
placeHolder: "<owner>/<repo> or https://github.com/<owner>/<repo>",
155+
placeHolder: `<owner>/<repo> or ${new URL("/", instanceUrl).toString()}<owner>/<repo>`,
154156
});
155157
if (!repoName) {
156158
return;
@@ -178,10 +180,12 @@ export class DbPanel extends DisposableObject {
178180
}
179181

180182
private async addNewRemoteOwner(): Promise<void> {
183+
const instanceUrl = getGitHubInstanceUrl();
184+
181185
const ownerName = await window.showInputBox({
182186
title: "Add all repositories of a GitHub org or owner",
183187
prompt: "Insert a GitHub organization or owner name",
184-
placeHolder: "<owner> or https://github.com/<owner>",
188+
placeHolder: `<owner> or ${new URL("/", instanceUrl).toString()}<owner>`,
185189
});
186190

187191
if (!ownerName) {
@@ -414,7 +418,7 @@ export class DbPanel extends DisposableObject {
414418
if (treeViewItem.dbItem === undefined) {
415419
throw new Error("Unable to open on GitHub. Please select a valid item.");
416420
}
417-
const githubUrl = getGitHubUrl(treeViewItem.dbItem);
421+
const githubUrl = getGitHubUrl(treeViewItem.dbItem, getGitHubInstanceUrl());
418422
if (!githubUrl) {
419423
throw new Error(
420424
"Unable to open on GitHub. Please select a variant analysis repository or owner.",

extensions/ql-vscode/src/databases/ui/db-tree-view-item-action.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ function canImportCodeSearch(dbItem: DbItem): boolean {
6262
return DbItemKind.RemoteUserDefinedList === dbItem.kind;
6363
}
6464

65-
export function getGitHubUrl(dbItem: DbItem): string | undefined {
65+
export function getGitHubUrl(
66+
dbItem: DbItem,
67+
githubUrl: URL,
68+
): string | undefined {
6669
switch (dbItem.kind) {
6770
case DbItemKind.RemoteOwner:
68-
return `https://github.com/${dbItem.ownerName}`;
71+
return new URL(`/${dbItem.ownerName}`, githubUrl).toString();
6972
case DbItemKind.RemoteRepo:
70-
return `https://github.com/${dbItem.repoFullName}`;
73+
return new URL(`/${dbItem.repoFullName}`, githubUrl).toString();
7174
default:
7275
return undefined;
7376
}

extensions/ql-vscode/test/unit-tests/databases/ui/db-tree-view-item-action.test.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,52 @@ describe("getDbItemActions", () => {
9292
});
9393

9494
describe("getGitHubUrl", () => {
95-
it("should return the correct url for a remote owner", () => {
95+
const githubUrl = new URL("https://github.com");
96+
97+
it("should return the correct url for a remote owner with github.com", () => {
9698
const dbItem = createRemoteOwnerDbItem();
9799

98-
const actualUrl = getGitHubUrl(dbItem);
100+
const actualUrl = getGitHubUrl(dbItem, githubUrl);
99101
const expectedUrl = `https://github.com/${dbItem.ownerName}`;
100102

101103
expect(actualUrl).toEqual(expectedUrl);
102104
});
103105

104-
it("should return the correct url for a remote repo", () => {
106+
it("should return the correct url for a remote owner with GHEC-DR", () => {
107+
const dbItem = createRemoteOwnerDbItem();
108+
109+
const actualUrl = getGitHubUrl(dbItem, new URL("https://tenant.ghe.com"));
110+
const expectedUrl = `https://tenant.ghe.com/${dbItem.ownerName}`;
111+
112+
expect(actualUrl).toEqual(expectedUrl);
113+
});
114+
115+
it("should return the correct url for a remote repo with github.com", () => {
105116
const dbItem = createRemoteRepoDbItem();
106117

107-
const actualUrl = getGitHubUrl(dbItem);
118+
const actualUrl = getGitHubUrl(dbItem, githubUrl);
108119
const expectedUrl = `https://github.com/${dbItem.repoFullName}`;
109120

110121
expect(actualUrl).toEqual(expectedUrl);
111122
});
112123

124+
it("should return the correct url for a remote repo with GHEC-DR", () => {
125+
const dbItem = createRemoteRepoDbItem();
126+
127+
const actualUrl = getGitHubUrl(dbItem, new URL("https://tenant.ghe.com"));
128+
const expectedUrl = `https://tenant.ghe.com/${dbItem.repoFullName}`;
129+
130+
expect(actualUrl).toEqual(expectedUrl);
131+
});
132+
113133
it("should return undefined for other remote db items", () => {
114134
const dbItem0 = createRootRemoteDbItem();
115135
const dbItem1 = createRemoteSystemDefinedListDbItem();
116136
const dbItem2 = createRemoteUserDefinedListDbItem();
117137

118-
const actualUrl0 = getGitHubUrl(dbItem0);
119-
const actualUrl1 = getGitHubUrl(dbItem1);
120-
const actualUrl2 = getGitHubUrl(dbItem2);
138+
const actualUrl0 = getGitHubUrl(dbItem0, githubUrl);
139+
const actualUrl1 = getGitHubUrl(dbItem1, githubUrl);
140+
const actualUrl2 = getGitHubUrl(dbItem2, githubUrl);
121141

122142
expect(actualUrl0).toBeUndefined();
123143
expect(actualUrl1).toBeUndefined();

0 commit comments

Comments
 (0)