Skip to content

Commit

Permalink
Add group post processor (github-tools#286)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yogevbd authored Dec 17, 2020
1 parent 6734707 commit 458289f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,16 @@ class Gren {
* @return {string}
*/
_templateGroups(groups) {
const { groupPostProcessor } = this.options;

return Object.entries(groups).map(([key, value]) => {
const heading = generate({
heading: key
}, this.options.template.group);
const body = value.join('\n');
const content = heading + '\n' + body;

return heading + '\n' + body;
return groupPostProcessor ? groupPostProcessor(content) : content;
});
}

Expand Down
16 changes: 16 additions & 0 deletions test/Gren.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ describe('Gren', () => {
};
assert.deepEqual(gren._groupBy(normal), [`All\n${normal[0].title}`], 'The issue does not match any labels, and goes in the ... group');
});

it('Should format group using post formatter', () => {
const { normal, noLabel } = issues;

gren.options.groupBy = {
'Test:': ['enhancement'],
'Others:': ['closed']
};

gren.options.groupPostProcessor = (groupContent) => {
return groupContent.replace(0, groupContent.indexOf(':\n') + 3);
}

assert.deepEqual(gren._groupBy(normal), [`Test:`], 'Passing one heading for one issue');
assert.deepEqual(gren._groupBy(noLabel), [`Others:`], 'Group option is "label" with no labels');
});
});

describe('_filterIssue', () => {
Expand Down

0 comments on commit 458289f

Please sign in to comment.