@@ -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+ const MAX_TAGS_LIMIT = 99 ;
24+ const TAGS_LIMIT = 30 ;
25+
2426/** Class creating release notes and changelog notes */
2527class Gren {
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 throw chalk . red ( 'You must provide the TOKEN' ) ;
@@ -58,7 +61,11 @@ class Gren {
5861
5962 return this . _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+ return blocks . 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- const loaded = utils . task ( this , 'Getting tags' ) ;
285-
293+ _getLastTags ( releases , page = 1 , limit = this . options . limit ) {
286294 return this . _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 throw chalk . 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+ const totalPages = 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+ return this . _getLastTags ( releases , page + 1 ) . then ( moreTags => moreTags . concat ( filteredTags ) ) ;
318+ }
309319
310320 return filteredTags ;
311321 } ) ;
@@ -323,10 +333,10 @@ class Gren {
323333 */
324334 _getTagDates ( tags ) {
325335 return tags . 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 return this . 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+ const linkMatch = Boolean ( link ) && link . match ( / p a g e = ( \d + ) > ; r e l = " l a s t " / ) ;
367+
368+ return linkMatch && + 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 const loaded = utils . task ( this , 'Getting the list of releases' ) ;
355381
356382 return this . _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+ const totalPages = this . _getLastPage ( link ) ;
390+
391+ if ( this . options . tags . indexOf ( 'all' ) >= 0 && totalPages && + page < totalPages ) {
392+ return this . _getListReleases ( page + 1 ) . then ( moreReleases => moreReleases . concat ( releases ) ) ;
393+ }
394+
362395 process . stdout . write ( releases . length + ' releases found\n' ) ;
363396
364397 return releases ;
@@ -791,7 +824,7 @@ class Gren {
791824 . filter ( this . _filterBlockIssue . bind ( this , range ) ) ;
792825 const body = ( ! 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 return this . _getListReleases ( )
864- . then ( releases => this . _getLastTags ( releases . length ? releases : false ) )
897+ . then ( releases => {
898+ loaded = utils . task ( this , 'Getting tags' ) ;
899+
900+ return this . _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 return Promise . all ( this . _getTagDates ( tags ) ) ;
0 commit comments