-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this PR adds the functionality to run `citgm-all` on specific tags in the lookup by passing in the `includeTags` or `excludeTags` option. fixes #72
- Loading branch information
George Adams
committed
Feb 28, 2017
1 parent
1820757
commit 14072a5
Showing
9 changed files
with
257 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
|
||
function checkTags(app, mod, name, log) { | ||
// Returns true if the module should be skipped | ||
|
||
if ((app.excludeTags && !mod.tags) || | ||
(!app.includeTags && !app.excludeTags)) { | ||
return false; // No checks to run. | ||
} else if (app.includeTags && !mod.tags) { | ||
return true; // No tags for this module | ||
} | ||
|
||
if (typeof mod.tags === 'string') { | ||
mod.tags = [mod.tags]; // If mod.tags is a single field | ||
} | ||
|
||
let excludeTagMatches = _.intersection(app.excludeTags, mod.tags); | ||
|
||
if (excludeTagMatches.length) { | ||
log.info(name, | ||
`skipped as these excludeTags matched: ${excludeTagMatches}`); | ||
return true; // We matched an excludeTag. | ||
} else if (app.excludeTags) { | ||
log.info(`${name} will run as no excludeTags matched`); | ||
return false; // We did not match an excludeTag. | ||
} | ||
|
||
let includeTagMatches = _.intersection(app.includeTags, mod.tags); | ||
|
||
if (includeTagMatches.length) { | ||
log.info(name, | ||
`will run as these includeTags matched: ${includeTagMatches}`); | ||
return false; // We matched an includeTag. | ||
} else { | ||
log.info(name, 'skipped as no includeTags matched'); | ||
return true; // We did not match an includeTag. | ||
} | ||
} | ||
|
||
module.exports = checkTags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"omg-i-pass": { | ||
"npm": true, | ||
"tags": "tag1" | ||
}, | ||
"omg-i-fail": { | ||
"npm": true, | ||
"tags": ["tag2", "tagNotUsed"] | ||
}, | ||
"omg-i-pass-too": { | ||
"npm": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
'use strict'; | ||
|
||
const test = require('tap').test; | ||
const rewire = require('rewire'); | ||
|
||
const checkTags = rewire('../lib/check-tags'); | ||
const log = require('../lib/out')({}); | ||
|
||
test('test includeTags and matching tag', function (t) { | ||
const app = { | ||
includeTags: ['test'] | ||
}; | ||
const mod = { | ||
tags: 'test' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test includeTags and same excludeTags', function (t) { | ||
const app = { | ||
includeTags: ['test'], | ||
excludeTags: ['test'] | ||
}; | ||
const mod = { | ||
tags: 'test' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.true(result, 'excludeTags should take priority over includeTags'); | ||
}); | ||
|
||
test('test several includeTags and matching tag', function (t) { | ||
const app = { | ||
includeTags: ['test', 'this', 'should', 'still', 'pass'] | ||
}; | ||
const mod = { | ||
tags: 'test' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test several includeTags and multiple tags', function (t) { | ||
const app = { | ||
includeTags: ['test', 'this', 'should', 'still', 'pass'] | ||
}; | ||
const mod = { | ||
tags: ['test', 'this', 'is'] | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
|
||
test('test includeTags and multiple tags', function (t) { | ||
const app = { | ||
includeTags: ['test'] | ||
}; | ||
const mod = { | ||
tags: ['test', 'noTest'] | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
|
||
test('test includeTags and no matching tag', function (t) { | ||
const app = { | ||
includeTags: ['test'] | ||
}; | ||
const mod = { | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.true(result, 'should return true'); | ||
}); | ||
|
||
test('test includeTags and different tag', function (t) { | ||
const app = { | ||
includeTags: ['test'] | ||
}; | ||
const mod = { | ||
tags: 'noMatch' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.true(result, 'should return true'); | ||
}); | ||
|
||
test('test excludeTags and matching tag', function (t) { | ||
const app = { | ||
excludeTags: ['test'] | ||
}; | ||
const mod = { | ||
tags: 'test' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.true(result, 'should return true'); | ||
}); | ||
|
||
test('test excludeTags and no matching tag', function (t) { | ||
const app = { | ||
excludeTags: ['test'] | ||
}; | ||
const mod = { | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test excludeTags and different tag', function (t) { | ||
const app = { | ||
excludeTags: ['test'] | ||
}; | ||
const mod = { | ||
tags: 'noMatch' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test', log); | ||
t.false(result, 'should return false'); | ||
}); |