Skip to content

Commit 2460fac

Browse files
committed
Fix the tag sorting issue
1 parent 59bfea3 commit 2460fac

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

lib/src/Gren.js

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class Gren {
290290
*
291291
* @since 0.1.0
292292
* @private
293+
* @deprecated
293294
*
294295
* @param {Array} releases
295296
* @param {number} page
@@ -327,6 +328,49 @@ class Gren {
327328
return filteredTags;
328329
}
329330

331+
/**
332+
* Get all the tags of the repo
333+
*
334+
* @since 0.1.0
335+
* @private
336+
* @deprecated
337+
*
338+
* @param {Array} releases
339+
* @param {number} page
340+
*
341+
* @return {Promise}
342+
*/
343+
async _getAllTags(releases, page = 1, limit = this.options.limit) {
344+
const { headers: { link }, data: tags } = await this._listTags({
345+
per_page: limit,
346+
page
347+
});
348+
349+
if (!tags.length) {
350+
throw chalk.red('\nLooks like you have no tags! Tag a commit first and then run gren again');
351+
}
352+
353+
const filteredTags = tags
354+
.filter((tag) => tag && this.options.ignoreTagsWith.every(ignoreTag => !tag.name.match(ignoreTag)))
355+
.map(tag => {
356+
const tagRelease = releases ? releases.filter(release => release.tag_name === tag.name)[0] : false;
357+
const releaseId = tagRelease ? tagRelease.id : null;
358+
359+
return {
360+
tag: tag,
361+
releaseId: releaseId
362+
};
363+
});
364+
365+
const totalPages = this._getLastPage(link);
366+
367+
if (totalPages && page < totalPages) {
368+
return this._getAllTags(releases, page + 1).then(moreTags => moreTags.concat(filteredTags));
369+
}
370+
371+
return filteredTags;
372+
}
373+
330374
/**
331375
* Get the dates of the last two tags
332376
*
@@ -1079,19 +1123,22 @@ class Gren {
10791123
const releases = await this._getListReleases();
10801124
this.tasks['Getting releases'].text = 'Getting tags';
10811125

1082-
const tags = await this._getLastTags(releases.length ? releases : false);
1126+
const tags = await this._getAllTags(releases.length ? releases : false);
1127+
10831128
this._validateRequiredTagsExists(tags, this.options.tags);
1084-
const releaseDates = await Promise.all(this._getTagDates(tags));
10851129

1086-
loaded(`Tags found: ${tags.map(({ tag: { name } }) => name).join(', ')}`);
1130+
const releaseDates = this._sortReleasesByDate(await Promise.all(this._getTagDates(tags)));
1131+
const selectedTags = (this._getSelectedTags(releaseDates) || [releaseDates[0], releaseDates[1]]);
1132+
1133+
loaded(`Tags found: ${selectedTags.map(({ name }) => name).join(', ')}`);
10871134

10881135
return dataSource[this.options.dataSource](
1089-
this._createReleaseRanges(releaseDates)
1136+
this._createReleaseRanges(selectedTags)
10901137
);
10911138
}
10921139

10931140
/**
1094-
* Check that the require tags are exists in tags
1141+
* Check that the require tags exist in tags
10951142
*
10961143
* @param {Array} tags
10971144
* @param {Array} requireTags

0 commit comments

Comments
 (0)