UNPKG

git-release-manager

Version:

A tool to generate release notes from git commit history

64 lines 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.groupBy = groupBy; exports.groupByNotes = groupByNotes; function groupBy(commits, key, config) { if (!Array.isArray(commits)) { throw new Error('Invalid input: commits must be an array'); } const result = []; const grouped = commits.reduce((acc, commit) => { const groupKey = key.split('.').reduce((nested, part) => nested === null || nested === void 0 ? void 0 : nested[part], commit); if (!acc[groupKey]) { const matchingType = config.commitTypes.find(ct => ct.terms.includes(groupKey)); 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[groupKey] = { type: matchingType ? matchingType.type : 'other', title: typeTitle, order: order, items: [], }; } acc[groupKey].items.push(commit); return acc; }, {}); result.push(...Object.values(grouped)); result.sort((a, b) => { var _a, _b; return ((_a = a.order) !== null && _a !== void 0 ? _a : 0) - ((_b = b.order) !== null && _b !== void 0 ? _b : 0); }); return result; } function groupByNotes(array, config, includeUnmatched = true) { if (!Array.isArray(array)) { throw new Error('Invalid input: array must be an array'); } const result = []; const grouped = array.reduce((acc, item) => { if (!item.notes || item.notes.length === 0) return acc; item.notes.forEach(note => { const groupKey = note.type; const matchingType = config.noteTypes.find(nt => nt.type === groupKey); if (!matchingType && !includeUnmatched) return; if (!acc[groupKey]) { const typeTitle = matchingType ? matchingType.title : groupKey; const order = (matchingType === null || matchingType === void 0 ? void 0 : matchingType.order) !== undefined ? matchingType.order : Number.MAX_SAFE_INTEGER; acc[groupKey] = { type: groupKey, title: typeTitle, order: order, items: [], }; } acc[groupKey].items.push({ note, commit: item, }); }); return acc; }, {}); result.push(...Object.values(grouped)); result.sort((a, b) => { var _a, _b; return ((_a = a.order) !== null && _a !== void 0 ? _a : 0) - ((_b = b.order) !== null && _b !== void 0 ? _b : 0); }); return result; } //# sourceMappingURL=grouping.js.map