UNPKG

ds-sfcoe-ailabs

Version:

AI-powered code review tool with static analysis integration for comprehensive code quality assessment.

68 lines (67 loc) 3.32 kB
export default class GitHelper { /** * Create a temporary directory containing only the changed files between two Git references * * @param repoDir - The path to the Git repository directory * @param from - The source commit/branch reference for diff comparison * @param to - The target commit/branch reference for diff comparison * @returns Promise resolving to the path of the temporary directory containing changed files * @throws Error if Git operations fail or file copying encounters issues */ static createDirectoryWithDiff(repoDir: string, from: string, to: string): Promise<string>; /** * Verify and resolve a commit SHA to its full form * * @param repoDir - The path to the Git repository directory * @param commitSha - The commit SHA or reference to verify (can be short SHA, HEAD, branch name, etc.) * @returns Promise resolving to the full commit SHA * @throws Error if the commit SHA cannot be verified or resolved */ static verifyCommitSha(repoDir: string, commitSha: string): Promise<string>; /** * Gets changed line ranges for each file between two commits * * @param repoDir - The path to the Git repository directory * @param from - The source commit/branch reference for diff comparison * @param to - The target commit/branch reference for diff comparison * @returns Promise resolving to a map of file paths to arrays of changed line ranges * @throws Error if Git diff operation fails * @example * ```typescript * const changedLines = await GitHelper.getChangedLineRanges('/path/to/repo', 'main', 'feature-branch'); * ``` */ static getChangedLineRanges(repoDir: string, from: string, to: string): Promise<Map<string, Array<{ start: number; end: number; }>>>; /** * Gets the status of files changed between two commits * Returns a map of file paths to their status ('A'=added, 'M'=modified, 'D'=deleted, 'R'=renamed) * * @param repoDir - The path to the Git repository directory * @param from - The source commit/branch reference for diff comparison * @param to - The target commit/branch reference for diff comparison * @returns Promise resolving to a map of file paths to their Git status * @throws Error if Git diff operation fails * @example * ```typescript * const statuses = await GitHelper.getFileStatuses('/path/to/repo', 'main', 'feature-branch'); * console.log(statuses.get('src/file.ts')); // 'M' for modified, 'A' for added, etc. * ``` */ static getFileStatuses(repoDir: string, from: string, to: string): Promise<Map<string, string>>; /** * Finds the git root directory by traversing up the directory tree * * @param startDir - Optional starting directory to search from (defaults to current working directory) * @returns Promise resolving to the absolute path of the Git repository root * @throws Error if no Git repository is found or Git operation fails * @example * ```typescript * const gitRoot = await GitHelper.findGitRoot('/path/to/subdirectory'); * console.log(gitRoot); // '/path/to/repo' * ``` */ static findGitRoot(startDir?: string): Promise<string>; }