-
Notifications
You must be signed in to change notification settings - Fork 248
/
jobs.go
129 lines (113 loc) · 3.42 KB
/
jobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package config
import (
prowconfig "k8s.io/test-infra/prow/config"
)
var (
SourceTypeLabel string = "pj-rehearse.openshift.io/source-type"
ChangedPresubmit SourceType = "changedPresubmit"
ChangedPeriodic SourceType = "changedPeriodic"
ChangedCiopConfig SourceType = "changedCiopConfig"
ChangedClusterProfile SourceType = "changedClusterProfile"
ChangedTemplate SourceType = "changedTemplate"
ChangedRegistryContent SourceType = "changedRegistryContent"
Unknown SourceType = "unknownSource"
)
type SourceType string
func GetSourceType(labels map[string]string) SourceType {
sourceType, ok := labels[SourceTypeLabel]
if !ok {
return Unknown
}
switch sourceType {
case "changedPresubmit":
return ChangedPresubmit
case "changedPeriodic":
return ChangedPeriodic
case "changedCiopConfig":
return ChangedCiopConfig
case "changedClusterProfile":
return ChangedClusterProfile
case "changedTemplate":
return ChangedTemplate
case "changedRegistryContent":
return ChangedRegistryContent
default:
return Unknown
}
}
func (sourceType SourceType) GetDisplayText() string {
switch sourceType {
case ChangedPresubmit:
return "Presubmit changed"
case ChangedPeriodic:
return "Periodic changed"
case ChangedCiopConfig:
return "Ci-operator config changed"
case ChangedClusterProfile:
return "Cluster Profile changed"
case ChangedTemplate:
return "Template changed"
case ChangedRegistryContent:
return "Registry content changed"
default:
return "Unknown change occurred"
}
}
type Presubmits map[string][]prowconfig.Presubmit
// AddAll adds all jobs from a different instance.
// The method assumes two jobs with a matching name for the same repository
// are identical, so if a presubmit with a given name already exists, it
// is kept as is.
func (p Presubmits) AddAll(jobs Presubmits, sourceType SourceType) {
for repo := range jobs {
if _, ok := p[repo]; !ok {
p[repo] = []prowconfig.Presubmit{}
}
for _, sourceJob := range jobs[repo] {
p.Add(repo, sourceJob, sourceType)
}
}
}
// Add a presubmit for a given repo.
// The method assumes two jobs with a matching name are identical, so if
// a presubmit with a given name already exists, it is kept as is.
func (p Presubmits) Add(repo string, job prowconfig.Presubmit, sourceType SourceType) {
for _, destJob := range p[repo] {
if destJob.Name == job.Name {
return
}
}
if len(job.Labels) == 0 {
job.Labels = make(map[string]string)
}
if _, ok := job.Labels[SourceTypeLabel]; !ok {
job.Labels[SourceTypeLabel] = string(sourceType)
}
p[repo] = append(p[repo], job)
}
type Periodics map[string]prowconfig.Periodic
// AddAll adds all jobs from a different instance.
// The method assumes two jobs with a matching name are identical,
// so if a periodic with a given name already exists, it
// is overridden.
func (p Periodics) AddAll(jobs Periodics, sourceType SourceType) {
for _, job := range jobs {
p.Add(job, sourceType)
}
}
// Add adds a job from a different instance.
// The method assumes two jobs with a matching name are identical,
// so if a periodic with a given name already exists, it
// is overridden.
func (p Periodics) Add(job prowconfig.Periodic, sourceType SourceType) {
if _, ok := p[job.Name]; ok {
return
}
if len(job.Labels) == 0 {
job.Labels = make(map[string]string)
}
if _, ok := job.Labels[SourceTypeLabel]; !ok {
job.Labels[SourceTypeLabel] = string(sourceType)
}
p[job.Name] = job
}