-
Notifications
You must be signed in to change notification settings - Fork 7
Parse git urls #127
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
Merged
Merged
Parse git urls #127
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 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 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
64 changes: 64 additions & 0 deletions
64
plugins/backstage-plugin-devcontainers-backend/src/utils/git.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,64 @@ | ||
| import { parseGitUrl } from './git'; | ||
|
|
||
| describe('git', () => { | ||
| it('parses urls', () => { | ||
| // List of forges and the various ways URLs can be formed. | ||
| const forges = { | ||
| github: { | ||
| saas: 'github.com', | ||
| paths: [ | ||
| '/tree/foo', | ||
| '/blob/foo', | ||
| '/tree/foo/dir', | ||
| '/blob/foo/dir/file.ts', | ||
| ], | ||
| }, | ||
| gitlab: { | ||
| saas: 'gitlab.com', | ||
| paths: [ | ||
| '/-/tree/foo', | ||
| '/-/blob/foo', | ||
| '/-/tree/foo/dir?ref_type=heads', | ||
| '/-/blob/foo/dir/file.ts?ref_type=heads', | ||
| ], | ||
| }, | ||
| bitbucket: { | ||
| saas: 'bitbucket.org', | ||
| paths: [ | ||
| '/src/hashOrTag', | ||
| '/src/hashOrTag?at=foo', | ||
| '/src/hashOrTag/dir', | ||
| '/src/hashOrTag/dir?at=foo', | ||
| '/src/hashOrTag/dir/file.ts', | ||
| '/src/hashOrTag/dir/file.ts?at=foo', | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| for (const [forge, test] of Object.entries(forges)) { | ||
| // These are URLs that point to the root of the repository. To these we | ||
| // append the above paths to test that the original root URL is extracted. | ||
| const baseUrls = [ | ||
| // Most common format. | ||
| `https://${test.saas}/coder/backstage-plugins`, | ||
| // GitLab lets you have a sub-group. | ||
| `https://${test.saas}/coder/group/backstage-plugins`, | ||
| // Self-hosted. | ||
| `https://${forge}.coder.com/coder/backstage-plugins`, | ||
| // Self-hosted at a port. | ||
| `https://${forge}.coder.com:9999/coder/backstage-plugins`, | ||
| // Self-hosted at base path. | ||
| `https://${forge}.coder.com/base/path/coder/backstage-plugins`, | ||
| // Self-hosted without the forge anywhere in the domain. | ||
| 'https://coder.com/coder/backstage-plugins', | ||
| ]; | ||
| for (const baseUrl of baseUrls) { | ||
| expect(parseGitUrl(baseUrl)).toEqual(baseUrl); | ||
| for (const path of test.paths) { | ||
| const url = `${baseUrl}${path}`; | ||
| expect(parseGitUrl(url)).toEqual(baseUrl); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| }); |
12 changes: 12 additions & 0 deletions
12
plugins/backstage-plugin-devcontainers-backend/src/utils/git.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,12 @@ | ||
| import parse from 'git-url-parse'; | ||
|
|
||
| /** | ||
| * Given a repository URL, figure out the base repository. | ||
| */ | ||
| export function parseGitUrl(url: string): String { | ||
| const parsed = parse(url); | ||
| // Although it seems to have a `host` property, it is not on the types, so we | ||
| // will have to reconstruct it. | ||
| const host = parsed.resource + (parsed.port ? `:${parsed.port}` : ''); | ||
| return `${parsed.protocol}://${host}/${parsed.full_name}`; | ||
| } |
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 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 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 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 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 |
|---|---|---|
|
|
@@ -8419,6 +8419,11 @@ | |
| "@types/qs" "*" | ||
| "@types/serve-static" "*" | ||
|
|
||
| "@types/git-url-parse@^9.0.3": | ||
| version "9.0.3" | ||
| resolved "https://registry.yarnpkg.com/@types/git-url-parse/-/git-url-parse-9.0.3.tgz#7ee022f8fa06ea74148aa28521cbff85915ac09d" | ||
| integrity sha512-Wrb8zeghhpKbYuqAOg203g+9YSNlrZWNZYvwxJuDF4dTmerijqpnGbI79yCuPtHSXHPEwv1pAFUB4zsSqn82Og== | ||
|
|
||
| "@types/graceful-fs@^4.1.3": | ||
| version "4.1.9" | ||
| resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.9.tgz#2a06bc0f68a20ab37b3e36aa238be6abdf49e8b4" | ||
|
|
@@ -21913,7 +21918,16 @@ string-length@^4.0.1: | |
| char-regex "^1.0.2" | ||
| strip-ansi "^6.0.0" | ||
|
|
||
| "string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: | ||
| "string-width-cjs@npm:string-width@^4.2.0": | ||
| version "4.2.3" | ||
| resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" | ||
| integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== | ||
| dependencies: | ||
| emoji-regex "^8.0.0" | ||
| is-fullwidth-code-point "^3.0.0" | ||
| strip-ansi "^6.0.1" | ||
|
|
||
| "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: | ||
| version "4.2.3" | ||
| resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" | ||
| integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== | ||
|
|
@@ -21987,7 +22001,7 @@ string_decoder@~1.1.1: | |
| dependencies: | ||
| safe-buffer "~5.1.0" | ||
|
|
||
| "strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: | ||
| "strip-ansi-cjs@npm:strip-ansi@^6.0.1": | ||
| version "6.0.1" | ||
| resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" | ||
| integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== | ||
|
|
@@ -22001,6 +22015,13 @@ [email protected]: | |
| dependencies: | ||
| ansi-regex "^4.1.0" | ||
|
|
||
| strip-ansi@^6.0.0, strip-ansi@^6.0.1: | ||
| version "6.0.1" | ||
| resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" | ||
| integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== | ||
| dependencies: | ||
| ansi-regex "^5.0.1" | ||
|
|
||
| strip-ansi@^7.0.1: | ||
| version "7.1.0" | ||
| resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" | ||
|
|
@@ -23809,7 +23830,7 @@ wordwrap@^1.0.0: | |
| resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" | ||
| integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== | ||
|
|
||
| "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: | ||
| "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": | ||
| version "7.0.0" | ||
| resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" | ||
| integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== | ||
|
|
@@ -23827,6 +23848,15 @@ wrap-ansi@^6.0.1: | |
| string-width "^4.1.0" | ||
| strip-ansi "^6.0.0" | ||
|
|
||
| wrap-ansi@^7.0.0: | ||
| version "7.0.0" | ||
| resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" | ||
| integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== | ||
| dependencies: | ||
| ansi-styles "^4.0.0" | ||
| string-width "^4.1.0" | ||
| strip-ansi "^6.0.0" | ||
|
|
||
| wrap-ansi@^8.1.0: | ||
| version "8.1.0" | ||
| resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" | ||
|
|
||
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.