forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
134 lines (104 loc) · 2.51 KB
/
job.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
130
131
132
133
134
package config
import "github.com/concourse/atc"
// these are expressly tucked away so as to avoid accidental use in public API
// endpoints as that could leak credentials
type JobInput struct {
Name string
Resource string
Passed []string
Trigger bool
Version *atc.VersionConfig
Params atc.Params
Tags atc.Tags
}
type JobOutput struct {
Name string
Resource string
}
func JobInputs(config atc.JobConfig) []JobInput {
return collectInputs(atc.PlanConfig{Do: &config.Plan})
}
func JobOutputs(config atc.JobConfig) []JobOutput {
return collectOutputs(atc.PlanConfig{Do: &config.Plan})
}
func collectInputs(plan atc.PlanConfig) []JobInput {
var inputs []JobInput
if plan.Success != nil {
inputs = append(inputs, collectInputs(*plan.Success)...)
}
if plan.Failure != nil {
inputs = append(inputs, collectInputs(*plan.Failure)...)
}
if plan.Ensure != nil {
inputs = append(inputs, collectInputs(*plan.Ensure)...)
}
if plan.Try != nil {
inputs = append(inputs, collectInputs(*plan.Try)...)
}
if plan.Do != nil {
for _, p := range *plan.Do {
inputs = append(inputs, collectInputs(p)...)
}
}
if plan.Aggregate != nil {
for _, p := range *plan.Aggregate {
inputs = append(inputs, collectInputs(p)...)
}
}
if plan.Get != "" {
get := plan.Get
resource := get
if plan.Resource != "" {
resource = plan.Resource
}
inputs = append(inputs, JobInput{
Name: get,
Resource: resource,
Passed: plan.Passed,
Version: plan.Version,
Trigger: plan.Trigger,
Params: plan.Params,
Tags: plan.Tags,
})
}
return inputs
}
func collectOutputs(plan atc.PlanConfig) []JobOutput {
var outputs []JobOutput
if plan.Success != nil {
outputs = append(outputs, collectOutputs(*plan.Success)...)
}
if plan.Failure != nil {
outputs = append(outputs, collectOutputs(*plan.Failure)...)
}
if plan.Ensure != nil {
outputs = append(outputs, collectOutputs(*plan.Ensure)...)
}
if plan.Try != nil {
outputs = append(outputs, collectOutputs(*plan.Try)...)
}
if plan.Do != nil {
for _, p := range *plan.Do {
outputs = append(outputs, collectOutputs(p)...)
}
}
if plan.Aggregate != nil {
var outputs []JobOutput
for _, p := range *plan.Aggregate {
outputs = append(outputs, collectOutputs(p)...)
}
return outputs
}
if plan.Put != "" {
put := plan.Put
resource := put
if plan.Resource != "" {
resource = plan.Resource
}
outputs = append(outputs, JobOutput{
Name: put,
Resource: resource,
})
}
return outputs
}