forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
86 lines (74 loc) · 1.91 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
package present
import (
"github.com/concourse/atc"
"github.com/concourse/atc/config"
"github.com/concourse/atc/db"
"github.com/concourse/atc/web"
"github.com/tedsuo/rata"
)
func Job(
teamName string,
job db.SavedJob,
groups atc.GroupConfigs,
finishedBuild db.Build,
nextBuild db.Build,
) atc.Job {
generator := rata.NewRequestGenerator("", web.Routes)
req, err := generator.CreateRequest(
web.GetJob,
rata.Params{
"job": job.Name,
"pipeline_name": job.PipelineName,
"team_name": teamName,
},
nil,
)
if err != nil {
panic("failed to generate url: " + err.Error())
}
var presentedNextBuild, presentedFinishedBuild *atc.Build
if nextBuild != nil {
presented := Build(nextBuild)
presentedNextBuild = &presented
}
if finishedBuild != nil {
presented := Build(finishedBuild)
presentedFinishedBuild = &presented
}
groupNames := []string{}
for _, group := range groups {
for _, name := range group.Jobs {
if name == job.Name {
groupNames = append(groupNames, group.Name)
}
}
}
sanitizedInputs := []atc.JobInput{}
for _, input := range config.JobInputs(job.Config) {
sanitizedInputs = append(sanitizedInputs, atc.JobInput{
Name: input.Name,
Resource: input.Resource,
Passed: input.Passed,
Trigger: input.Trigger,
})
}
sanitizedOutputs := []atc.JobOutput{}
for _, output := range config.JobOutputs(job.Config) {
sanitizedOutputs = append(sanitizedOutputs, atc.JobOutput{
Name: output.Name,
Resource: output.Resource,
})
}
return atc.Job{
Name: job.Name,
URL: req.URL.String(),
DisableManualTrigger: job.Config.DisableManualTrigger,
Paused: job.Paused,
FirstLoggedBuildID: job.FirstLoggedBuildID,
FinishedBuild: presentedFinishedBuild,
NextBuild: presentedNextBuild,
Inputs: sanitizedInputs,
Outputs: sanitizedOutputs,
Groups: groupNames,
}
}