From 9e54e5eced6bcc4204f12a6bdd14f85dad3222fb Mon Sep 17 00:00:00 2001 From: Nora Date: Tue, 31 Jan 2023 14:18:12 +0000 Subject: [PATCH 1/3] Drop protocol check --- .../ql-vscode/src/common/github-url-identifier-helper.ts | 3 --- .../unit-tests/common/github-url-identifier-helper.test.ts | 6 ++---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/extensions/ql-vscode/src/common/github-url-identifier-helper.ts b/extensions/ql-vscode/src/common/github-url-identifier-helper.ts index 2499ef663fc..f8ae60c9d64 100644 --- a/extensions/ql-vscode/src/common/github-url-identifier-helper.ts +++ b/extensions/ql-vscode/src/common/github-url-identifier-helper.ts @@ -51,9 +51,6 @@ function getNwoOrOwnerFromGitHubUrl( ): string | undefined { try { const uri = new URL(githubUrl); - if (uri.protocol !== "https:") { - return; - } if (uri.hostname !== "github.com" && uri.hostname !== "www.github.com") { return; } diff --git a/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts b/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts index 16d24af8df8..51044f59a30 100644 --- a/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts +++ b/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts @@ -24,7 +24,6 @@ describe("github url identifier helper", () => { describe("getNwoFromGitHubUrl method", () => { it("should handle invalid urls", () => { expect(getNwoFromGitHubUrl("")).toBe(undefined); - expect(getNwoFromGitHubUrl("http://github.com/foo/bar")).toBe(undefined); expect(getNwoFromGitHubUrl("https://ww.github.com/foo/bar")).toBe( undefined, ); @@ -35,6 +34,7 @@ describe("github url identifier helper", () => { it("should handle valid urls", () => { expect(getNwoFromGitHubUrl("https://github.com/foo/bar")).toBe("foo/bar"); + expect(getNwoFromGitHubUrl("http://github.com/foo/bar")).toBe("foo/bar"); expect(getNwoFromGitHubUrl("https://www.github.com/foo/bar")).toBe( "foo/bar", ); @@ -47,9 +47,6 @@ describe("github url identifier helper", () => { describe("getOwnerFromGitHubUrl method", () => { it("should handle invalid urls", () => { expect(getOwnerFromGitHubUrl("")).toBe(undefined); - expect(getOwnerFromGitHubUrl("http://github.com/foo/bar")).toBe( - undefined, - ); expect(getOwnerFromGitHubUrl("https://ww.github.com/foo/bar")).toBe( undefined, ); @@ -58,6 +55,7 @@ describe("github url identifier helper", () => { }); it("should handle valid urls", () => { + expect(getOwnerFromGitHubUrl("http://github.com/foo/bar")).toBe("foo"); expect(getOwnerFromGitHubUrl("https://github.com/foo/bar")).toBe("foo"); expect(getOwnerFromGitHubUrl("https://www.github.com/foo/bar")).toBe( "foo", From 72412c92c8cf61c502c084853257e257a59a40a9 Mon Sep 17 00:00:00 2001 From: Nora Date: Wed, 1 Feb 2023 11:32:57 +0000 Subject: [PATCH 2/3] Allow usage of github.com --- .../src/common/github-url-identifier-helper.ts | 13 +++++++++---- .../common/github-url-identifier-helper.test.ts | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/extensions/ql-vscode/src/common/github-url-identifier-helper.ts b/extensions/ql-vscode/src/common/github-url-identifier-helper.ts index f8ae60c9d64..e2c40e603c3 100644 --- a/extensions/ql-vscode/src/common/github-url-identifier-helper.ts +++ b/extensions/ql-vscode/src/common/github-url-identifier-helper.ts @@ -50,11 +50,16 @@ function getNwoOrOwnerFromGitHubUrl( kind: "owner" | "nwo", ): string | undefined { try { - const uri = new URL(githubUrl); - if (uri.hostname !== "github.com" && uri.hostname !== "www.github.com") { - return; + let paths: string[]; + if (githubUrl.split("/")[0] === "github.com") { + paths = githubUrl.split("/").slice(1); + } else { + const uri = new URL(githubUrl); + if (uri.hostname !== "github.com" && uri.hostname !== "www.github.com") { + return; + } + paths = uri.pathname.split("/").filter((segment: string) => segment); } - const paths = uri.pathname.split("/").filter((segment: string) => segment); const owner = `${paths[0]}`; if (kind === "owner") { return owner ? owner : undefined; diff --git a/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts b/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts index 51044f59a30..c55c32108f4 100644 --- a/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts +++ b/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts @@ -33,6 +33,7 @@ describe("github url identifier helper", () => { }); it("should handle valid urls", () => { + expect(getNwoFromGitHubUrl("github.com/foo/bar")).toBe("foo/bar"); expect(getNwoFromGitHubUrl("https://github.com/foo/bar")).toBe("foo/bar"); expect(getNwoFromGitHubUrl("http://github.com/foo/bar")).toBe("foo/bar"); expect(getNwoFromGitHubUrl("https://www.github.com/foo/bar")).toBe( @@ -64,6 +65,7 @@ describe("github url identifier helper", () => { getOwnerFromGitHubUrl("https://github.com/foo/bar/sub/pages"), ).toBe("foo"); expect(getOwnerFromGitHubUrl("https://www.github.com/foo")).toBe("foo"); + expect(getOwnerFromGitHubUrl("github.com/foo")).toBe("foo"); }); }); }); From 4c547785150c5e825faf31b4c1e44f3edfe93937 Mon Sep 17 00:00:00 2001 From: Nora Date: Wed, 1 Feb 2023 11:34:49 +0000 Subject: [PATCH 3/3] Allow usage of www.github.com --- .../ql-vscode/src/common/github-url-identifier-helper.ts | 6 +++++- .../unit-tests/common/github-url-identifier-helper.test.ts | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/ql-vscode/src/common/github-url-identifier-helper.ts b/extensions/ql-vscode/src/common/github-url-identifier-helper.ts index e2c40e603c3..748ef2fad90 100644 --- a/extensions/ql-vscode/src/common/github-url-identifier-helper.ts +++ b/extensions/ql-vscode/src/common/github-url-identifier-helper.ts @@ -51,7 +51,11 @@ function getNwoOrOwnerFromGitHubUrl( ): string | undefined { try { let paths: string[]; - if (githubUrl.split("/")[0] === "github.com") { + const urlElements = githubUrl.split("/"); + if ( + urlElements[0] === "github.com" || + urlElements[0] === "www.github.com" + ) { paths = githubUrl.split("/").slice(1); } else { const uri = new URL(githubUrl); diff --git a/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts b/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts index c55c32108f4..e628e95e9ad 100644 --- a/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts +++ b/extensions/ql-vscode/test/unit-tests/common/github-url-identifier-helper.test.ts @@ -34,6 +34,7 @@ describe("github url identifier helper", () => { it("should handle valid urls", () => { expect(getNwoFromGitHubUrl("github.com/foo/bar")).toBe("foo/bar"); + expect(getNwoFromGitHubUrl("www.github.com/foo/bar")).toBe("foo/bar"); expect(getNwoFromGitHubUrl("https://github.com/foo/bar")).toBe("foo/bar"); expect(getNwoFromGitHubUrl("http://github.com/foo/bar")).toBe("foo/bar"); expect(getNwoFromGitHubUrl("https://www.github.com/foo/bar")).toBe( @@ -66,6 +67,7 @@ describe("github url identifier helper", () => { ).toBe("foo"); expect(getOwnerFromGitHubUrl("https://www.github.com/foo")).toBe("foo"); expect(getOwnerFromGitHubUrl("github.com/foo")).toBe("foo"); + expect(getOwnerFromGitHubUrl("www.github.com/foo")).toBe("foo"); }); }); });