Visitar URL original
Add the limit option for pagination by alexcanessa · Pull Request #94 · github-tools/github-release-notes · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/_examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = {
{
name: 'Create release notes for all the tags',
description: 'Get the commits or issues closed between the specified tag and the one before.',
code: 'gren release --tags=all'
code: 'gren release --tags=all --limit=200'
},
{
name: 'Work with milestones',
Expand Down
7 changes: 7 additions & 0 deletions lib/_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ module.exports = {
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=*',
action: value => value.split('..')
},
{
short: '-l',
name: 'limit',
valueType: '<number>',
description: 'The limit of tags/releases to get. [30]',
defaultValue: '30'
},
{
short: '-D',
name: 'data-source',
Expand Down
48 changes: 35 additions & 13 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const defaults = {
ignoreLabels: false,
ignoreIssuesWith: false,
groupBy: false,
limit: 30,
milestoneMatch: 'Release {{tag_name}}'
};

Expand Down Expand Up @@ -150,11 +151,9 @@ class Gren {
const loaded = utils.task(this, 'Updating latest release');

return this.repo.updateRelease(releaseId, releaseOptions)
.then(response => {
.then(({ data: release }) => {
loaded();

const release = response.data;

console.log(chalk.green(`\n${release.name} has been successfully updated!`));
console.log(chalk.blue(`See the results here: ${release.html_url}`));

Expand Down Expand Up @@ -184,9 +183,8 @@ class Gren {
const loaded = utils.task(this, 'Preparing the release');

return this.repo.createRelease(releaseOptions)
.then(response => {
.then(({ data: release }) => {
loaded();
const release = response.data;

console.log(chalk.green(`\n${release.name} has been successfully created!`));
console.log(chalk.blue(`See the results here: ${release.html_url}`));
Expand Down Expand Up @@ -262,6 +260,18 @@ class Gren {
}).slice(0, 2);
}

/**
* Temporary function for this.repo.listReleases to accept options
*
* @see https://github.com/github-tools/github/pull/485
* @param {Object} options
*
* @return {Promise}
*/
_listTags(options) {
return this.repo._request('GET', `/repos/${this.repo.__fullname}/tags`, options);
}

/**
* Get all the tags of the repo
*
Expand All @@ -273,12 +283,12 @@ class Gren {
_getLastTags(releases) {
const loaded = utils.task(this, 'Getting tags');

return this.repo.listTags()
.then(response => {
return this._listTags({
per_page: this.options.limit
})
.then(({ data: tags }) => {
loaded();

const tags = response.data;

if (!tags.length) {
throw chalk.red('Looks like you have no tags! Tag a commit first and then run gren again');
}
Expand Down Expand Up @@ -320,6 +330,18 @@ class Gren {
})));
}

/**
* Temporary function for this.repo.listReleases to accept options
*
* @see https://github.com/github-tools/github/pull/485
* @param {Object} options
*
* @return {Promise}
*/
_listReleases(options) {
return this.repo._request('GET', `/repos/${this.repo.__fullname}/releases`, options);
}

/**
* Get all releases
*
Expand All @@ -331,12 +353,12 @@ class Gren {
_getListReleases() {
const loaded = utils.task(this, 'Getting the list of releases');

return this.repo.listReleases()
.then(response => {
return this._listReleases({
per_page: this.options.limit
})
.then(({ data: releases }) => {
loaded();

const releases = response.data;

process.stdout.write(releases.length + ' releases found\n');

return releases;
Expand Down
70 changes: 34 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions test/Gren.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,28 @@ describe('Gren', () => {
.catch(err => done(err));
});

it('_listReleases', done => {
gren._listReleases({
per_page: 10
})
.then(({ data: releases }) => {
assert.lengthOf(releases, 10, 'The list of releases is the set one.');
done();
})
.catch(err => done(err));
});

it('_listTags', done => {
gren._listTags({
per_page: 10
})
.then(({ data: tags }) => {
assert.lengthOf(tags, 10, 'The list of tags is the set one.');
done();
})
.catch(err => done(err));
});

it('_getReleaseBlocks', done => {
gren._getReleaseBlocks()
.then(releaseBlocks => {
Expand Down