惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
腾讯CDC
GbyAI
GbyAI
I
InfoQ
博客园 - Franky
G
Google Developers Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
Vercel News
Vercel News
博客园_首页
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
V
V2EX
T
The Blog of Author Tim Ferriss
M
MIT News - Artificial intelligence
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
The GitHub Blog
The GitHub Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor: share git url parsing helpers · openclaw/opencl...
vincentkoc · 2026-05-30 · via Recent Commits to openclaw:main

@@ -18,43 +18,47 @@ export type GitSource = {

1818

pinned: boolean;

1919

};

202021+

function splitPathRef(params: {

22+

originalRepo: string;

23+

pathWithMaybeRef: string;

24+

buildRepo: (repoPath: string) => string;

25+

}): { repo: string; ref?: string } {

26+

const refSeparator = params.pathWithMaybeRef.indexOf("@");

27+

if (refSeparator < 0) {

28+

return { repo: params.originalRepo };

29+

}

30+

const repoPath = params.pathWithMaybeRef.slice(0, refSeparator);

31+

const ref = params.pathWithMaybeRef.slice(refSeparator + 1);

32+

if (!repoPath || !ref) {

33+

return { repo: params.originalRepo };

34+

}

35+

return {

36+

repo: params.buildRepo(repoPath),

37+

ref,

38+

};

39+

}

40+2141

