Skip to content

Commit 458289f

Browse files
authored
Add group post processor (#286)
* Add post group formatter * Push dist and bin * Rename postGroupFormatter to groupPostProcessor * Revert "Push dist and bin" This reverts commit 02d5b21. * f * f * remove clg
1 parent 6734707 commit 458289f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/src/Gren.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,16 @@ class Gren {
606606
* @return {string}
607607
*/
608608
_templateGroups(groups) {
609+
const { groupPostProcessor } = this.options;
610+
609611
return Object.entries(groups).map(([key, value]) => {
610612
const heading = generate({
611613
heading: key
612614
}, this.options.template.group);
613615
const body = value.join('\n');
616+
const content = heading + '\n' + body;
614617

615-
return heading + '\n' + body;
618+
return groupPostProcessor ? groupPostProcessor(content) : content;
616619
});
617620
}
618621

test/Gren.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ describe('Gren', () => {
211211
};
212212
assert.deepEqual(gren._groupBy(normal), [`All\n${normal[0].title}`], 'The issue does not match any labels, and goes in the ... group');
213213
});
214+
215+
it('Should format group using post formatter', () => {
216+
const { normal, noLabel } = issues;
217+
218+
gren.options.groupBy = {
219+
'Test:': ['enhancement'],
220+
'Others:': ['closed']
221+
};
222+
223+
gren.options.groupPostProcessor = (groupContent) => {
224+
return groupContent.replace(0, groupContent.indexOf(':\n') + 3);
225+
}
226+
227+
assert.deepEqual(gren._groupBy(normal), [`Test:`], 'Passing one heading for one issue');
228+
assert.deepEqual(gren._groupBy(noLabel), [`Others:`], 'Group option is "label" with no labels');
229+
});
214230
});
215231

216232
describe('_filterIssue', () => {

0 commit comments

Comments
 (0)