Skip to content

Remove git & local connection types #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
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
7 changes: 0 additions & 7 deletions packages/backend/src/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ export class ConnectionManager implements IConnectionManager {
case 'gerrit': {
return await compileGerritConfig(config, job.data.connectionId, orgId);
}
default: {
return {repoData: [], notFound: {
users: [],
orgs: [],
repos: [],
}};
}
}
})();
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/gerrit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fetch from 'cross-fetch';
import { GerritConfig } from "@sourcebot/schemas/v2/index.type"
import { createLogger } from './logger.js';
import micromatch from "micromatch";
import { measure, marshalBool, excludeReposByName, includeReposByName, fetchWithRetry } from './utils.js';
import { measure, fetchWithRetry } from './utils.js';
import { BackendError } from '@sourcebot/error';
import { BackendException } from '@sourcebot/error';

Expand Down
83 changes: 0 additions & 83 deletions packages/backend/src/git.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import { GitRepository, AppContext } from './types.js';
import { simpleGit, SimpleGitProgressEvent } from 'simple-git';
import { createLogger } from './logger.js';
import { GitConfig } from "@sourcebot/schemas/v2/index.type"
import path from 'path';

const logger = createLogger('git');

export const cloneRepository = async (cloneURL: string, path: string, gitConfig?: Record<string, string>, onProgress?: (event: SimpleGitProgressEvent) => void) => {
const git = simpleGit({
Expand Down Expand Up @@ -45,80 +39,3 @@ export const fetchRepository = async (path: string, onProgress?: (event: SimpleG
]
);
}

const isValidGitRepo = async (url: string): Promise<boolean> => {
const git = simpleGit();
try {
await git.listRemote([url]);
return true;
} catch (error) {
logger.debug(`Error checking if ${url} is a valid git repo: ${error}`);
return false;
}
}

const stripProtocolAndGitSuffix = (url: string): string => {
return url.replace(/^[a-zA-Z]+:\/\//, '').replace(/\.git$/, '');
}

const getRepoNameFromUrl = (url: string): string => {
const strippedUrl = stripProtocolAndGitSuffix(url);
return strippedUrl.split('/').slice(-2).join('/');
}

export const getGitRepoFromConfig = async (config: GitConfig, ctx: AppContext) => {
const repoValid = await isValidGitRepo(config.url);
if (!repoValid) {
logger.error(`Git repo provided in config with url ${config.url} is not valid`);
return null;
}

const cloneUrl = config.url;
const repoId = stripProtocolAndGitSuffix(cloneUrl);
const repoName = getRepoNameFromUrl(config.url);
const repoPath = path.resolve(path.join(ctx.reposPath, `${repoId}.git`));
const repo: GitRepository = {
vcs: 'git',
id: repoId,
name: repoName,
path: repoPath,
isStale: false,
cloneUrl: cloneUrl,
branches: [],
tags: [],
}

if (config.revisions) {
if (config.revisions.branches) {
const branchGlobs = config.revisions.branches;
const git = simpleGit();
const branchList = await git.listRemote(['--heads', cloneUrl]);
const branches = branchList
.split('\n')
.map(line => line.split('\t')[1])
.filter(Boolean)
.map(branch => branch.replace('refs/heads/', ''));

repo.branches = branches.filter(branch =>
branchGlobs.some(glob => new RegExp(glob).test(branch))
);
}

if (config.revisions.tags) {
const tagGlobs = config.revisions.tags;
const git = simpleGit();
const tagList = await git.listRemote(['--tags', cloneUrl]);
const tags = tagList
.split('\n')
.map(line => line.split('\t')[1])
.filter(Boolean)
.map(tag => tag.replace('refs/tags/', ''));

repo.tags = tags.filter(tag =>
tagGlobs.some(glob => new RegExp(glob).test(tag))
);
}
}

return repo;
}
71 changes: 0 additions & 71 deletions packages/backend/src/local.ts

This file was deleted.

43 changes: 0 additions & 43 deletions packages/backend/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
/**
* @deprecated in V3
*/
interface BaseRepository {
vcs: 'git' | 'local';
id: string;
name: string;
path: string;
isStale: boolean;
lastIndexedDate?: string;
isFork?: boolean;
isArchived?: boolean;
codeHost?: string;
topics?: string[];
sizeInBytes?: number;
tenantId?: number;
}

/**
* @deprecated in V3
*/
export interface GitRepository extends BaseRepository {
vcs: 'git';
cloneUrl: string;
branches: string[];
tags: string[];
gitConfigMetadata?: Record<string, string>;
}

/**
* @deprecated in V3
*/
export interface LocalRepository extends BaseRepository {
vcs: 'local';
excludedPaths: string[];
watch: boolean;
}

/**
* @deprecated in V3
*/
export type Repository = GitRepository | LocalRepository;

export type AppContext = {
/**
* Path to the repos cache directory.
Expand Down
Loading