Skip to content

Commit

Permalink
Fix the tag sorting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcanessa committed Dec 12, 2019
1 parent 59bfea3 commit 2460fac
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class Gren {
*
* @since 0.1.0
* @private
* @deprecated
*
* @param {Array} releases
* @param {number} page
Expand Down Expand Up @@ -327,6 +328,49 @@ class Gren {
return filteredTags;
}

/**
* Get all the tags of the repo
*
* @since 0.1.0
* @private
* @deprecated
*
* @param {Array} releases
* @param {number} page
*
* @return {Promise}
*/
async _getAllTags(releases, page = 1, limit = this.options.limit) {
const { headers: { link }, data: tags } = await this._listTags({
per_page: limit,
page
});

if (!tags.length) {
throw chalk.red('\nLooks like you have no tags! Tag a commit first and then run gren again');
}

const filteredTags = tags
.filter((tag) => tag && this.options.ignoreTagsWith.every(ignoreTag => !tag.name.match(ignoreTag)))
.map(tag => {
const tagRelease = releases ? releases.filter(release => release.tag_name === tag.name)[0] : false;
const releaseId = tagRelease ? tagRelease.id : null;

return {
tag: tag,
releaseId: releaseId
};
});

const totalPages = this._getLastPage(link);

if (totalPages && page < totalPages) {
return this._getAllTags(releases, page + 1).then(moreTags => moreTags.concat(filteredTags));
}

return filteredTags;
}

/**
* Get the dates of the last two tags
*
Expand Down Expand Up @@ -1079,19 +1123,22 @@ class Gren {
const releases = await this._getListReleases();
this.tasks['Getting releases'].text = 'Getting tags';

const tags = await this._getLastTags(releases.length ? releases : false);
const tags = await this._getAllTags(releases.length ? releases : false);

this._validateRequiredTagsExists(tags, this.options.tags);
const releaseDates = await Promise.all(this._getTagDates(tags));

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

loaded(`Tags found: ${selectedTags.map(({ name }) => name).join(', ')}`);

return dataSource[this.options.dataSource](
this._createReleaseRanges(releaseDates)
this._createReleaseRanges(selectedTags)
);
}

/**
* Check that the require tags are exists in tags
* Check that the require tags exist in tags
*
* @param {Array} tags
* @param {Array} requireTags
Expand Down

0 comments on commit 2460fac

Please sign in to comment.