function splitRef(url: string): { repo: string; ref?: string } {

2242

const scpLikeMatch = url.match(/^git@([^:]+):(.+)$/);

2343

if (scpLikeMatch) {

24-

const pathWithMaybeRef = scpLikeMatch[2] ?? "";

25-

const refSeparator = pathWithMaybeRef.indexOf("@");

26-

if (refSeparator < 0) {

27-

return { repo: url };

28-

}

29-

const repoPath = pathWithMaybeRef.slice(0, refSeparator);

30-

const ref = pathWithMaybeRef.slice(refSeparator + 1);

31-

if (!repoPath || !ref) {

32-

return { repo: url };

33-

}

34-

return {

35-

repo: `git@${scpLikeMatch[1] ?? ""}:${repoPath}`,

36-

ref,

37-

};

44+

return splitPathRef({

45+

originalRepo: url,

46+

pathWithMaybeRef: scpLikeMatch[2] ?? "",

47+

buildRepo: (repoPath) => `git@${scpLikeMatch[1] ?? ""}:${repoPath}`,

48+

});

3849

}

39504051

if (url.includes("://")) {

4152

try {

4253

const parsed = new URL(url);

43-

const pathWithMaybeRef = parsed.pathname.replace(/^\/+/, "");

44-

const refSeparator = pathWithMaybeRef.indexOf("@");

45-

if (refSeparator < 0) {

46-

return { repo: url };

47-

}

48-

const repoPath = pathWithMaybeRef.slice(0, refSeparator);

49-

const ref = pathWithMaybeRef.slice(refSeparator + 1);

50-

if (!repoPath || !ref) {

51-

return { repo: url };

52-

}

53-

parsed.pathname = `/${repoPath}`;

54-

return {

55-

repo: parsed.toString().replace(/\/$/, ""),

56-

ref,

57-

};

54+

return splitPathRef({

55+

originalRepo: url,

56+

pathWithMaybeRef: parsed.pathname.replace(/^\/+/, ""),

57+

buildRepo: (repoPath) => {

58+

parsed.pathname = `/${repoPath}`;

59+

return parsed.toString().replace(/\/$/, "");

60+

},

61+

});

5862

} catch {

5963

return { repo: url };

6064

}

@@ -65,20 +69,11 @@ function splitRef(url: string): { repo: string; ref?: string } {

6569

return { repo: url };

6670

}

6771

const host = url.slice(0, slashIndex);

68-

const pathWithMaybeRef = url.slice(slashIndex + 1);

69-

const refSeparator = pathWithMaybeRef.indexOf("@");

70-

if (refSeparator < 0) {

71-

return { repo: url };

72-

}

73-

const repoPath = pathWithMaybeRef.slice(0, refSeparator);

74-

const ref = pathWithMaybeRef.slice(refSeparator + 1);

75-

if (!repoPath || !ref) {

76-

return { repo: url };

77-

}

78-

return {

79-

repo: `${host}/${repoPath}`,

80-

ref,

81-

};

72+

return splitPathRef({

73+

originalRepo: url,

74+

pathWithMaybeRef: url.slice(slashIndex + 1),

75+

buildRepo: (repoPath) => `${host}/${repoPath}`,

76+

});

8277

}

83788479

function parseGenericGitUrl(url: string): GitSource | null {

@@ -154,6 +149,33 @@ function normalizeGitPath(path: string): string | null {

154149

return segments.join("/");

155150

}

156151152+

function resolveHostedGitSource(params: {

153+

candidate: string;

154+

split: { repo: string; ref?: string };

155+

repo: string;

156+

}): GitSource | null {

157+

const info = hostedGitInfo.fromUrl(params.candidate);

158+

if (!info) {

159+

return null;

160+

}

161+

if (params.split.ref && info.project?.includes("@")) {

162+

return null;

163+

}

164+

const host = info.domain || "";

165+

const path = normalizeGitPath(`${info.user}/${info.project}`);

166+

if (!isSafeGitHost(host) || !path) {

167+

return null;

168+

}

169+

return {

170+

type: "git",

171+

repo: params.repo,

172+

host,

173+

path,

174+

ref: info.committish || params.split.ref || undefined,

175+

pinned: Boolean(info.committish || params.split.ref),

176+

};

177+

}

178+157179

/**

158180

* Parse git source into a GitSource.

159181

*

@@ -176,30 +198,19 @@ export function parseGitUrl(source: string): GitSource | null {

176198

(value): value is string => Boolean(value),

177199

);

178200

for (const candidate of hostedCandidates) {

179-

const info = hostedGitInfo.fromUrl(candidate);

180-

if (info) {

181-

if (split.ref && info.project?.includes("@")) {

182-

continue;

183-

}

184-

const host = info.domain || "";

185-

const path = normalizeGitPath(`${info.user}/${info.project}`);

186-

if (!isSafeGitHost(host) || !path) {

187-

continue;

188-

}

189-

const useHttpsPrefix =

190-

!split.repo.startsWith("http://") &&

191-

!split.repo.startsWith("https://") &&

192-

!split.repo.startsWith("ssh://") &&

193-

!split.repo.startsWith("git://") &&

194-

!split.repo.startsWith("git@");

195-

return {

196-

type: "git",

197-

repo: useHttpsPrefix ? `https://${split.repo}` : split.repo,

198-

host,

199-

path,

200-

ref: info.committish || split.ref || undefined,

201-

pinned: Boolean(info.committish || split.ref),

202-

};

201+

const useHttpsPrefix =

202+

!split.repo.startsWith("http://") &&

203+

!split.repo.startsWith("https://") &&

204+

!split.repo.startsWith("ssh://") &&

205+

!split.repo.startsWith("git://") &&

206+

!split.repo.startsWith("git@");

207+

const parsed = resolveHostedGitSource({

208+

candidate,

209+

split,

210+

repo: useHttpsPrefix ? `https://${split.repo}` : split.repo,

211+

});

212+

if (parsed) {

213+

return parsed;

203214

}

204215

}

205216

@@ -208,24 +219,13 @@ export function parseGitUrl(source: string): GitSource | null {

208219

`https://${url}`,

209220

].filter((value): value is string => Boolean(value));

210221

for (const candidate of httpsCandidates) {

211-

const info = hostedGitInfo.fromUrl(candidate);

212-

if (info) {

213-

if (split.ref && info.project?.includes("@")) {

214-

continue;

215-

}

216-

const host = info.domain || "";

217-

const path = normalizeGitPath(`${info.user}/${info.project}`);

218-

if (!isSafeGitHost(host) || !path) {

219-

continue;

220-

}

221-

return {

222-

type: "git",

223-

repo: `https://${split.repo}`,

224-

host,

225-

path,

226-

ref: info.committish || split.ref || undefined,

227-

pinned: Boolean(info.committish || split.ref),

228-

};

222+

const parsed = resolveHostedGitSource({

223+

candidate,

224+

split,

225+

repo: `https://${split.repo}`,

226+

});

227+

if (parsed) {

228+

return parsed;

229229

}

230230

}

231231