Skip to content

Commit 72412c9

Browse files
committed
Allow usage of github.com
1 parent 9e54e5e commit 72412c9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

extensions/ql-vscode/src/common/github-url-identifier-helper.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ function getNwoOrOwnerFromGitHubUrl(
5050
kind: "owner" | "nwo",
5151
): string | undefined {
5252
try {
53-
const uri = new URL(githubUrl);
54-
if (uri.hostname !== "github.com" && uri.hostname !== "www.github.com") {
55-
return;
53+
let paths: string[];
54+
if (githubUrl.split("/")[0] === "github.com") {
55+
paths = githubUrl.split("/").slice(1);
56+
} else {
57+
const uri = new URL(githubUrl);
58+
if (uri.hostname !== "github.com" && uri.hostname !== "www.github.com") {
59+
return;
60+
}
61+
paths = uri.pathname.split("/").filter((segment: string) => segment);
5662
}
57-
const paths = uri.pathname.split("/").filter((segment: string) => segment);
5863
const owner = `${paths[0]}`;
5964
if (kind === "owner") {
6065
return owner ? owner : undefined;

extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("github url identifier helper", () => {
3333
});
3434

3535
it("should handle valid urls", () => {
36+
expect(getNwoFromGitHubUrl("github.com/foo/bar")).toBe("foo/bar");
3637
expect(getNwoFromGitHubUrl("https://github.com/foo/bar")).toBe("foo/bar");
3738
expect(getNwoFromGitHubUrl("http://github.com/foo/bar")).toBe("foo/bar");
3839
expect(getNwoFromGitHubUrl("https://www.github.com/foo/bar")).toBe(
@@ -64,6 +65,7 @@ describe("github url identifier helper", () => {
6465
getOwnerFromGitHubUrl("https://github.com/foo/bar/sub/pages"),
6566
).toBe("foo");
6667
expect(getOwnerFromGitHubUrl("https://www.github.com/foo")).toBe("foo");
68+
expect(getOwnerFromGitHubUrl("github.com/foo")).toBe("foo");
6769
});
6870
});
6971
});

0 commit comments

Comments
 (0)