forked from nodejs/citgm
-
Notifications
You must be signed in to change notification settings - Fork 0
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 `withTags` or `excludeTags` option. fixes nodejs#72
- Loading branch information
George Adams
committed
Feb 19, 2017
1 parent
449cf6c
commit 0be65a6
Showing
9 changed files
with
262 additions
and
3 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,43 @@ | ||
'use strict'; | ||
const log = require('./out')({}); | ||
|
||
function checkTags(app, mod, name) { | ||
// Returns true if the module should be skipped | ||
|
||
if ((app.excludeTags && !mod.tags) || (!app.withTags && !app.excludeTags)) { | ||
return false; // No checks to run. | ||
} else if (app.withTags && !mod.tags) { | ||
return true; // No tags for this module | ||
} | ||
|
||
if (typeof mod.tags === 'string') { | ||
mod.tags = mod.tags.split(','); // If mod.tags is a single field | ||
} | ||
|
||
function checkMatches (A, B) { | ||
return A.filter((tag) => B.indexOf(tag) !== -1); | ||
} | ||
|
||
let excludeTagMatches = app.excludeTags ? | ||
checkMatches(mod.tags, app.excludeTags) : []; | ||
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 withTagMatches = app.withTags ? | ||
checkMatches(mod.tags, app.withTags) : []; | ||
if (withTagMatches.length) { | ||
log.info(name, `will run as these withTags matched: ${withTagMatches}`); | ||
return false; // We matched a withTag. | ||
} else { | ||
log.info(name, 'skipped as no withTags matched'); | ||
return true; // We didn't match any withTags. | ||
} | ||
} | ||
|
||
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,127 @@ | ||
'use strict'; | ||
|
||
const test = require('tap').test; | ||
const rewire = require('rewire'); | ||
|
||
const checkTags = rewire('../lib/check-tags'); | ||
|
||
test('test withTags and matching tag', function (t) { | ||
const app = { | ||
withTags: 'test' | ||
}; | ||
const mod = { | ||
tags: 'test' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test withTags and same excludeTags', function (t) { | ||
const app = { | ||
withTags: 'test', | ||
excludeTags: 'test' | ||
}; | ||
const mod = { | ||
tags: 'test' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test'); | ||
t.true(result, 'excludeTags should take priority over withTags'); | ||
}); | ||
|
||
test('test several withTags and matching tag', function (t) { | ||
const app = { | ||
withTags: 'test,this,should,still,pass' | ||
}; | ||
const mod = { | ||
tags: 'test' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test several withTags and multiple tags', function (t) { | ||
const app = { | ||
withTags: 'test,this,should,still,pass' | ||
}; | ||
const mod = { | ||
tags: ['test', 'this', 'is'] | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
|
||
test('test withTags and multiple tags', function (t) { | ||
const app = { | ||
withTags: 'test' | ||
}; | ||
const mod = { | ||
tags: ['test', 'noTest'] | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
|
||
test('test withTags and no matching tag', function (t) { | ||
const app = { | ||
withTags: 'test' | ||
}; | ||
const mod = { | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test'); | ||
t.true(result, 'should return true'); | ||
}); | ||
|
||
test('test withTags and different tag', function (t) { | ||
const app = { | ||
withTags: 'test' | ||
}; | ||
const mod = { | ||
tags: 'noMatch' | ||
}; | ||
t.plan(1); | ||
const result = checkTags(app, mod, 'test'); | ||
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'); | ||
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'); | ||
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'); | ||
t.false(result, 'should return false'); | ||
}); |