Allow usage of github.com
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user