worker/koji-finalize: handle multiple upload targets

Enhance the `koji-finalize` job implementation to be able to cope with
multiple upload targets being specified for an `OSBuildJob`.

Implement a convenience method `OSBuildJobResult.TargetResultsByName()`
for filtering the target results attached to the job result by their
name. Cover the method with an unit test. And lastly use this method in
the `koji-finalize` job to find the appropriate Koji upload target
results.

This is a preparation for enabling cloud uploads for Koji composes.
This commit is contained in:
Tomas Hozza 2022-07-20 12:48:03 +02:00 committed by Tom Gundersen
parent 58696e849f
commit 77a1672b79
3 changed files with 123 additions and 5 deletions

View file

@ -75,6 +75,20 @@ func (j *OSBuildJobResult) TargetErrors() []*clienterrors.Error {
return targetErrors
}
// TargetResultsByName iterates over TargetResults attached to the Job result and
// returns a slice of Target results of the provided name (type). If there were no
// TargetResults of the desired type attached to the Job results, the returned
// slice will be empty.
func (j *OSBuildJobResult) TargetResultsByName(name target.TargetName) []*target.TargetResult {
targetResults := []*target.TargetResult{}
for _, targetResult := range j.TargetResults {
if targetResult.Name == name {
targetResults = append(targetResults, targetResult)
}
}
return targetResults
}
type KojiInitJob struct {
Server string `json:"server"`
Name string `json:"name"`