Skip to content

Fix 132 tags not found #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 21, 2018
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
25 changes: 24 additions & 1 deletion lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class Gren {
});
const totalPages = this._getLastPage(link);

if (this.options.tags.indexOf('all') >= 0 && totalPages && +page < totalPages) {
if ((this.options.tags.indexOf('all') >= 0 || filteredTags < 2) && totalPages && +page < totalPages) {
return this._getLastTags(releases, page + 1).then(moreTags => moreTags.concat(filteredTags));
}

Expand Down Expand Up @@ -904,6 +904,7 @@ class Gren {
this.tasks['Getting releases'].text = 'Getting tags';

const tags = await this._getLastTags(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(', ')}`);
Expand All @@ -913,6 +914,28 @@ class Gren {
);
}

/**
* Check that the require tags are exists in tags
*
* @param {Array} tags
* @param {Array} requireTags
*
* @throws{Exception} Will throw exception in case that
* @requireTags were set to 2 specific tags and these tags aren't exists in @tags
*/
_validateRequiredTagsExists(tags, requireTags) {
if (requireTags.indexOf('all') >= 0 || !(requireTags instanceof Array)) return;

const tagsNames = tags.map(tagData => tagData.tag.name);

const missingTags = requireTags.filter(requireTag => tagsNames.indexOf(requireTag) < 0);
if (missingTags.length > 0) {
const inflection = (missingTags.length === 1) ? 'tag is' : 'tags are';
throw chalk.red(`\nThe following ${inflection} not found in the repository: ${missingTags}. ` +
'please provide existing tags.');
}
}

/**
* Check if there is connectivity
*
Expand Down
44 changes: 34 additions & 10 deletions test/Gren.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,24 @@ describe('Gren', () => {
fs.unlinkSync(gren.options.changelogFilename);
}
});
})

describe('_validateRequiredTagsExists', () => {
it('should failed if one tag is missing', () => {
const existingTagName = 'existing_tag';
const existingTag = { tag: { name: existingTagName } };
const expectedException = chalk.red('\nThe following tag is not found in the repository: some_tag. please provide existing tags.');
assert.throw(() => gren._validateRequiredTagsExists([existingTag], ['some_tag', 'existing_tag']), expectedException);
});

it('should failed if the two input tags are missing', () => {
const expectedException = chalk.red('\nThe following tags are not found in the repository: some_tag,some_other_tag. please provide existing tags.');
assert.throw(() => gren._validateRequiredTagsExists([], ['some_tag', 'some_other_tag']), expectedException);
});

it('Should do nothing if requireTags=all', () => {
assert.doesNotThrow(() => gren._validateRequiredTagsExists([], 'all'));
});
});

describe('Tests that require network', () => {
Expand Down Expand Up @@ -543,19 +561,25 @@ describe('Gren', () => {
.catch(err => done(err));
});

it('_getLastTags', done => {
gren.options.ignoreTagsWith = ['11'];
gren.options.tags = ['0.12.0', '0.11.0'];

gren._getLastTags()
.then(tags => {
assert.notInclude(tags.map(({ name }) => name), '0.11.0', 'The ignored tag is not present');
done();
})
.catch(err => done(err));
describe('_getLastTags', () => {
describe('with tags=all', () => {
describe('with ignoreTagsWith', () => {
it('should ignore the specific tag', done => {
gren.options.ignoreTagsWith = ['11'];
gren.options.tags = ['all'];
gren._getLastTags()
.then(tags => {
assert.notInclude(tags.map(({ name }) => name), '0.11.0', 'The ignored tag is not present');
done();
})
.catch(err => done(err));
});
});
});
});

it('_getReleaseBlocks', done => {
gren.options.tags = ['0.12.0', '0.11.0'];
gren._getReleaseBlocks()
.then(releaseBlocks => {
assert.isArray(releaseBlocks, 'The releaseBlocks is an Array');
Expand Down