@nerdo/code-reviewer
Version:
A web-based visual git diff tool for reviewing code changes between commits, branches, and tags
47 lines (46 loc) • 1.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitRepositoryRepository = void 0;
const simple_git_1 = __importDefault(require("simple-git"));
const path_1 = __importDefault(require("path"));
class GitRepositoryRepository {
getGit(repoPath) {
return (0, simple_git_1.default)(repoPath);
}
async getRepository(repoPath) {
const git = this.getGit(repoPath);
const [branches, currentBranch, tags, remotes] = await Promise.all([
this.getBranches(repoPath),
this.getCurrentBranch(repoPath),
this.getTags(repoPath),
git.getRemotes()
]);
return {
path: repoPath,
name: path_1.default.basename(repoPath),
currentBranch,
branches,
tags,
remotes: remotes.map(r => r.name)
};
}
async getBranches(repoPath) {
const git = this.getGit(repoPath);
const branchSummary = await git.branchLocal();
return branchSummary.all;
}
async getCurrentBranch(repoPath) {
const git = this.getGit(repoPath);
const branchSummary = await git.branchLocal();
return branchSummary.current;
}
async getTags(repoPath) {
const git = this.getGit(repoPath);
const tags = await git.tags();
return tags.all;
}
}
exports.GitRepositoryRepository = GitRepositoryRepository;