Skip to content

Commit

Permalink
consolidate tags reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
LongLiveCHIEF committed Dec 5, 2020
1 parent 65b702e commit c4cf549
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
6 changes: 3 additions & 3 deletions __tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {extraTagsReducer, getInputBoolean, getInputList, conditionalTagsReducer} = require('../src/utils')
const {tagsReducer, getInputBoolean, getInputList} = require('../src/utils')
const {getInputBooleanScenarios, getInputListScenarios} = require('./__data__/utils')

describe('getInputBoolean', () => {
Expand All @@ -16,10 +16,10 @@ describe('getInputList', ()=>{

})

describe('extraTagsReducer', () => {
describe('tagsReducer', () => {
test('reduces imperative booleans',() => {

let extraTagsOutput = ['latest::true', 'edge::true', 'canary::false'].reduce(extraTagsReducer, [])
let extraTagsOutput = ['latest::true', 'edge::true', 'canary::false'].reduce(tagsReducer, [])
expect(extraTagsOutput).toEqual(['latest', 'edge'])
})

Expand Down
6 changes: 3 additions & 3 deletions src/taggingStrategy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {parseTag} = require('./parseTag')
const {extraTagsReducer, conditionalTagsReducer, imageNameReducer, getInputList} = require('./utils')
const {tagsReducer, imageNameReducer, getInputList} = require('./utils')

exports.taggingStrategy = ({inputTags, tagName, imageName, extraTags}) => {
try {
let outputTags = getInputList(inputTags)
.reduce(extraTagsReducer, [])
.reduce(tagsReducer, [])
.map(strategy => parseTag(strategy, tagName))
.reduce(imageNameReducer(imageName), [])

Expand All @@ -13,7 +13,7 @@ exports.taggingStrategy = ({inputTags, tagName, imageName, extraTags}) => {
// reduce imageNames for extraTags
// push the extraTag to outputTags array
getInputList(extraTags)
.reduce(extraTagsReducer, [])
.reduce(tagsReducer, [])
.map(extraTag => imageName ? `${imageName}:${extraTag}`: `${extraTag}`)
.forEach(extraTag => outputTags.push(extraTag))

Expand Down
19 changes: 1 addition & 18 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,7 @@ exports.getInputBoolean = (input) => {
return boolTest.test(input)
}

exports.conditionalTagsReducer = (tags,tag) => {
const isConditionalTag = /(?<strategy>.*)::'?(?<include>true|false)/i

// tag has condition specified, so only return
//the tag if the condition is true
if(isConditionalTag.test(tag)){
let {groups} = tag.match(isConditionalTag)
if(groups.include == ('true'||true)) {
return [...tags, groups.strategy]
} else {
return tags
}
}

return [...tags, tag]
}

exports.extraTagsReducer = (tags,tag) => {
exports.tagsReducer = (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 c4cf549

Please sign in to comment.