Skip to content

Commit 30f6194

Browse files
committed
Add pull requests as data source
1 parent 295194d commit 30f6194

File tree

4 files changed

+151
-24
lines changed

4 files changed

+151
-24
lines changed

lib/_options.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ module.exports = {
6565
{
6666
short: '-D',
6767
name: 'data-source',
68-
valueType: '<issues|commits|milestones>',
68+
valueType: '<issues|commits|milestones|prs>',
6969
description: 'The informations you want to use to build release notes. [issues]',
70-
action: /^(issues|commits|milestones)$/i,
70+
action: /^(issues|commits|milestones|prs)$/i,
7171
defaultValue: 'issues'
7272
},
7373
{
@@ -95,8 +95,7 @@ module.exports = {
9595
short: '-g',
9696
name: 'group-by',
9797
valueType: '<label>',
98-
description: 'Group the issues using the labels as group headings. You can set custom headings for groups of labels from a configuration file.',
99-
action: /^(label)$/i
98+
description: 'Group the issues using the labels as group headings. You can set custom headings for groups of labels from a configuration file.'
10099
},
101100
{
102101
short: '-L',

lib/src/Gren.js

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ class Gren {
736736
const { groupBy } = this.options;
737737
const issues = Object.values(ObjectAssign({}, passedIssues));
738738

739-
if (!groupBy) {
739+
if (!groupBy || groupBy === 'false') {
740740
return issues.map(this._templateIssue.bind(this));
741741
}
742742

@@ -784,8 +784,10 @@ class Gren {
784784
* @return {Boolean}
785785
*/
786786
_filterIssue(issue) {
787-
return !issue.pull_request && !this._lablesAreIgnored(issue.labels) &&
788-
!((this.options.onlyMilestones || this.options.dataSource === 'milestones') && !issue.milestone);
787+
const { dataSource } = this.options;
788+
789+
return (issue.pull_request ? dataSource === 'prs' : dataSource === 'issues' | dataSource === 'milestones') && !this._lablesAreIgnored(issue.labels) &&
790+
!((this.options.onlyMilestones || dataSource === 'milestones') && !issue.milestone);
789791
}
790792

791793
/**
@@ -826,23 +828,35 @@ class Gren {
826828
console.log('Creating the body blocks from releases:');
827829

828830
return this._getClosedIssues(releaseRanges)
829-
.then(issues => releaseRanges
830-
.map(range => {
831-
const filteredIssues = Array.from(issues)
832-
.filter(this._filterIssue.bind(this))
833-
.filter(this._filterBlockIssue.bind(this, range));
834-
const body = (!range[0].body || this.options.override) && this._groupBy(filteredIssues);
831+
.then(issues => {
832+
let totalIssues = 0;
833+
const type = {
834+
'issues': 'issues',
835+
'prs': 'pull requests',
836+
'milestones': 'issues'
837+
}[this.options.dataSource];
838+
const release = releaseRanges
839+
.map(range => {
840+
const filteredIssues = Array.from(issues)
841+
.filter(this._filterIssue.bind(this))
842+
.filter(this._filterBlockIssue.bind(this, range));
843+
const body = (!range[0].body || this.options.override) && this._groupBy(filteredIssues);
844+
845+
totalIssues += filteredIssues.length;
835846

836-
process.stdout.write(`${this.options.prefix + range[0].name} has ${filteredIssues.length} issues found\t`);
847+
return {
848+
id: range[0].id,
849+
release: range[0].name,
850+
name: this.options.prefix + range[0].name,
851+
published_at: range[0].date,
852+
body: this._templateIssueBody(body, range[0].body)
853+
};
854+
});
837855

838-
return {
839-
id: range[0].id,
840-
release: range[0].name,
841-
name: this.options.prefix + range[0].name,
842-
published_at: range[0].date,
843-
body: this._templateIssueBody(body, range[0].body)
844-
};
845-
}));
856+
process.stdout.write(`${totalIssues} ${type} found.\n`);
857+
858+
return release;
859+
});
846860
}
847861

848862
/**
@@ -899,7 +913,8 @@ class Gren {
899913
const dataSource = {
900914
issues: this._getIssueBlocks.bind(this),
901915
commits: this._getCommitBlocks.bind(this),
902-
milestones: this._getIssueBlocks.bind(this)
916+
milestones: this._getIssueBlocks.bind(this),
917+
prs: this._getIssueBlocks.bind(this)
903918
};
904919

905920
return this._getListReleases()

test/Gren.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ describe('Gren', () => {
123123
issues = {
124124
normal: issueFile.filter(({ id }) => id === 234567890),
125125
noMilestone: issueFile.filter(({ id }) => id === 234567891),
126-
noLabel: issueFile.filter(({ id }) => id === 234567891)
126+
noLabel: issueFile.filter(({ id }) => id === 234567891),
127+
pullRequests: issueFile.filter(({ pull_request }) => pull_request)
127128
};
128129
});
129130

@@ -222,6 +223,14 @@ describe('Gren', () => {
222223
gren.options.onlyMilestones = false;
223224
gren.options.dataSource = 'milestones';
224225
assert.isNotOk(gren._filterIssue(noMilestone[0]), 'Issue without milestone, with dataSource as milestone');
226+
227+
gren.options.dataSource = 'prs';
228+
assert.isNotOk(gren._filterIssue(normal[0]), 'Issue are not included, with dataSource as prs');
229+
});
230+
231+
it('Should include pull requests', () => {
232+
gren.options.dataSource = 'prs';
233+
assert.isOk(gren._filterIssue(issues.pullRequests[0]), 'Pull Requests are included, with dataSource as prs');
225234
});
226235
});
227236

test/data/issues.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,109 @@
129129
"author_association": "OWNER",
130130
"body": "Use `nyc` `babel` and `istanbul`",
131131
"closed_by": null
132+
},
133+
{
134+
"url":"https://api.github.com/repos/github-tools/github-release-notes/issues/101",
135+
"repository_url":"https://api.github.com/repos/github-tools/github-release-notes",
136+
"labels_url":"https://api.github.com/repos/github-tools/github-release-notes/issues/101/labels{/name}",
137+
"comments_url":"https://api.github.com/repos/github-tools/github-release-notes/issues/101/comments",
138+
"events_url":"https://api.github.com/repos/github-tools/github-release-notes/issues/101/events",
139+
"html_url":"https://github.com/github-tools/github-release-notes/pull/101",
140+
"id":265524462,
141+
"number":101,
142+
"title":"Add babel-plugin-transform-runtime",
143+
"user":{
144+
"login":"alexcanessa",
145+
"id":1176495,
146+
"avatar_url":"https://avatars0.githubusercontent.com/u/1176495?v=4",
147+
"gravatar_id":"",
148+
"url":"https://api.github.com/users/alexcanessa",
149+
"html_url":"https://github.com/alexcanessa",
150+
"followers_url":"https://api.github.com/users/alexcanessa/followers",
151+
"following_url":"https://api.github.com/users/alexcanessa/following{/other_user}",
152+
"gists_url":"https://api.github.com/users/alexcanessa/gists{/gist_id}",
153+
"starred_url":"https://api.github.com/users/alexcanessa/starred{/owner}{/repo}",
154+
"subscriptions_url":"https://api.github.com/users/alexcanessa/subscriptions",
155+
"organizations_url":"https://api.github.com/users/alexcanessa/orgs",
156+
"repos_url":"https://api.github.com/users/alexcanessa/repos",
157+
"events_url":"https://api.github.com/users/alexcanessa/events{/privacy}",
158+
"received_events_url":"https://api.github.com/users/alexcanessa/received_events",
159+
"type":"User",
160+
"site_admin":false
161+
},
162+
"labels":[
163+
164+
],
165+
"state":"closed",
166+
"locked":false,
167+
"assignee":null,
168+
"assignees":[
169+
170+
],
171+
"milestone":null,
172+
"comments":1,
173+
"created_at":"2017-10-14T21:16:13Z",
174+
"updated_at":"2017-10-14T21:18:37Z",
175+
"closed_at":"2017-10-14T21:18:27Z",
176+
"author_association":"OWNER",
177+
"pull_request":{
178+
"url":"https://api.github.com/repos/github-tools/github-release-notes/pulls/101",
179+
"html_url":"https://github.com/github-tools/github-release-notes/pull/101",
180+
"diff_url":"https://github.com/github-tools/github-release-notes/pull/101.diff",
181+
"patch_url":"https://github.com/github-tools/github-release-notes/pull/101.patch"
182+
},
183+
"body":"Fixes #99 "
184+
},
185+
{
186+
"url":"https://api.github.com/repos/github-tools/github-release-notes/issues/100",
187+
"repository_url":"https://api.github.com/repos/github-tools/github-release-notes",
188+
"labels_url":"https://api.github.com/repos/github-tools/github-release-notes/issues/100/labels{/name}",
189+
"comments_url":"https://api.github.com/repos/github-tools/github-release-notes/issues/100/comments",
190+
"events_url":"https://api.github.com/repos/github-tools/github-release-notes/issues/100/events",
191+
"html_url":"https://github.com/github-tools/github-release-notes/pull/100",
192+
"id":265522515,
193+
"number":100,
194+
"title":"Remove the limit option and add the logic to tags all and pagination",
195+
"user":{
196+
"login":"alexcanessa",
197+
"id":1176495,
198+
"avatar_url":"https://avatars0.githubusercontent.com/u/1176495?v=4",
199+
"gravatar_id":"",
200+
"url":"https://api.github.com/users/alexcanessa",
201+
"html_url":"https://github.com/alexcanessa",
202+
"followers_url":"https://api.github.com/users/alexcanessa/followers",
203+
"following_url":"https://api.github.com/users/alexcanessa/following{/other_user}",
204+
"gists_url":"https://api.github.com/users/alexcanessa/gists{/gist_id}",
205+
"starred_url":"https://api.github.com/users/alexcanessa/starred{/owner}{/repo}",
206+
"subscriptions_url":"https://api.github.com/users/alexcanessa/subscriptions",
207+
"organizations_url":"https://api.github.com/users/alexcanessa/orgs",
208+
"repos_url":"https://api.github.com/users/alexcanessa/repos",
209+
"events_url":"https://api.github.com/users/alexcanessa/events{/privacy}",
210+
"received_events_url":"https://api.github.com/users/alexcanessa/received_events",
211+
"type":"User",
212+
"site_admin":false
213+
},
214+
"labels":[
215+
216+
],
217+
"state":"closed",
218+
"locked":false,
219+
"assignee":null,
220+
"assignees":[
221+
222+
],
223+
"milestone":null,
224+
"comments":1,
225+
"created_at":"2017-10-14T20:47:40Z",
226+
"updated_at":"2017-10-14T20:51:52Z",
227+
"closed_at":"2017-10-14T20:51:31Z",
228+
"author_association":"OWNER",
229+
"pull_request":{
230+
"url":"https://api.github.com/repos/github-tools/github-release-notes/pulls/100",
231+
"html_url":"https://github.com/github-tools/github-release-notes/pull/100",
232+
"diff_url":"https://github.com/github-tools/github-release-notes/pull/100.diff",
233+
"patch_url":"https://github.com/github-tools/github-release-notes/pull/100.patch"
234+
},
235+
"body":"If the option `tags` is `all` the purpose is to get all the tags in the repo, therefore the option `limit` is not necessary.\r\n\r\nResolves #95"
132236
}
133237
]

0 commit comments

Comments
 (0)