Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions apps/web/src/components/cloud-agent-next/utils/git-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
buildRepoBrowseUrl,
detectGitPlatform,
extractRepoFromGitUrl,
buildPrepareSessionRepoParams,
findAllGitPlatformUrls,
} from './git-utils';

Expand Down Expand Up @@ -217,34 +216,6 @@ describe('extractRepoFromGitUrl', () => {
});
});

describe('buildPrepareSessionRepoParams', () => {
test('github platform with repo', () => {
expect(buildPrepareSessionRepoParams({ repo: 'owner/repo', platform: 'github' })).toEqual({
githubRepo: 'owner/repo',
});
});

test('gitlab platform with repo', () => {
expect(buildPrepareSessionRepoParams({ repo: 'group/project', platform: 'gitlab' })).toEqual({
gitlabProject: 'group/project',
});
});

test('bitbucket platform requires structured repository identity', () => {
expect(
buildPrepareSessionRepoParams({ repo: 'workspace/repo', platform: 'bitbucket' })
).toBeNull();
});

test('null repo returns null', () => {
expect(buildPrepareSessionRepoParams({ repo: null, platform: 'github' })).toBeNull();
});

test('empty string repo returns null', () => {
expect(buildPrepareSessionRepoParams({ repo: '', platform: 'github' })).toBeNull();
});
});

describe('findAllGitPlatformUrls', () => {
test('extracts GitHub URL from plain text', () => {
expect(findAllGitPlatformUrls('Fix https://github.com/owner/repo/issues/42 please')).toEqual([
Expand Down
22 changes: 0 additions & 22 deletions apps/web/src/components/cloud-agent-next/utils/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* This module has no dependencies on other cloud-agent-next modules to avoid circular imports.
*/

import { PLATFORM } from '@/lib/integrations/core/constants';

/**
* Extract owner/repo, group/project, or workspace/repo from a git URL
*
Expand Down Expand Up @@ -65,26 +63,6 @@ export function extractRepoFromGitUrl(gitUrl: string | null | undefined): string

export type GitPlatform = 'github' | 'gitlab' | 'bitbucket';

export function buildPrepareSessionRepoParams(options: {
repo?: string | null;
platform: GitPlatform;
}): { githubRepo?: string; gitlabProject?: string } | null {
const repo = options.repo?.trim();
if (!repo) return null;

switch (options.platform) {
case PLATFORM.GITHUB:
return { githubRepo: repo };
case PLATFORM.GITLAB:
return { gitlabProject: repo };
case 'bitbucket':
return null;
default:
options.platform satisfies never;
return null;
}
}

export function buildRepoBrowseUrl(gitUrl: string | null | undefined): string | undefined {
if (!gitUrl) return undefined;

Expand Down
145 changes: 0 additions & 145 deletions apps/web/src/components/cloud-agent/utils/git-utils.test.ts

This file was deleted.

72 changes: 2 additions & 70 deletions apps/web/src/components/cloud-agent/utils/git-utils.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,2 @@
/**
* Git URL Utilities
*
* Pure utility functions for parsing and extracting information from git URLs.
* This module has no dependencies on other cloud-agent modules to avoid circular imports.
*/

import { PLATFORM } from '@/lib/integrations/core/constants';

/**
* Extract owner/repo or group/project from a git URL
*
* Supports formats:
* - https://github.com/owner/repo
* - https://github.com/owner/repo.git
* - git@github.com:owner/repo.git
* - git@github.com:owner/repo
* - https://gitlab.com/group/project.git
* - https://gitlab.com/group/subgroup/project.git (nested GitLab groups)
* - git@gitlab.com:group/project.git
* - git@gitlab.com:group/subgroup/project.git (nested GitLab groups)
*
* @param gitUrl - The git URL to parse
* @returns owner/repo or group/project format string, or undefined if parsing fails
*/
export function extractRepoFromGitUrl(gitUrl: string | null | undefined): string | undefined {
if (!gitUrl) return undefined;

// SSH format: git@github.com:owner/repo.git or git@gitlab.com:group/subgroup/project.git
const sshMatch = gitUrl.match(/^git@[^:]+:(.+?)(?:\.git)?$/);
if (sshMatch) {
return sshMatch[1];
}

// HTTPS format: https://github.com/owner/repo.git or https://gitlab.com/group/subgroup/project.git
try {
const url = new URL(gitUrl);
const pathParts = url.pathname.split('/').filter(Boolean);
if (pathParts.length >= 2) {
// For clone URLs (ending in .git), use the full path (supports nested GitLab groups)
// For non-clone URLs (like GitHub tree URLs), only use first two segments
const fullPath = pathParts.join('/');
if (fullPath.endsWith('.git')) {
return fullPath.replace(/\.git$/, '');
}
// Non-clone URL: only take owner/repo (first two segments)
return `${pathParts[0]}/${pathParts[1]}`;
}
} catch {
// Not a valid URL
}

return undefined;
}

export type GitPlatform = 'github' | 'gitlab';

export function buildPrepareSessionRepoParams(options: {
repo?: string | null;
platform: GitPlatform;
}): { githubRepo?: string; gitlabProject?: string } | null {
const repo = options.repo?.trim();
if (!repo) return null;

if (options.platform === PLATFORM.GITLAB) {
return { gitlabProject: repo };
}

return { githubRepo: repo };
}
export { extractRepoFromGitUrl } from '@/components/cloud-agent-next/utils/git-utils';
export type { GitPlatform } from '@/components/cloud-agent-next/utils/git-utils';