forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
51 lines (43 loc) · 1.13 KB
/
resource.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
package present
import (
"github.com/concourse/atc"
"github.com/concourse/atc/db"
"github.com/concourse/atc/web"
"github.com/tedsuo/rata"
)
func Resource(resource db.Resource, groups atc.GroupConfigs, showCheckError bool, teamName string) atc.Resource {
generator := rata.NewRequestGenerator("", web.Routes)
req, err := generator.CreateRequest(
web.GetResource,
rata.Params{
"resource": resource.Name(),
"team_name": teamName,
"pipeline_name": resource.PipelineName(),
},
nil,
)
if err != nil {
panic("failed to generate url: " + err.Error())
}
groupNames := []string{}
for _, group := range groups {
for _, name := range group.Resources {
if name == resource.Name() {
groupNames = append(groupNames, group.Name)
}
}
}
var checkErrString string
if resource.CheckError() != nil && showCheckError {
checkErrString = resource.CheckError().Error()
}
return atc.Resource{
Name: resource.Name(),
Type: resource.Type(),
Groups: groupNames,
URL: req.URL.String(),
Paused: resource.Paused(),
FailingToCheck: resource.FailingToCheck(),
CheckError: checkErrString,
}
}