Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Overwriting Combinations in Matrix #6463

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions pkg/apis/pipeline/v1/matrix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,26 @@ func (m *Matrix) FanOut() []Params {
for _, parameter := range m.Params {
combinations = combinations.fanOutMatrixParams(parameter)
}
combinations = combinations.overwriteCombinations(includeCombinations)
combinations.overwriteCombinations(includeCombinations)
EmmaMunley marked this conversation as resolved.
Show resolved Hide resolved
combinations = combinations.addNewCombinations(includeCombinations)
return combinations.toParams()
}

// overwriteCombinations replaces any missing include params in the initial
// matrix params combinations by overwriting the initial combinations with the
// include combinations
func (cs Combinations) overwriteCombinations(ics Combinations) Combinations {
func (cs Combinations) overwriteCombinations(ics Combinations) {
for _, paramCombination := range cs {
for _, includeCombination := range ics {
if paramCombination.contains(includeCombination) {
includeCombination.overwrite(paramCombination)
// overwrite the parameter name and value in existing combination
// with the include combination
for name, val := range includeCombination {
paramCombination[name] = val
}
}
}
}
return cs
}

// addNewCombinations creates a new combination for any include parameter
Expand All @@ -115,14 +118,6 @@ func (c Combination) contains(includeCombination Combination) bool {
return true
}

// overwrite the parameter name and value exists in combination with the include combination
func (c Combination) overwrite(oldCombination Combination) Combination {
for name, val := range c {
oldCombination[name] = val
}
return oldCombination
}

// shouldAddNewCombination returns true if the include parameter name exists but the value is
// missing from combinations
func (cs Combinations) shouldAddNewCombination(includeCombination map[string]string) bool {
Expand Down
19 changes: 7 additions & 12 deletions pkg/apis/pipeline/v1beta1/matrix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,26 @@ func (m *Matrix) FanOut() []Params {
for _, parameter := range m.Params {
combinations = combinations.fanOutMatrixParams(parameter)
}
combinations = combinations.overwriteCombinations(includeCombinations)
combinations.overwriteCombinations(includeCombinations)
combinations = combinations.addNewCombinations(includeCombinations)
return combinations.toParams()
}

// overwriteCombinations replaces any missing include params in the initial
// matrix params combinations by overwriting the initial combinations with the
// include combinations
func (cs Combinations) overwriteCombinations(ics Combinations) Combinations {
func (cs Combinations) overwriteCombinations(ics Combinations) {
EmmaMunley marked this conversation as resolved.
Show resolved Hide resolved
for _, paramCombination := range cs {
for _, includeCombination := range ics {
if paramCombination.contains(includeCombination) {
includeCombination.overwrite(paramCombination)
// overwrite the parameter name and value in existing combination
// with the include combination
for name, val := range includeCombination {
paramCombination[name] = val
}
}
}
}
return cs
}

// addNewCombinations creates a new combination for any include parameter
Expand All @@ -115,14 +118,6 @@ func (c Combination) contains(includeCombination Combination) bool {
return true
}

// overwrite the parameter name and value exists in combination with the include combination
func (c Combination) overwrite(oldCombination Combination) Combination {
for name, val := range c {
oldCombination[name] = val
}
return oldCombination
}

// shouldAddNewCombination returns true if the include parameter name exists but the value is
// missing from combinations
func (cs Combinations) shouldAddNewCombination(includeCombination map[string]string) bool {
Expand Down