-
Notifications
You must be signed in to change notification settings - Fork 226
Create "Add database" button in DB panel #1882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
extensions/ql-vscode/src/common/github-url-identifier-helper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { OWNER_REGEX, REPO_REGEX } from "../pure/helpers-pure"; | ||
|
|
||
| /** | ||
| * Checks if a string is a valid GitHub NWO. | ||
| * @param identifier The GitHub NWO | ||
| * @returns | ||
| */ | ||
| export function validGitHubNwo(identifier: string): boolean { | ||
| return validGitHubNwoOrOwner(identifier, "nwo"); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a string is a valid GitHub owner. | ||
| * @param identifier The GitHub owner | ||
| * @returns | ||
| */ | ||
| export function validGitHubOwner(identifier: string): boolean { | ||
| return validGitHubNwoOrOwner(identifier, "owner"); | ||
| } | ||
|
|
||
| function validGitHubNwoOrOwner( | ||
| identifier: string, | ||
| kind: "owner" | "nwo", | ||
| ): boolean { | ||
| return kind === "owner" | ||
| ? OWNER_REGEX.test(identifier) | ||
| : REPO_REGEX.test(identifier); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts an NOW from a GitHub URL. | ||
| * @param githubUrl The GitHub repository URL | ||
| * @return The corresponding NWO, or undefined if the URL is not valid | ||
| */ | ||
| export function getNwoFromGitHubUrl(githubUrl: string): string | undefined { | ||
| return getNwoOrOwnerFromGitHubUrl(githubUrl, "nwo"); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts an owner from a GitHub URL. | ||
| * @param githubUrl The GitHub repository URL | ||
| * @return The corresponding Owner, or undefined if the URL is not valid | ||
| */ | ||
| export function getOwnerFromGitHubUrl(githubUrl: string): string | undefined { | ||
| return getNwoOrOwnerFromGitHubUrl(githubUrl, "owner"); | ||
| } | ||
|
|
||
| function getNwoOrOwnerFromGitHubUrl( | ||
| githubUrl: string, | ||
| kind: "owner" | "nwo", | ||
| ): string | undefined { | ||
| try { | ||
| const uri = new URL(githubUrl); | ||
| if (uri.protocol !== "https:") { | ||
| return; | ||
| } | ||
| if (uri.hostname !== "github.com" && uri.hostname !== "www.github.com") { | ||
| return; | ||
| } | ||
| const paths = uri.pathname.split("/").filter((segment: string) => segment); | ||
| const owner = `${paths[0]}`; | ||
| if (kind === "owner") { | ||
| return owner ? owner : undefined; | ||
| } | ||
| const nwo = `${paths[0]}/${paths[1]}`; | ||
| return paths[1] ? nwo : undefined; | ||
| } catch (e) { | ||
| // Ignore the error here, since we catch failures at a higher level. | ||
| return; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
extensions/ql-vscode/test/pure-tests/common/github-url-identifier-helper.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { | ||
| getNwoFromGitHubUrl, | ||
| getOwnerFromGitHubUrl, | ||
| validGitHubNwo, | ||
| validGitHubOwner, | ||
| } from "../../../src/common/github-url-identifier-helper"; | ||
|
|
||
| describe("github url identifier helper", () => { | ||
| describe("valid GitHub Nwo Or Owner method", () => { | ||
| it("should return true for valid owner", () => { | ||
| expect(validGitHubOwner("github")).toBe(true); | ||
| }); | ||
| it("should return true for valid NWO", () => { | ||
| expect(validGitHubNwo("github/codeql")).toBe(true); | ||
| }); | ||
| it("should return false for invalid owner", () => { | ||
| expect(validGitHubOwner("github/codeql")).toBe(false); | ||
| }); | ||
| it("should return false for invalid NWO", () => { | ||
| expect(validGitHubNwo("githubl")).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| 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, | ||
| ); | ||
| expect(getNwoFromGitHubUrl("https://www.github.com/foo")).toBe(undefined); | ||
| expect(getNwoFromGitHubUrl("foo")).toBe(undefined); | ||
| expect(getNwoFromGitHubUrl("foo/bar")).toBe(undefined); | ||
| }); | ||
|
|
||
| it("should handle valid urls", () => { | ||
| expect(getNwoFromGitHubUrl("https://github.com/foo/bar")).toBe("foo/bar"); | ||
| expect(getNwoFromGitHubUrl("https://www.github.com/foo/bar")).toBe( | ||
| "foo/bar", | ||
| ); | ||
| expect(getNwoFromGitHubUrl("https://github.com/foo/bar/sub/pages")).toBe( | ||
| "foo/bar", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| 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, | ||
| ); | ||
| expect(getOwnerFromGitHubUrl("foo")).toBe(undefined); | ||
| expect(getOwnerFromGitHubUrl("foo/bar")).toBe(undefined); | ||
| }); | ||
|
|
||
| it("should handle valid urls", () => { | ||
| expect(getOwnerFromGitHubUrl("https://github.com/foo/bar")).toBe("foo"); | ||
| expect(getOwnerFromGitHubUrl("https://www.github.com/foo/bar")).toBe( | ||
| "foo", | ||
| ); | ||
| expect( | ||
| getOwnerFromGitHubUrl("https://github.com/foo/bar/sub/pages"), | ||
| ).toBe("foo"); | ||
| expect(getOwnerFromGitHubUrl("https://www.github.com/foo")).toBe("foo"); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.