git-release-manager
Version:
A tool to generate release notes from git commit history
54 lines • 1.96 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBranches = getBranches;
exports.isGitBranch = isGitBranch;
const simple_git_1 = __importDefault(require("simple-git"));
const cmd_1 = require("../../../utils/cmd");
const git = (0, simple_git_1.default)();
async function getBranches(range) {
try {
const logCommand = `git log --oneline --decorate=short ${range}`;
const { stdout } = await (0, cmd_1.execWithErrorHandling)(logCommand);
// Extract branches
const branchRegex = /([a-f0-9]+)\s.*\(.*?([^,\s)]+)\)/g;
const branchesWithRefs = [];
let match;
while ((match = branchRegex.exec(stdout.trim())) !== null) {
if (!match[2].startsWith('tag:')) {
// Ensures it's a branch
branchesWithRefs.push({ name: match[2], reference: match[1] });
}
}
// Use a Set to filter unique branches by name
const uniqueBranchesMap = new Map();
branchesWithRefs.forEach(branch => {
if (!uniqueBranchesMap.has(branch.name)) {
uniqueBranchesMap.set(branch.name, branch);
}
});
return Array.from(uniqueBranchesMap.values());
}
catch (error) {
console.error('Error retrieving branches in range:', error);
throw error;
}
}
/**
* Checks if the given value is a local Git branch.
*
* @param value - The name of the branch to check.
* @returns A promise that resolves to `true` if the value is a local Git branch, otherwise `false`.
*/
async function isGitBranch(value) {
try {
const branches = await git.branchLocal();
return branches.all.includes(value);
}
catch (_a) {
return false;
}
}
//# sourceMappingURL=branchUtils.js.map