@nerdo/code-reviewer
Version:
A web-based visual git diff tool for reviewing code changes between commits, branches, and tags
46 lines (45 loc) • 1.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitCommitRepository = void 0;
const simple_git_1 = __importDefault(require("simple-git"));
class GitCommitRepository {
getGit(repoPath) {
return (0, simple_git_1.default)(repoPath);
}
async getCommit(repoPath, hash) {
const git = this.getGit(repoPath);
const log = await git.log([hash, '-1']);
if (log.all.length === 0) {
throw new Error(`Commit ${hash} not found`);
}
return this.mapLogToCommit(log.all[0]);
}
async getCommits(repoPath, branch, limit = 100) {
const git = this.getGit(repoPath);
const options = [`-${limit}`];
if (branch) {
options.push(branch);
}
const log = await git.log(options);
return log.all.map(entry => this.mapLogToCommit(entry));
}
async getCommitsBetween(repoPath, fromHash, toHash) {
const git = this.getGit(repoPath);
const log = await git.log([`${fromHash}..${toHash}`]);
return log.all.map(entry => this.mapLogToCommit(entry));
}
mapLogToCommit(logEntry) {
return {
hash: logEntry.hash,
message: logEntry.message,
author: logEntry.author_name,
authorEmail: logEntry.author_email,
date: new Date(logEntry.date),
parentHashes: [] // For simplicity, we'll omit parent hashes for now
};
}
}
exports.GitCommitRepository = GitCommitRepository;