MCPcopy Create free account
hub / github.com/LF112/gotAction / normalizeRepoUrl

Function normalizeRepoUrl

scripts/check-github-repo.js:14–34  ·  view source on GitHub ↗

* 归一化仓库链接(修复路径解析,正确拼接用户名/仓库名) * @param {string} url 原始链接 * @returns { { normalized: string, raw: string } } 归一化后的链接 + 原始链接

(url)

Source from the content-addressed store, hash-verified

12 * @returns { { normalized: string, raw: string } } 归一化后的链接 + 原始链接
13 */
14function normalizeRepoUrl(url) {
15 try {
16 const urlObj = new URL(url);
17 // 拆分路径并过滤空字符串(解决双斜杠导致的空元素问题)
18 const pathParts = urlObj.pathname.split('/').filter((part) => part.trim() !== '');
19
20 // 必须满足 用户名/仓库名 两级路径(排除作者主页)
21 if (pathParts.length >= 2) {
22 const [owner, repo] = pathParts; // 第一级是用户名,第二级是仓库名
23 // 正确拼接:避免双斜杠,严格拼接 用户名/仓库名.git
24 const normalizedUrl = `https://github.com/${owner}/${repo}.git`;
25 return {
26 normalized: normalizedUrl,
27 raw: url,
28 };
29 }
30 return { normalized: null, raw: url };
31 } catch (err) {
32 return { normalized: null, raw: url };
33 }
34}
35
36/**
37 * 执行 git ls-remote 检查仓库可达性(适配 403/仓库禁用场景)

Callers 1

checkRepoAccessibilityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected