Skip to content

Commit 9ff8e2a

Browse files
Alexander Vassbotn Røyne-Helgesenalexcanessa
authored andcommitted
Add feature to set limit in options for tags. Fixes #144 (#148)
* 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
1 parent 8fba52f commit 9ff8e2a

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

lib/_options.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = {
1010
{
1111
short: '-G',
1212
name: 'generate',
13-
description: 'Generate the changelog with gren rather then using the repo releases'
13+
description:
14+
'Generate the changelog with gren rather then using the repo releases'
1415
},
1516
{
1617
short: '-f',
@@ -22,7 +23,9 @@ module.exports = {
2223
{
2324
short: false,
2425
name: false,
25-
description: `\n\n${chalk.yellow('Release options')} \n${chalk.blue('(only applicable with the --generate option).')}\n\n`
26+
description: `\n\n${chalk.yellow('Release options')} \n${chalk.blue(
27+
'(only applicable with the --generate option).'
28+
)}\n\n`
2629
}
2730
],
2831
globalOptions: [
@@ -48,7 +51,8 @@ module.exports = {
4851
short: '-a',
4952
name: 'api-url',
5053
valueType: '<url>',
51-
description: 'Override the GitHub API URL, allows gren to connect to a private GHE installation'
54+
description:
55+
'Override the GitHub API URL, allows gren to connect to a private GHE installation'
5256
},
5357
{
5458
short: '-o',
@@ -64,37 +68,49 @@ module.exports = {
6468
short: '-t',
6569
name: 'tags',
6670
valueType: '<new-tag>..<old-tag>',
67-
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',
71+
description:
72+
'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',
6873
action: value => value.split('..')
6974
},
75+
{
76+
short: '-l',
77+
name: 'limit',
78+
valueType: '<number>',
79+
description:
80+
'Just produce release notes for the <number> last releases.'
81+
},
7082
{
7183
short: '-D',
7284
name: 'data-source',
7385
valueType: '<issues|commits|milestones|prs>',
74-
description: 'The informations you want to use to build release notes. [issues]',
86+
description:
87+
'The informations you want to use to build release notes. [issues]',
7588
action: /^(issues|commits|milestones|prs)$/i,
7689
defaultValue: 'issues'
7790
},
7891
{
7992
short: '-N',
8093
name: 'include-messages',
8194
valueType: '<merge|commits|all>',
82-
description: 'Filter the messages added to the release notes. Only used when --data-source used is commits [commits]',
95+
description:
96+
'Filter the messages added to the release notes. Only used when --data-source used is commits [commits]',
8397
action: /^(merge|commits|all)$/i,
8498
defaultValue: 'commits'
8599
},
86100
{
87101
short: '-i',
88102
name: 'ignore-tags-with',
89103
valueType: '<string1>,<string2>',
90-
description: 'Ignore tags that contain one of the specified strings.',
104+
description:
105+
'Ignore tags that contain one of the specified strings.',
91106
action: value => value.split(',')
92107
},
93108
{
94109
short: '-C',
95110
name: 'ignore-commits-with',
96111
valueType: '<string1>,<string2>',
97-
description: 'Ignore commits that contain one of the specified strings.',
112+
description:
113+
'Ignore commits that contain one of the specified strings.',
98114
action: value => value.split(',')
99115
},
100116
{
@@ -107,7 +123,8 @@ module.exports = {
107123
short: '-g',
108124
name: 'group-by',
109125
valueType: '<label>',
110-
description: 'Group the issues using the labels as group headings. You can set custom headings for groups of labels from a configuration file.'
126+
description:
127+
'Group the issues using the labels as group headings. You can set custom headings for groups of labels from a configuration file.'
111128
},
112129
{
113130
short: '-L',
@@ -120,20 +137,23 @@ module.exports = {
120137
short: '-I',
121138
name: 'ignore-issues-with',
122139
valueType: '<label1>,<label2>',
123-
description: 'Ignore issues that contains one of the specified labels.',
140+
description:
141+
'Ignore issues that contains one of the specified labels.',
124142
action: value => value.split(',')
125143
},
126144
{
127145
short: '-M',
128146
name: 'milestone-match',
129147
valueType: '<prefix>',
130-
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}}]',
148+
description:
149+
'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}}]',
131150
defaultValue: 'Release {{tag_name}}'
132151
},
133152
{
134153
short: '-m',
135154
name: 'only-milestones',
136-
description: 'Add to the release bodies only the issues that have a milestone'
155+
description:
156+
'Add to the release bodies only the issues that have a milestone'
137157
},
138158
{
139159
short: '-q',
@@ -154,3 +174,4 @@ module.exports = {
154174
}
155175
]
156176
};
177+

lib/src/Gren.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Gren {
3838
token,
3939
apiUrl,
4040
tags,
41+
limit,
4142
ignoreLabels,
4243
ignoreIssuesWith,
4344
ignoreCommitsWith,
@@ -49,7 +50,14 @@ class Gren {
4950
this.options.ignoreIssuesWith = utils.convertStringToArray(ignoreIssuesWith);
5051
this.options.ignoreCommitsWith = utils.convertStringToArray(ignoreCommitsWith);
5152
this.options.ignoreTagsWith = utils.convertStringToArray(ignoreTagsWith);
52-
this.options.limit = this.options.tags.indexOf('all') >= 0 ? MAX_TAGS_LIMIT : TAGS_LIMIT;
53+
54+
if (limit && limit > 0 && limit <= MAX_TAGS_LIMIT) {
55+
this.options.limit = limit;
56+
} else if (this.options.tags.indexOf('all') >= 0) {
57+
this.options.limit = MAX_TAGS_LIMIT;
58+
} else {
59+
this.options.limit = TAGS_LIMIT;
60+
}
5361

5462
if (!token) {
5563
throw chalk.red('You must provide the TOKEN');
@@ -452,6 +460,7 @@ class Gren {
452460
*
453461
* @return {string}
454462
*/
463+
// eslint-disable-next-line camelcase
455464
_templateCommits({ sha, html_url, commit: { author: { name }, message } }) {
456465
return generate({
457466
sha,

0 commit comments

Comments
 (0)