-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_builder_event.go
85 lines (73 loc) · 1.82 KB
/
ci_builder_event.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
package contracts
import (
"errors"
)
type BuildEventType string
const (
BuildEventTypeUnknown BuildEventType = ""
BuildEventTypeUpdateStatus BuildEventType = "updateStatus"
BuildEventTypeClean BuildEventType = "clean"
)
type EstafetteCiBuilderEvent struct {
BuildEventType BuildEventType `json:"buildEventType,omitempty"`
JobType JobType `json:"jobType,omitempty"`
JobName string `json:"job_name"`
PodName string `json:"pod_name,omitempty"`
Build *Build `json:"build,omitempty"`
Release *Release `json:"release,omitempty"`
Bot *Bot `json:"bot,omitempty"`
Git *GitConfig `json:"git,omitempty"`
}
func (bc *EstafetteCiBuilderEvent) Validate() (err error) {
if bc.Git == nil {
return errors.New("git needs to be set")
}
switch bc.JobType {
case JobTypeBuild:
if bc.Build == nil {
return errors.New("build needs to be set for jobType build")
}
case JobTypeRelease:
if bc.Release == nil {
return errors.New("release needs to be set for jobType release")
}
case JobTypeBot:
if bc.Bot == nil {
return errors.New("bot needs to be set for jobType bot")
}
}
return nil
}
func (bc *EstafetteCiBuilderEvent) GetStatus() Status {
switch bc.JobType {
case JobTypeBuild:
if bc.Build != nil {
return bc.Build.BuildStatus
}
case JobTypeRelease:
if bc.Release != nil {
return bc.Release.ReleaseStatus
}
case JobTypeBot:
if bc.Bot != nil {
return bc.Bot.BotStatus
}
}
return StatusUnknown
}
func (bc *EstafetteCiBuilderEvent) SetStatus(status Status) {
switch bc.JobType {
case JobTypeBuild:
if bc.Build != nil {
bc.Build.BuildStatus = status
}
case JobTypeRelease:
if bc.Release != nil {
bc.Release.ReleaseStatus = status
}
case JobTypeBot:
if bc.Bot != nil {
bc.Bot.BotStatus = status
}
}
}