Skip to content

Commit f428e36

Browse files
committed
[protocol] Make ContextURL.parseToURL support the newly-accepted 'git@{host}:{user}/{repo}.git' format
Fixes #8097 Companion to #7951
1 parent 6e8e2a5 commit f428e36

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

components/gitpod-protocol/src/context-url.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export class ContextUrlTest {
2424
expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
2525
}
2626

27+
@test public parseContextUrl_withEnvVar_sshUrl() {
28+
const actual = ContextURL.parseToURL("passedin=test%20value/[email protected]:gitpod-io/gitpod-test-repo.git");
29+
expect(actual?.host).to.equal("github.com");
30+
expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo.git");
31+
}
32+
2733
@test public parseContextUrl_withPrebuild() {
2834
const actual = ContextURL.parseToURL("prebuild/https://github.com/gitpod-io/gitpod-test-repo");
2935
expect(actual?.host).to.equal("github.com");
@@ -35,5 +41,10 @@ export class ContextUrlTest {
3541
expect(actual?.host).to.equal("github.com");
3642
expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
3743
}
44+
45+
@test public parseContextUrl_badUrl() {
46+
const actual = ContextURL.parseToURL("this/will/not/work");
47+
expect(actual).to.be.undefined;
48+
}
3849
}
3950
module.exports = new ContextUrlTest()

components/gitpod-protocol/src/context-url.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ export namespace ContextURL {
2626
return new URL(segments[0]); // this might be something, we just try
2727
}
2828

29-
const segmentsToURL = (offset: number): URL => {
29+
const segmentsToURL = (offset: number): URL | undefined => {
3030
let rest = segments.slice(offset).join("/");
3131
if (!rest.startsWith("http")) {
3232
rest = 'https://' + rest;
3333
}
34-
return new URL(rest);
34+
if (/^git@[^:\/]+:/.test(rest)) {
35+
rest = rest.replace(/^git@([^:\/]+):/, 'https://$1/');
36+
}
37+
try {
38+
return new URL(rest);
39+
} catch (error) {
40+
console.error('Could not parse context URL', rest, error);
41+
}
3542
};
3643

3744

0 commit comments

Comments
 (0)