-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4f3749
commit 2fd0959
Showing
11 changed files
with
177 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from './service/router'; | ||
export { DevcontainersProcessor } from './processors/DevcontainersProcessor'; | ||
export { | ||
DevcontainersProcessor, | ||
type VsCodeUrlKey, | ||
} from './processors/DevcontainersProcessor'; |
This file contains 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 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 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 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 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 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 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 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 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" | ||
|