From b910b4801b6024e3d390b088960f9ffaed0b3077 Mon Sep 17 00:00:00 2001 From: Huakun Shen Date: Mon, 24 Mar 2025 08:08:01 -0400 Subject: [PATCH] refactor: simplify GitHub repository URI parsing - Removed dependency on `parse-github-url` and implemented a regex-based approach for parsing GitHub repository URIs in the `parseGitHubRepoFromUri` function. - Enhanced error handling for invalid URIs while maintaining the function's output structure. --- packages/package-registry/package.json | 4 +--- packages/package-registry/src/github.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/package-registry/package.json b/packages/package-registry/package.json index 52a2c9f..1273062 100644 --- a/packages/package-registry/package.json +++ b/packages/package-registry/package.json @@ -13,7 +13,6 @@ }, "devDependencies": { "@types/bun": "latest", - "@types/parse-github-url": "^1.0.3", "verify-package-export": "^0.0.3" }, "peerDependencies": { @@ -22,7 +21,6 @@ "dependencies": { "@huakunshen/jsr-client": "^0.1.5", "@kksh/api": "workspace:*", - "@octokit/rest": "^21.1.0", - "parse-github-url": "^1.0.3" + "@octokit/rest": "^21.1.0" } } diff --git a/packages/package-registry/src/github.ts b/packages/package-registry/src/github.ts index d4734bb..6f94e0a 100644 --- a/packages/package-registry/src/github.ts +++ b/packages/package-registry/src/github.ts @@ -2,7 +2,6 @@ * TODO: move this module to another folder */ import { Octokit } from "@octokit/rest" -import gh from "parse-github-url" /** * Check if a user is a public member of a GitHub organization @@ -44,14 +43,14 @@ export function parseGitHubRepoFromUri(uri: string): { owner: string repo: string } { - const ghUrl = gh(uri) - if (!ghUrl) { + // check regex + const regex = /https?:\/\/github\.com\/([^\/]+)\/([^\/]+)/ + const match = uri.match(regex) + if (!match) { throw new Error("Invalid GitHub repository URI") } - if (!ghUrl.owner || !ghUrl.name) { - throw new Error("Invalid GitHub repository URI") - } - return { owner: ghUrl.owner, repo: ghUrl.name } + const [, owner, repo] = match + return { owner, repo } } /**