From eb51293ddd6b44b21de640cc322d28ed08da63a9 Mon Sep 17 00:00:00 2001 From: kevin <5299031+kevin9327@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:12:22 +0900 Subject: [PATCH] fix(github): read dotted repo names from the origin remote in github_repo_analyze (#4571) The remote-URL pattern stopped the repo name at the first dot, so remotes like vercel/next.js or socketio/socket.io did not match and the repository was reported and stored as local/repo. --- .../github-repo-analyze-dotted-name.test.ts | 71 +++++++++++++++++++ .../cli/src/mcp-tools/github-tools.ts | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts diff --git a/v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts b/v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts new file mode 100644 index 0000000000..fa4d2a9189 --- /dev/null +++ b/v3/@claude-flow/cli/__tests__/github-repo-analyze-dotted-name.test.ts @@ -0,0 +1,71 @@ +/** + * github_repo_analyze reads owner/repo from `git remote get-url origin` when + * they are not passed. The pattern stopped the repo name at the first dot, so + * remotes such as vercel/next.js or socketio/socket.io did not match and the + * repository was reported (and stored) as local/repo. + * + * Mocks `node:child_process` like github-tools-false-success-4424.test.ts. + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { mkdirSync, mkdtempSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; + +const execSyncMock = vi.fn(); + +vi.mock('node:child_process', () => ({ + execFileSync: vi.fn(), + execSync: (...args: unknown[]) => execSyncMock(...args), +})); + +const originalProjectCwd = process.env.CLAUDE_FLOW_CWD; + +function gitWithRemote(remoteUrl: string) { + execSyncMock.mockImplementation((cmd: string) => { + if (cmd === 'git remote get-url origin') return `${remoteUrl}\n`; + if (cmd === 'git rev-list --count HEAD') return '42\n'; + if (cmd.startsWith('git ')) return '1\n'; + // No gh CLI: skip the issue/PR counts. + throw new Error('not found'); + }); +} + +async function analyze(input: Record = {}) { + const { githubTools } = await import('../src/mcp-tools/github-tools.js'); + const t = githubTools.find((c) => c.name === 'github_repo_analyze')!; + return (await t.handler(input)) as Record; +} + +beforeEach(() => { + execSyncMock.mockReset(); + const scratch = mkdtempSync(join(tmpdir(), 'ruflo-repo-analyze-')); + process.env.CLAUDE_FLOW_CWD = scratch; + mkdirSync(join(scratch, '.claude-flow', 'github'), { recursive: true }); +}); + +afterEach(() => { + if (originalProjectCwd === undefined) delete process.env.CLAUDE_FLOW_CWD; + else process.env.CLAUDE_FLOW_CWD = originalProjectCwd; +}); + +describe('github_repo_analyze owner/repo from the origin remote', () => { + it.each([ + ['https://github.com/vercel/next.js.git', 'vercel/next.js'], + ['https://github.com/vercel/next.js', 'vercel/next.js'], + ['git@github.com:socketio/socket.io.git', 'socketio/socket.io'], + ['git@github.com:mrdoob/three.js', 'mrdoob/three.js'], + ['https://github.com/ruvnet/ruflo.git', 'ruvnet/ruflo'], + ['git@github.com:ruvnet/ruflo', 'ruvnet/ruflo'], + ])('%s is %s', async (remoteUrl, expected) => { + gitWithRemote(remoteUrl); + const r = await analyze(); + expect(r.success).toBe(true); + expect(r.repository).toBe(expected); + }); + + it('keeps an explicitly passed owner and repo', async () => { + gitWithRemote('https://github.com/vercel/next.js.git'); + const r = await analyze({ owner: 'acme', repo: 'widgets' }); + expect(r.repository).toBe('acme/widgets'); + }); +}); diff --git a/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts index 2d3b69ec2b..97c58ba18b 100644 --- a/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts +++ b/v3/@claude-flow/cli/src/mcp-tools/github-tools.ts @@ -181,7 +181,7 @@ export const githubTools: MCPTool[] = [ let owner = (input.owner as string) || ''; let repo = (input.repo as string) || ''; if (remoteUrl && (!owner || !repo)) { - const m = remoteUrl.match(/[:/]([^/]+)\/([^/.]+?)(?:\.git)?$/); + const m = remoteUrl.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/); if (m) { owner = owner || m[1]; repo = repo || m[2]; } } const repoKey = `${owner || 'local'}/${repo || 'repo'}`;