Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa5216b

Browse files
committed
Remove the limit option and add the logic to tags all and pagination
1 parent4aedacd commitaa5216b

File tree

4 files changed

+91
-43
lines changed

4 files changed

+91
-43
lines changed

‎lib/_examples.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ module.exports = {
7070
},
7171
{
7272
name:'Create release notes for a specific tag',
73-
description:'Getthe commits or issues closedbetween the specified tag and the one before.',
73+
description:'Create release notes fromthe commits or issues closedfor the specified tag and the one before.',
7474
code:'gren release --tags=4.0.0'
7575
},
7676
{
77-
description:'Get the commits or the issues between two specified tags.',
77+
description:'Create release notes from the commits or the issues between two specified tags.',
7878
code:'gren release --tags=4.0.0..3.0.0'
7979
},
8080
{
8181
name:'Create release notes for all the tags',
82-
description:'Get the commits or issues closed betweenthespecified tag andtheone before.',
83-
code:'gren release --tags=all --limit=200'
82+
description:'Create release notes for allthetags intherepository.',
83+
code:'gren release --tags=all'
8484
},
8585
{
8686
name:'Work with milestones',

‎lib/_options.js‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,9 @@ module.exports = {
5959
short:'-t',
6060
name:'tags',
6161
valueType:'<new-tag>..<old-tag>',
62-
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=*',
62+
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',
6363
action:value=>value.split('..')
6464
},
65-
{
66-
short:'-l',
67-
name:'limit',
68-
valueType:'<number>',
69-
description:'The limit of tags/releases to get. [30]',
70-
defaultValue:'30'
71-
},
7265
{
7366
short:'-D',
7467
name:'data-source',

‎lib/src/Gren.js‎

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ const defaults = {
1717
ignoreLabels:false,
1818
ignoreIssuesWith:false,
1919
groupBy:false,
20-
limit:30,
2120
milestoneMatch:'Release {{tag_name}}'
2221
};
2322

23+
constMAX_TAGS_LIMIT=99;
24+
constTAGS_LIMIT=30;
25+
2426
/** Class creating release notes and changelog notes */
2527
classGren{
2628
constructor(props={}){
@@ -32,6 +34,7 @@ class Gren {
3234
this.options.tags=utils.convertStringToArray(tags);
3335
this.options.ignoreLabels=utils.convertStringToArray(ignoreLabels);
3436
this.options.ignoreIssuesWith=utils.convertStringToArray(ignoreIssuesWith);
37+
this.options.limit=this.options.tags.indexOf('all')>=0 ?MAX_TAGS_LIMIT :TAGS_LIMIT;
3538

3639
if(!token){
3740
throwchalk.red('You must provide the TOKEN');
@@ -58,7 +61,11 @@ class Gren {
5861

5962
returnthis._hasNetwork()
6063
.then(this._getReleaseBlocks.bind(this))
61-
.then(blocks=>blocks.reduce((carry,block)=>carry.then(this._prepareRelease.bind(this,block)),Promise.resolve()));
64+
.then(blocks=>{
65+
console.log('');
66+
67+
returnblocks.reduce((carry,block)=>carry.then(this._prepareRelease.bind(this,block)),Promise.resolve());
68+
});
6269
}
6370

6471
/**
@@ -278,17 +285,17 @@ class Gren {
278285
*@since 0.1.0
279286
*@private
280287
*
288+
*@param {Array} releases
289+
*@param {number} page
290+
*
281291
*@return {Promise}
282292
*/
283-
_getLastTags(releases){
284-
constloaded=utils.task(this,'Getting tags');
285-
293+
_getLastTags(releases,page=1,limit=this.options.limit){
286294
returnthis._listTags({
287-
per_page:this.options.limit
295+
per_page:limit,
296+
page
288297
})
289-
.then(({data:tags})=>{
290-
loaded();
291-
298+
.then(({headers:{ link},data:tags})=>{
292299
if(!tags.length){
293300
throwchalk.red('Looks like you have no tags! Tag a commit first and then run gren again');
294301
}
@@ -304,8 +311,11 @@ class Gren {
304311
releaseId:releaseId
305312
};
306313
});
314+
consttotalPages=this._getLastPage(link);
307315

308-
console.log('Tags found: '+filteredTags.map(tag=>tag.tag.name).join(', '));
316+
if(this.options.tags.indexOf('all')>=0&&totalPages&&+page<totalPages){
317+
returnthis._getLastTags(releases,page+1).then(moreTags=>moreTags.concat(filteredTags));
318+
}
309319

310320
returnfilteredTags;
311321
});
@@ -323,10 +333,10 @@ class Gren {
323333
*/
324334
_getTagDates(tags){
325335
returntags.map(tag=>this.repo.getCommit(tag.tag.commit.sha)
326-
.then(response=>({
336+
.then(({data:{ committer}})=>({
327337
id:tag.releaseId,
328338
name:tag.tag.name,
329-
date:response.data.committer.date
339+
date:committer.date
330340
})));
331341
}
332342

@@ -342,6 +352,22 @@ class Gren {
342352
returnthis.repo._request('GET',`/repos/${this.repo.__fullname}/releases`,options);
343353
}
344354

355+
/**
356+
* Get the last page from a Hypermedia link
357+
*
358+
*@since 0.11.1
359+
*@private
360+
*
361+
*@param {string} link
362+
*
363+
*@return {boolean|number}
364+
*/
365+
_getLastPage(link){
366+
constlinkMatch=Boolean(link)&&link.match(/page=(\d+)>;rel="last"/);
367+
368+
returnlinkMatch&&+linkMatch[1];
369+
}
370+
345371
/**
346372
* Get all releases
347373
*
@@ -350,15 +376,22 @@ class Gren {
350376
*
351377
*@return {Promise} The promise which resolves an array of releases
352378
*/
353-
_getListReleases(){
379+
_getListReleases(page=1,limit=this.options.limit){
354380
constloaded=utils.task(this,'Getting the list of releases');
355381

356382
returnthis._listReleases({
357-
per_page:this.options.limit
383+
per_page:limit,
384+
page
358385
})
359-
.then(({data:releases})=>{
386+
.then(({headers:{ link},data:releases})=>{
360387
loaded();
361388

389+
consttotalPages=this._getLastPage(link);
390+
391+
if(this.options.tags.indexOf('all')>=0&&totalPages&&+page<totalPages){
392+
returnthis._getListReleases(page+1).then(moreReleases=>moreReleases.concat(releases));
393+
}
394+
362395
process.stdout.write(releases.length+' releases found\n');
363396

364397
returnreleases;
@@ -791,7 +824,7 @@ class Gren {
791824
.filter(this._filterBlockIssue.bind(this,range));
792825
constbody=(!range[0].body||this.options.override)&&this._groupBy(filteredIssues);
793826

794-
process.stdout.write(filteredIssues.length+'issues found\n');
827+
process.stdout.write(`${this.options.prefix+range[0].name} has${filteredIssues.length}issues found\t`);
795828

796829
return{
797830
id:range[0].id,
@@ -861,8 +894,16 @@ class Gren {
861894
};
862895

863896
returnthis._getListReleases()
864-
.then(releases=>this._getLastTags(releases.length ?releases :false))
897+
.then(releases=>{
898+
loaded=utils.task(this,'Getting tags');
899+
900+
returnthis._getLastTags(releases.length ?releases :false);
901+
})
865902
.then(tags=>{
903+
loaded();
904+
905+
console.log('Tags found: '+tags.map(({tag:{ name}})=>name).join(', '));
906+
866907
loaded=utils.task(this,'Getting the tag dates ranges');
867908

868909
returnPromise.all(this._getTagDates(tags));

‎test/Gren.spec.js‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { requireConfig } from '../lib/src/_utils.js';
77
constTOKEN=process.env.GREN_GITHUB_TOKEN;
88

99
if(!TOKEN){
10-
console.log(chalk.blue('Token not present, skipping Gren tests.'))
11-
describe=describe.skip
10+
console.log(chalk.blue('Token not present, skipping Gren tests.'));
11+
describe=describe.skip;
1212
}
1313

1414
describe('Gren',()=>{
@@ -96,10 +96,10 @@ describe('Gren', () => {
9696

9797
assert.deepEqual(gren._createReleaseRanges(blocks),rangedBlocks,'Given release blocks');
9898

99-
gren.options.tags='all'
99+
gren.options.tags='all';
100100
assert.deepEqual(gren._createReleaseRanges(blocks),rangedBlocks.concat([[
101101
{
102-
date:'2016-09-01T23:00:00.000Z',
102+
date:'2016-09-01T23:00:00.000Z'
103103
},
104104
{
105105
id:0,
@@ -127,6 +127,20 @@ describe('Gren', () => {
127127
};
128128
});
129129

130+
describe('_getLastPage',()=>{
131+
it('Should return the number of the last page',()=>{
132+
constlink='<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=2>; rel="next", <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>; rel="last"';
133+
134+
assert.deepEqual(gren._getLastPage(link),34,'String of pages');
135+
});
136+
137+
it('Should return false',()=>{
138+
assert.isNotOk(gren._getLastPage(),'Nothing has been passed');
139+
assert.isNotOk(gren._getLastPage('Lorem ipsum'),'The string does not contain the page information');
140+
assert.isNotOk(gren._getLastPage(false),'False has been passed');
141+
});
142+
});
143+
130144
describe('_groupBy, _groupByLabel',()=>{
131145
it('Should return the just templated issues',()=>{
132146
const{ normal, noLabel}=issues;
@@ -497,22 +511,22 @@ describe('Gren', () => {
497511
gren._listReleases({
498512
per_page:10
499513
})
500-
.then(({data:releases})=>{
501-
assert.lengthOf(releases,10,'The list of releases is the set one.');
502-
done();
503-
})
504-
.catch(err=>done(err));
514+
.then(({data:releases})=>{
515+
assert.lengthOf(releases,10,'The list of releases is the set one.');
516+
done();
517+
})
518+
.catch(err=>done(err));
505519
});
506520

507521
it('_listTags',done=>{
508522
gren._listTags({
509523
per_page:10
510524
})
511-
.then(({data:tags})=>{
512-
assert.lengthOf(tags,10,'The list of tags is the set one.');
513-
done();
514-
})
515-
.catch(err=>done(err));
525+
.then(({data:tags})=>{
526+
assert.lengthOf(tags,10,'The list of tags is the set one.');
527+
done();
528+
})
529+
.catch(err=>done(err));
516530
});
517531

518532
it('_getReleaseBlocks',done=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp