Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 6eb10c1

Browse files
authored
HYP-2635: Fix git owner/repo parsing (#54)
1 parent 659ad66 commit 6eb10c1

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/commands/link/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ export default class LinkIndex extends Command {
127127
return;
128128
}
129129

130-
const gitOwner = gitUrl.split("/")[3];
131-
132-
const repoName = gitUrl.split("/")[4].replace(/\.git$/, "");
130+
const { gitOwner, repoName } = parseGitUrl(gitUrl);
133131

134132
const repoFullName = `${gitOwner}/${repoName}`;
135133

@@ -257,3 +255,17 @@ const linkHTML = `<!-- src/commands/login/login.html -->
257255
</body>
258256
</html>
259257
`;
258+
259+
function parseGitUrl(gitUrl: string) {
260+
const regex = /^(?:git@|https:\/\/)([^:/]+)[:/]([^/]+)\/([^/]+?)(?:\.git)?$/;
261+
const match = gitUrl.match(regex);
262+
263+
if (!match) {
264+
throw new Error(`Invalid Git URL: ${gitUrl}`);
265+
}
266+
267+
const gitOwner = match[2];
268+
const repoName = match[3];
269+
270+
return { gitOwner, repoName };
271+
}

src/util/graphql.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export async function sendGraphQLReqToHypermode(jwt: string, query: string): Pro
2424

2525
const response = await fetch(url, options);
2626

27+
console.log(jwt, response);
28+
2729
const data: any = await response.json();
2830
return data;
2931
}
@@ -104,7 +106,7 @@ export async function sendGetRepoIdReq(jwt: string, installationId: string, gitU
104106
const query = `
105107
query getUserRepoIdByUrl {
106108
getUserRepoIdByUrl(installationId: "${installationId}", gitUrl: "${gitUrl}")
107-
}`;
109+
}`;
108110

109111
const data: any = await sendGraphQLReqToHypermode(jwt, query);
110112

0 commit comments

Comments
 (0)