diff --git a/CHANGELOG.md b/CHANGELOG.md index 01ea51f27..f6319fce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed issue with filtering on generic git repo indexed from http/https [#742](https://github.com/sourcebot-dev/sourcebot/pull/742) + ## [4.10.10] - 2026-01-16 ### Added diff --git a/packages/backend/src/repoCompileUtils.test.ts b/packages/backend/src/repoCompileUtils.test.ts index 5bb356a5e..3c80fc62f 100644 --- a/packages/backend/src/repoCompileUtils.test.ts +++ b/packages/backend/src/repoCompileUtils.test.ts @@ -1,10 +1,11 @@ import { expect, test, vi, describe, beforeEach, afterEach } from 'vitest'; -import { compileGenericGitHostConfig_file } from './repoCompileUtils'; +import { compileGenericGitHostConfig_file, compileGenericGitHostConfig_url } from './repoCompileUtils'; // Mock the git module vi.mock('./git.js', () => ({ isPathAValidGitRepoRoot: vi.fn(), getOriginUrl: vi.fn(), + isUrlAValidGitRepo: vi.fn(), })); // Mock the glob module @@ -12,12 +13,13 @@ vi.mock('glob', () => ({ glob: vi.fn(), })); -import { isPathAValidGitRepoRoot, getOriginUrl } from './git.js'; +import { isPathAValidGitRepoRoot, getOriginUrl, isUrlAValidGitRepo } from './git.js'; import { glob } from 'glob'; const mockedGlob = vi.mocked(glob); const mockedIsPathAValidGitRepoRoot = vi.mocked(isPathAValidGitRepoRoot); const mockedGetOriginUrl = vi.mocked(getOriginUrl); +const mockedIsUrlAValidGitRepo = vi.mocked(isUrlAValidGitRepo); describe('compileGenericGitHostConfig_file', () => { beforeEach(() => { @@ -122,3 +124,71 @@ describe('compileGenericGitHostConfig_file', () => { expect(result.warnings[0]).toContain('not a git repository'); }); }); + +describe('compileGenericGitHostConfig_url', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + afterEach(() => { + vi.resetAllMocks(); + }); + + test('should return warning when url is not a valid git repo', async () => { + mockedIsUrlAValidGitRepo.mockResolvedValue(false); + + const config = { + type: 'git' as const, + url: 'https://example.com/not-a-repo', + }; + + const result = await compileGenericGitHostConfig_url(config, 1); + + expect(result.repoData).toHaveLength(0); + expect(result.warnings).toHaveLength(1); + expect(result.warnings[0]).toContain('not a git repository'); + }); + + test('should successfully compile with gitConfig when valid git repo url is found', async () => { + mockedIsUrlAValidGitRepo.mockResolvedValue(true); + + const config = { + type: 'git' as const, + url: 'https://git.kernel.org/pub/scm/bluetooth/bluez.git', + }; + + const result = await compileGenericGitHostConfig_url(config, 1); + + expect(result.repoData).toHaveLength(1); + expect(result.warnings).toHaveLength(0); + expect(result.repoData[0].cloneUrl).toBe('https://git.kernel.org/pub/scm/bluetooth/bluez.git'); + expect(result.repoData[0].name).toBe('git.kernel.org/pub/scm/bluetooth/bluez'); + + // Verify gitConfig is set properly (this is the key fix for SOU-218) + const metadata = result.repoData[0].metadata as { gitConfig?: Record }; + expect(metadata.gitConfig).toBeDefined(); + expect(metadata.gitConfig!['zoekt.name']).toBe('git.kernel.org/pub/scm/bluetooth/bluez'); + expect(metadata.gitConfig!['zoekt.web-url']).toBe('https://git.kernel.org/pub/scm/bluetooth/bluez.git'); + expect(metadata.gitConfig!['zoekt.display-name']).toBe('git.kernel.org/pub/scm/bluetooth/bluez'); + expect(metadata.gitConfig!['zoekt.archived']).toBe('0'); + expect(metadata.gitConfig!['zoekt.fork']).toBe('0'); + expect(metadata.gitConfig!['zoekt.public']).toBe('1'); + }); + + test('should handle url with trailing .git correctly', async () => { + mockedIsUrlAValidGitRepo.mockResolvedValue(true); + + const config = { + type: 'git' as const, + url: 'https://github.com/test/repo.git', + }; + + const result = await compileGenericGitHostConfig_url(config, 1); + + expect(result.repoData).toHaveLength(1); + expect(result.repoData[0].name).toBe('github.com/test/repo'); + + const metadata = result.repoData[0].metadata as { gitConfig?: Record }; + expect(metadata.gitConfig!['zoekt.name']).toBe('github.com/test/repo'); + }); +}); diff --git a/packages/backend/src/repoCompileUtils.ts b/packages/backend/src/repoCompileUtils.ts index eab9bafe9..678ef6ea8 100644 --- a/packages/backend/src/repoCompileUtils.ts +++ b/packages/backend/src/repoCompileUtils.ts @@ -609,9 +609,17 @@ export const compileGenericGitHostConfig_url = async ( } }, metadata: { + gitConfig: { + 'zoekt.name': repoName, + 'zoekt.web-url': remoteUrl.toString(), + 'zoekt.archived': marshalBool(false), + 'zoekt.fork': marshalBool(false), + 'zoekt.public': marshalBool(true), + 'zoekt.display-name': repoName, + }, branches: config.revisions?.branches ?? undefined, tags: config.revisions?.tags ?? undefined, - } + } satisfies RepoMetadata, }; return {