Skip to content

Commit

Permalink
fix extraTags parser
Browse files Browse the repository at this point in the history
  • Loading branch information
LongLiveCHIEF committed Dec 5, 2020
1 parent 796dae8 commit 65b702e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 8 additions & 0 deletions __tests__/taggingStrategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {taggingStrategy} = require('../src/taggingStrategy')
const {scenarios} = require('./__data__/taggingStrategy')

describe.each(scenarios)('produce tags %s given %o', (expected, given) => {
test('it produces a csv list', () => {
expect(taggingStrategy(given)).toEqual(expected)
})
})
7 changes: 4 additions & 3 deletions src/taggingStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {extraTagsReducer, conditionalTagsReducer, imageNameReducer, getInputList}
exports.taggingStrategy = ({inputTags, tagName, imageName, extraTags}) => {
try {
let outputTags = getInputList(inputTags)
.reduce(conditionalTagsReducer, [])
.reduce(extraTagsReducer, [])
.map(strategy => parseTag(strategy, tagName))
.reduce(imageNameReducer(imageName), [])

Expand All @@ -14,8 +14,9 @@ exports.taggingStrategy = ({inputTags, tagName, imageName, extraTags}) => {
// push the extraTag to outputTags array
getInputList(extraTags)
.reduce(extraTagsReducer, [])
.reduce(imageNameReducer(imageName),[])
.forEach(tag => outputTags.push(tag))
.map(extraTag => imageName ? `${imageName}:${extraTag}`: `${extraTag}`)
.forEach(extraTag => outputTags.push(extraTag))

}

return outputTags.join(',')
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports.conditionalTagsReducer = (tags,tag) => {
return [...tags, tag]
}

exports.extraTagsReducer = (tags,tag,i) => {
exports.extraTagsReducer = (tags,tag) => {
let isConditionalTag = tag.search('::')
// tag has condition specified, so only return
//the tag if the condition is true
Expand Down

0 comments on commit 65b702e

Please sign in to comment.