Skip to content

Commit

Permalink
Add option to get commits since last tag; don't skip any commits
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth committed Aug 26, 2022
1 parent 59f222a commit 73ba41a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
5 changes: 5 additions & 0 deletions docs/_data/global-options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
valueType: '<issues|commits|milestones|prs|prs-with-issues>'
description: 'The informations you want to use to build release notes. [issues]'
defaultValue: issues
-
short: '-h'
name: head
valueType: '<string>'
description: 'Which branch would you like to include commits from after the last tag?'
-
short: '-N'
name: include-messages
Expand Down
6 changes: 6 additions & 0 deletions lib/_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ module.exports = {
action: /^(issues|commits|milestones|prs|prs-with-issues)$/i,
defaultValue: 'issues'
},
{
short: '-h',
name: 'head',
valueType: '<string>',
description: 'Which branch would you like to include commits from after the last tag?'
},
{
short: '-N',
name: 'include-messages',
Expand Down
27 changes: 18 additions & 9 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,10 @@ class Gren {
*
* @return {string}
*/
_generateCommitsBody(commits = [], addEmptyCommit) {
_generateCommitsBody(commits = []) {
const bodyMessages = Array.from(commits);

if (bodyMessages.length === 1 || addEmptyCommit) {
bodyMessages.push(null);
}

return bodyMessages
.slice(0, -1)
.filter(this._filterCommit.bind(this))
.map(this._templateCommits.bind(this))
.join('\n');
Expand All @@ -676,7 +671,7 @@ class Gren {
name: this.options.prefix + range[0].name,
release: range[0].name,
published_at: range[0].date,
body: this._generateCommitsBody(range[2], range[1].id === 0) + '\n'
body: this._generateCommitsBody(range[2]) + '\n'
}));

loaded(`Commit ranges loaded: ${ranges.length}`);
Expand Down Expand Up @@ -1047,7 +1042,7 @@ class Gren {
if (sortedReleaseDates.length === 1 || this.options.tags.indexOf('all') >= 0) {
sortedReleaseDates.push({
id: 0,
date: new Date(0)
date: (new Date(0)).toISOString()
});
}

Expand All @@ -1062,6 +1057,20 @@ class Gren {
]);
}

if (this.options.head != null) {
const latest = [{
...sortedReleaseDates[0],
name: this.options.head,
date: (new Date()).toISOString()
},
{
...sortedReleaseDates[0]
}
];

ranges.unshift(latest);
}

return ranges;
}

Expand Down Expand Up @@ -1101,7 +1110,7 @@ class Gren {
if (releaseRange[1].name != null) {
({ data: { commits } } = await this.repo.compareBranches(releaseRange[1].name, releaseRange[0].name));
} else {
({ data: commits } = await this.repo.listCommits({ until: releaseRange[1].date }));
({ data: commits } = await this.repo.listCommits({ since: releaseRange[1].date, until: releaseRange[0].date }));
}
releaseRange.push(commits);
}
Expand Down

0 comments on commit 73ba41a

Please sign in to comment.