forked from vmware-archive/atc
/
job.go
74 lines (62 loc) · 1.7 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
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(dbJob db.SavedJob, job atc.JobConfig, groups atc.GroupConfigs, finishedBuild, nextBuild *db.Build) atc.Job {
generator := rata.NewRequestGenerator("", web.Routes)
req, err := generator.CreateRequest(
web.GetJob,
rata.Params{"job": job.Name, "pipeline_name": dbJob.PipelineName},
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) {
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) {
sanitizedOutputs = append(sanitizedOutputs, atc.JobOutput{
Name: output.Name,
Resource: output.Resource,
})
}
return atc.Job{
Name: job.Name,
URL: req.URL.String(),
Paused: dbJob.Paused,
FinishedBuild: presentedFinishedBuild,
NextBuild: presentedNextBuild,
Inputs: sanitizedInputs,
Outputs: sanitizedOutputs,
Groups: groupNames,
}
}