Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
feat(context): expose finalizeContext to modify context at last
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Aug 3, 2015
1 parent 37337b2 commit 4d43f5c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@ When the upstream finishes pouring the commits it will generate a block of logs

If this value is a `string`, it checks the existence of the field. Set to other type to disable it.

##### finalizeContext

Type: `function` Default: pass through

###### finalizeContext(context, options, commits, keyCommit)

####### context

The generated context based on original input `context` and `options`.

####### options

Normalized options.

####### commits

Filtered commits from your git metadata.

####### keyCommit

The commit that triggers to generate the log.

##### reverse

Type: `boolean` Default: `false`
Expand Down Expand Up @@ -251,7 +273,7 @@ Variables in upstream are commit specific and should be used per commit. Eg: *co

context should be module specific and can be used across the whole log. Thus these variables should not be related to any single commit and should be generic information of the module or all commits. Eg: *repository url* and *author names*, etc. You can think of them as "global" or "root" variables.

Basically you can make your own templates and define all your template variables. This module can iterate the commits and compile them. For more details, please checkout [handlebars](http://handlebarsjs.com) and the source code of this module.
Basically you can make your own templates and define all your template context. Extra context are based on commits from upstream and `options`. For more details, please checkout [handlebars](http://handlebarsjs.com) and the source code of this module.


## CLI
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function conventionalChangelogWriter(context, options) {
generateOn: function(commit) {
return semverValid(commit.version);
},
finalizeContext: function(context) {
return context;
},
reverse: false,
includeDetails: false,
ignoreReverted: true,
Expand Down
2 changes: 2 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ function generate(options, commits, context, keyCommit) {
context.isPatch = context.isPatch || semver.patch(context.version) !== 0;
}

context = options.finalizeContext(context, options, commits, keyCommit);

return compiled(context);
}

Expand Down
29 changes: 26 additions & 3 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ describe('util', function() {
describe('generate', function() {
it('should merge with the key commit', function() {
var log = util.generate({
mainTemplate: '{{whatever}}'
mainTemplate: '{{whatever}}',
finalizeContext: function(context) {
return context;
}
}, [], {
whatever: 'a'
}, {
Expand All @@ -557,7 +560,10 @@ describe('util', function() {

it('should not html escape any content', function() {
var log = util.generate({
mainTemplate: '{{whatever}}'
mainTemplate: '{{whatever}}',
finalizeContext: function(context) {
return context;
}
}, [], [], {
whatever: '`a`'
});
Expand All @@ -568,7 +574,10 @@ describe('util', function() {
it('should ignore a reverted commit', function() {
var log = util.generate({
mainTemplate: '{{#each commitGroups}}{{commits.length}}{{#each commits}}{{header}}{{/each}}{{/each}}{{#each noteGroups}}{{title}}{{#each notes}}{{this}}{{/each}}{{/each}}',
ignoreReverted: true
ignoreReverted: true,
finalizeContext: function(context) {
return context;
}
}, [{
header: 'revert: feat(): amazing new module\n',
body: 'This reverts commit 56185b7356766d2b30cfa2406b257080272e0b7a.\n',
Expand Down Expand Up @@ -631,5 +640,19 @@ describe('util', function() {
expect(log).to.not.include('revert');
expect(log).to.not.include('breaking change');
});

it('should finalize context', function() {
var log = util.generate({
mainTemplate: '{{whatever}} {{somethingExtra}}',
finalizeContext: function(context) {
context.somethingExtra = 'oh';
return context;
}
}, [], [], {
whatever: '`a`'
});

expect(log).to.equal('`a` oh');
});
});
});

0 comments on commit 4d43f5c

Please sign in to comment.