Skip to content

Commit

Permalink
Add feature to set limit in options for tags. Fixes #144 (#148)
Browse files Browse the repository at this point in the history
* Add feature to set limit in options for tags. Fixes #144

* Add limit to options file

* Revert quotes

* Add an eslint ignore for camelcase, since the properties from github is not camelcased
  • Loading branch information
Alexander Vassbotn Røyne-Helgesen authored and alexcanessa committed Apr 19, 2018
1 parent 8fba52f commit 9ff8e2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
45 changes: 33 additions & 12 deletions lib/_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
{
short: '-G',
name: 'generate',
description: 'Generate the changelog with gren rather then using the repo releases'
description:
'Generate the changelog with gren rather then using the repo releases'
},
{
short: '-f',
Expand All @@ -22,7 +23,9 @@ module.exports = {
{
short: false,
name: false,
description: `\n\n${chalk.yellow('Release options')} \n${chalk.blue('(only applicable with the --generate option).')}\n\n`
description: `\n\n${chalk.yellow('Release options')} \n${chalk.blue(
'(only applicable with the --generate option).'
)}\n\n`
}
],
globalOptions: [
Expand All @@ -48,7 +51,8 @@ module.exports = {
short: '-a',
name: 'api-url',
valueType: '<url>',
description: 'Override the GitHub API URL, allows gren to connect to a private GHE installation'
description:
'Override the GitHub API URL, allows gren to connect to a private GHE installation'
},
{
short: '-o',
Expand All @@ -64,37 +68,49 @@ module.exports = {
short: '-t',
name: 'tags',
valueType: '<new-tag>..<old-tag>',
description: 'Write release notes for <new-tag> using data collected until <old-tag>. If only one tag is specified, will use data until the previous tag. To run gren for all the tags, use --tags=all',
description:
'Write release notes for <new-tag> using data collected until <old-tag>. If only one tag is specified, will use data until the previous tag. To run gren for all the tags, use --tags=all',
action: value => value.split('..')
},
{
short: '-l',
name: 'limit',
valueType: '<number>',
description:
'Just produce release notes for the <number> last releases.'
},
{
short: '-D',
name: 'data-source',
valueType: '<issues|commits|milestones|prs>',
description: 'The informations you want to use to build release notes. [issues]',
description:
'The informations you want to use to build release notes. [issues]',
action: /^(issues|commits|milestones|prs)$/i,
defaultValue: 'issues'
},
{
short: '-N',
name: 'include-messages',
valueType: '<merge|commits|all>',
description: 'Filter the messages added to the release notes. Only used when --data-source used is commits [commits]',
description:
'Filter the messages added to the release notes. Only used when --data-source used is commits [commits]',
action: /^(merge|commits|all)$/i,
defaultValue: 'commits'
},
{
short: '-i',
name: 'ignore-tags-with',
valueType: '<string1>,<string2>',
description: 'Ignore tags that contain one of the specified strings.',
description:
'Ignore tags that contain one of the specified strings.',
action: value => value.split(',')
},
{
short: '-C',
name: 'ignore-commits-with',
valueType: '<string1>,<string2>',
description: 'Ignore commits that contain one of the specified strings.',
description:
'Ignore commits that contain one of the specified strings.',
action: value => value.split(',')
},
{
Expand All @@ -107,7 +123,8 @@ module.exports = {
short: '-g',
name: 'group-by',
valueType: '<label>',
description: 'Group the issues using the labels as group headings. You can set custom headings for groups of labels from a configuration file.'
description:
'Group the issues using the labels as group headings. You can set custom headings for groups of labels from a configuration file.'
},
{
short: '-L',
Expand All @@ -120,20 +137,23 @@ module.exports = {
short: '-I',
name: 'ignore-issues-with',
valueType: '<label1>,<label2>',
description: 'Ignore issues that contains one of the specified labels.',
description:
'Ignore issues that contains one of the specified labels.',
action: value => value.split(',')
},
{
short: '-M',
name: 'milestone-match',
valueType: '<prefix>',
description: 'The title that the script needs to match to link the release to the milestone. e.g. v will match v0.1.0 [Release {{tag_name}}]',
description:
'The title that the script needs to match to link the release to the milestone. e.g. v will match v0.1.0 [Release {{tag_name}}]',
defaultValue: 'Release {{tag_name}}'
},
{
short: '-m',
name: 'only-milestones',
description: 'Add to the release bodies only the issues that have a milestone'
description:
'Add to the release bodies only the issues that have a milestone'
},
{
short: '-q',
Expand All @@ -154,3 +174,4 @@ module.exports = {
}
]
};

11 changes: 10 additions & 1 deletion lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Gren {
token,
apiUrl,
tags,
limit,
ignoreLabels,
ignoreIssuesWith,
ignoreCommitsWith,
Expand All @@ -49,7 +50,14 @@ class Gren {
this.options.ignoreIssuesWith = utils.convertStringToArray(ignoreIssuesWith);
this.options.ignoreCommitsWith = utils.convertStringToArray(ignoreCommitsWith);
this.options.ignoreTagsWith = utils.convertStringToArray(ignoreTagsWith);
this.options.limit = this.options.tags.indexOf('all') >= 0 ? MAX_TAGS_LIMIT : TAGS_LIMIT;

if (limit && limit > 0 && limit <= MAX_TAGS_LIMIT) {
this.options.limit = limit;
} else if (this.options.tags.indexOf('all') >= 0) {
this.options.limit = MAX_TAGS_LIMIT;
} else {
this.options.limit = TAGS_LIMIT;
}

if (!token) {
throw chalk.red('You must provide the TOKEN');
Expand Down Expand Up @@ -452,6 +460,7 @@ class Gren {
*
* @return {string}
*/
// eslint-disable-next-line camelcase
_templateCommits({ sha, html_url, commit: { author: { name }, message } }) {
return generate({
sha,
Expand Down

0 comments on commit 9ff8e2a

Please sign in to comment.