git-release-manager
Version:
A tool to generate release notes from git commit history
75 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.summarizeCommits = summarizeCommits;
exports.summarizeNotes = summarizeNotes;
exports.summarizeContributors = summarizeContributors;
function summarizeCommits(commits, config) {
if (!Array.isArray(commits)) {
throw new Error('Invalid input: commits must be an array');
}
const result = [];
const summary = commits.reduce((acc, commit) => {
const type = commit.type;
if (!acc[type]) {
const matchingType = config.commitTypes.find(ct => ct.type === type);
const typeTitle = matchingType ? matchingType.title : 'Other Changes';
const order = (matchingType === null || matchingType === void 0 ? void 0 : matchingType.order) !== undefined ? matchingType.order : Number.MAX_SAFE_INTEGER;
acc[type] = {
type: type,
title: typeTitle,
count: commit.items.length,
order: order,
};
}
return acc;
}, {});
result.push(...Object.values(summary));
result.sort((a, b) => a.order - b.order);
return result;
}
function summarizeNotes(notes, config) {
if (!Array.isArray(notes)) {
throw new Error('Invalid input: notes must be an array');
}
const result = [];
const summary = notes.reduce((acc, note) => {
const type = note.type;
if (!acc[type]) {
const matchingType = config.noteTypes.find(nt => nt.type === type);
const typeTitle = matchingType ? matchingType.title : 'Other Notes';
const order = (matchingType === null || matchingType === void 0 ? void 0 : matchingType.order) !== undefined ? matchingType.order : Number.MAX_SAFE_INTEGER;
acc[type] = {
type: type,
title: typeTitle,
count: note.items.length,
order: order,
};
}
return acc;
}, {});
result.push(...Object.values(summary));
result.sort((a, b) => a.order - b.order);
return result;
}
function summarizeContributors(contributors, config) {
if (!Array.isArray(contributors)) {
throw new Error('Invalid input: contributors must be an array');
}
const result = [];
const summary = contributors.reduce((acc, contributor) => {
var _a, _b;
const type = contributor.email;
if (!acc[type]) {
acc[type] = {
email: contributor.email,
name: contributor.name,
profileUrl: contributor.profileUrl,
count: (_b = (_a = contributor.groups) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
};
}
return acc;
}, {});
result.push(...Object.values(summary));
return result;
}
//# sourceMappingURL=summarizing.js.map