Skip to content

Commit a05bd79

Browse files
authored
Fix incorrect URLs for Github and GitLab (#17)
* Fix incorrect URLs being generated for Github and GitLab repositories * Bump up version
1 parent 8cdce6c commit a05bd79

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clone-with-devpod-extension",
33
"private": true,
4-
"version": "0.3.1",
4+
"version": "0.3.3",
55
"type": "module",
66
"license": "MIT",
77
"scripts": {

src/lib/integrations/github.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export class EGithubParseError extends EIntegrationParseError {
2323
}
2424

2525
function isPR(url: string | URL) {
26-
return /[/](?<repo>[^/]+[/][^/]+)([/]?pull[/](\d+))?/i.test(url.toString());
26+
return /^https?:[/][/][^/]+[/](?<repo>[^/]+[/][^/]+)([/]?pull[/](\d+))/i.test(
27+
url.toString(),
28+
);
2729
}
2830

2931
export const Github: Integration = {
@@ -48,7 +50,7 @@ export const Github: Integration = {
4850
},
4951
getRepo({ url }) {
5052
const results =
51-
/[/](?<repo>[^/]+[/][^/]+)([/]?tree[/](?<branch>[^?]+))?/i.exec(
53+
/^https?:[/][/][^/]+[/](?<repo>[^/]+[/][^/]+)([/]?tree[/](?<branch>[^?]+))?/i.exec(
5254
url.toString(),
5355
)?.groups;
5456
if (!results) {
@@ -101,7 +103,7 @@ export const Github: Integration = {
101103
return branch;
102104
} else {
103105
const results =
104-
/[/](?<repo>[^/]+[/][^/]+)([/]?tree[/](?<branch>[^?]+))/i.exec(
106+
/^https?:[/][/][^/]+[/](?<repo>[^/]+[/][^/]+)([/]?tree[/](?<branch>[^?]+))?/i.exec(
105107
url.toString(),
106108
)?.groups;
107109
if (!results) {

src/lib/integrations/gitlab.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const GitLab: Integration = {
4949
},
5050
getRepo({ url }) {
5151
const results =
52-
/[/](?<repo>[^/]+[/][^/]+)([/]?tree[/](?<branch>[^?]+))?/i.exec(
52+
/^https?:[/][/][^/]+[/](?<repo>[^/]+[/][^/]+)([/]?tree[/](?<branch>[^?]+))?/i.exec(
5353
url.toString(),
5454
)?.groups;
5555
if (!results) {
@@ -101,13 +101,14 @@ export const GitLab: Integration = {
101101
}
102102
return branch;
103103
} else {
104-
const results = /[/][^/]+[/][^/]+[/]-[/]tree[/](?<branch>[^?]+)/i.exec(
105-
url.toString(),
106-
)?.groups;
104+
const results =
105+
/^https?:[/][/][^/]+[/][^/]+[/][^/]+[/]-[/]tree[/](?<branch>[^?]+)/i.exec(
106+
url.toString(),
107+
)?.groups;
107108
if (!results) {
108109
throw new EGitLabParseError({
109110
data: {
110-
url: window.location.href,
111+
url: url.toString(),
111112
integration: "GitLab",
112113
cause: "no match",
113114
process: "branch",

src/pages/content/CloneButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ export function getDevPodUrl(url: string) {
2929
throw error;
3030
}
3131
}
32+
const { hostname, protocol } = new URL(url);
3233

3334
const branchSuffix = branch ? `@${branch}` : "";
34-
return `https://devpod.sh/open#https://github.com/${repo}${branchSuffix}`;
35+
return `https://devpod.sh/open#${protocol}://${hostname}/${repo}${branchSuffix}`;
3536
} catch (error) {
3637
console.error(EError.serialize(error));
3738
throw error;

0 commit comments

Comments
 (0)