-
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 `withTags` or `excludeTags` option. fixes #72
- Loading branch information
George Adams
committed
Feb 8, 2017
1 parent
826cf80
commit b3ded44
Showing
8 changed files
with
230 additions
and
1 deletion.
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,51 @@ | ||
var logger = require('./out'); | ||
|
||
var log = logger({ | ||
}); | ||
|
||
function checkTag(app, mod, name) { | ||
if (mod.tag && mod.tag !== '' && typeof mod.tag === 'string') { | ||
mod.tag = mod.tag.split(','); | ||
} | ||
if (app.withTags && typeof app.withTags === 'string') { | ||
app.withTags = app.withTags.split(','); | ||
} | ||
if (app.excludeTags && typeof app.excludeTags === 'string') { | ||
app.excludeTags = app.excludeTags.split(','); | ||
} | ||
|
||
function intersection (A, B) { | ||
var m = A.reduce(function(m, v) { | ||
m[v] = 1; return m; | ||
}, {}); | ||
return B.filter(function(v) { | ||
return m[v]; | ||
}); | ||
} | ||
|
||
function checkMatch (A, B) { | ||
var result = intersection(A, B); | ||
if (result.length !== 0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
if ((app.withTags && mod.tag && !checkMatch(mod.tag, app.withTags)) || | ||
(app.withTags && !mod.tag)) { | ||
log.info(name, 'no matching tag found'); | ||
return true; | ||
} else if (app.withTags && mod.tag && checkMatch(mod.tag, app.withTags)) { | ||
log.info(name, 'the following tag was matched: ' + app.withTags); | ||
return false; | ||
} else if (app.excludeTags && mod.tag && checkMatch(mod.tag, | ||
app.excludeTags)) { | ||
log.info(name, 'skipped because of tag: ' + app.excludeTags); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = checkTag; |
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, | ||
"tag": "tag1" | ||
}, | ||
"omg-i-fail": { | ||
"npm": true, | ||
"tag": "tag2" | ||
}, | ||
"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,114 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
var rewire = require('rewire'); | ||
|
||
var checkTag = rewire('../lib/check-tag'); | ||
|
||
test('test withTags and matching tag', function (t) { | ||
var app = { | ||
withTags: 'test' | ||
}; | ||
var mod = { | ||
tag: 'test' | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test several withTags and matching tag', function (t) { | ||
var app = { | ||
withTags: 'test,this,should,still,pass' | ||
}; | ||
var mod = { | ||
tag: 'test' | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test several withTags and multiple tags', function (t) { | ||
var app = { | ||
withTags: 'test,this,should,still,pass' | ||
}; | ||
var mod = { | ||
tag: ['test', 'this', 'is'] | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
|
||
test('test withTags and multiple tags', function (t) { | ||
var app = { | ||
withTags: 'test' | ||
}; | ||
var mod = { | ||
tag: ['test', 'noTest'] | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
|
||
test('test withTags and no matching tag', function (t) { | ||
var app = { | ||
withTags: 'test' | ||
}; | ||
var mod = { | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.true(result, 'should return true'); | ||
}); | ||
|
||
test('test withTags and different tag', function (t) { | ||
var app = { | ||
withTags: 'test' | ||
}; | ||
var mod = { | ||
tag: 'noMatch' | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.true(result, 'should return true'); | ||
}); | ||
|
||
test('test excludeTags and matching tag', function (t) { | ||
var app = { | ||
excludeTags: 'test' | ||
}; | ||
var mod = { | ||
tag: 'test' | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.true(result, 'should return true'); | ||
}); | ||
|
||
test('test excludeTags and no matching tag', function (t) { | ||
var app = { | ||
excludeTags: 'test' | ||
}; | ||
var mod = { | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); | ||
|
||
test('test excludeTags and different tag', function (t) { | ||
var app = { | ||
excludeTags: 'test' | ||
}; | ||
var mod = { | ||
tag: 'noMatch' | ||
}; | ||
t.plan(1); | ||
var result = checkTag(app, mod, 'test'); | ||
t.false(result, 'should return false'); | ||
}); |