Skip to content

Commit adfc5e5

Browse files
wellDan28alexcanessa
authored andcommitted
Fix 132 tags not found (#136)
* Fix pagination should work for two specific tags getLastTags should use pagination when the tag option were set to 2 tags and these tags weren not found yet * Add validation - check that the tags option are found * Fix - requireTags contains 'all clause' * Fix test ignoreTagsWith should work only when tags=all * Add tests fot _validateRequiredTagsExists method * Rename paramters names * Change the exception message * Change const name * Improve the documention to '_validateRequiredTagsExists'
1 parent 3e6b2e4 commit adfc5e5

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

lib/src/Gren.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class Gren {
312312
});
313313
const totalPages = this._getLastPage(link);
314314

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

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

906906
const tags = await this._getLastTags(releases.length ? releases : false);
907+
this._validateRequiredTagsExists(tags, this.options.tags);
907908
const releaseDates = await Promise.all(this._getTagDates(tags));
908909

909910
loaded(`Tags found: ${tags.map(({ tag: { name } }) => name).join(', ')}`);
@@ -913,6 +914,28 @@ class Gren {
913914
);
914915
}
915916

917+
/**
918+
* Check that the require tags are exists in tags
919+
*
920+
* @param {Array} tags
921+
* @param {Array} requireTags
922+
*
923+
* @throws{Exception} Will throw exception in case that
924+
* @requireTags were set to 2 specific tags and these tags aren't exists in @tags
925+
*/
926+
_validateRequiredTagsExists(tags, requireTags) {
927+
if (requireTags.indexOf('all') >= 0 || !(requireTags instanceof Array)) return;
928+
929+
const tagsNames = tags.map(tagData => tagData.tag.name);
930+
931+
const missingTags = requireTags.filter(requireTag => tagsNames.indexOf(requireTag) < 0);
932+
if (missingTags.length > 0) {
933+
const inflection = (missingTags.length === 1) ? 'tag is' : 'tags are';
934+
throw chalk.red(`\nThe following ${inflection} not found in the repository: ${missingTags}. ` +
935+
'please provide existing tags.');
936+
}
937+
}
938+
916939
/**
917940
* Check if there is connectivity
918941
*

test/Gren.spec.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,24 @@ describe('Gren', () => {
504504
fs.unlinkSync(gren.options.changelogFilename);
505505
}
506506
});
507+
})
508+
509+
describe('_validateRequiredTagsExists', () => {
510+
it('should failed if one tag is missing', () => {
511+
const existingTagName = 'existing_tag';
512+
const existingTag = { tag: { name: existingTagName } };
513+
const expectedException = chalk.red('\nThe following tag is not found in the repository: some_tag. please provide existing tags.');
514+
assert.throw(() => gren._validateRequiredTagsExists([existingTag], ['some_tag', 'existing_tag']), expectedException);
515+
});
516+
517+
it('should failed if the two input tags are missing', () => {
518+
const expectedException = chalk.red('\nThe following tags are not found in the repository: some_tag,some_other_tag. please provide existing tags.');
519+
assert.throw(() => gren._validateRequiredTagsExists([], ['some_tag', 'some_other_tag']), expectedException);
520+
});
521+
522+
it('Should do nothing if requireTags=all', () => {
523+
assert.doesNotThrow(() => gren._validateRequiredTagsExists([], 'all'));
524+
});
507525
});
508526

509527
describe('Tests that require network', () => {
@@ -543,19 +561,25 @@ describe('Gren', () => {
543561
.catch(err => done(err));
544562
});
545563

546-
it('_getLastTags', done => {
547-
gren.options.ignoreTagsWith = ['11'];
548-
gren.options.tags = ['0.12.0', '0.11.0'];
549-
550-
gren._getLastTags()
551-
.then(tags => {
552-
assert.notInclude(tags.map(({ name }) => name), '0.11.0', 'The ignored tag is not present');
553-
done();
554-
})
555-
.catch(err => done(err));
564+
describe('_getLastTags', () => {
565+
describe('with tags=all', () => {
566+
describe('with ignoreTagsWith', () => {
567+
it('should ignore the specific tag', done => {
568+
gren.options.ignoreTagsWith = ['11'];
569+
gren.options.tags = ['all'];
570+
gren._getLastTags()
571+
.then(tags => {
572+
assert.notInclude(tags.map(({ name }) => name), '0.11.0', 'The ignored tag is not present');
573+
done();
574+
})
575+
.catch(err => done(err));
576+
});
577+
});
578+
});
556579
});
557580

558581
it('_getReleaseBlocks', done => {
582+
gren.options.tags = ['0.12.0', '0.11.0'];
559583
gren._getReleaseBlocks()
560584
.then(releaseBlocks => {
561585
assert.isArray(releaseBlocks, 'The releaseBlocks is an Array');

0 commit comments

Comments
 (0)