forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
90 lines (70 loc) · 1.96 KB
/
types.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
package nodes
import (
"fmt"
"reflect"
osgraph "github.com/openshift/origin/pkg/api/graph"
buildapi "github.com/openshift/origin/pkg/build/api"
)
var (
BuildConfigNodeKind = reflect.TypeOf(buildapi.BuildConfig{}).Name()
BuildNodeKind = reflect.TypeOf(buildapi.Build{}).Name()
// non-api types
SourceRepositoryNodeKind = reflect.TypeOf(buildapi.BuildSource{}).Name()
)
func BuildConfigNodeName(o *buildapi.BuildConfig) osgraph.UniqueName {
return osgraph.GetUniqueRuntimeObjectNodeName(BuildConfigNodeKind, o)
}
type BuildConfigNode struct {
osgraph.Node
*buildapi.BuildConfig
}
func (n BuildConfigNode) Object() interface{} {
return n.BuildConfig
}
func (n BuildConfigNode) String() string {
return string(BuildConfigNodeName(n.BuildConfig))
}
func (n BuildConfigNode) ResourceString() string {
return "bc/" + n.Name
}
func (*BuildConfigNode) Kind() string {
return BuildConfigNodeKind
}
func SourceRepositoryNodeName(source buildapi.BuildSource) osgraph.UniqueName {
switch {
case source.Git != nil:
sourceType, uri, ref := "git", source.Git.URI, source.Git.Ref
return osgraph.UniqueName(fmt.Sprintf("%s|%s|%s#%s", SourceRepositoryNodeKind, sourceType, uri, ref))
default:
panic(fmt.Sprintf("invalid build source", source))
}
}
type SourceRepositoryNode struct {
osgraph.Node
Source buildapi.BuildSource
}
func (n SourceRepositoryNode) String() string {
return string(SourceRepositoryNodeName(n.Source))
}
func (SourceRepositoryNode) Kind() string {
return SourceRepositoryNodeKind
}
func BuildNodeName(o *buildapi.Build) osgraph.UniqueName {
return osgraph.GetUniqueRuntimeObjectNodeName(BuildNodeKind, o)
}
type BuildNode struct {
osgraph.Node
Build *buildapi.Build
}
func (n BuildNode) Object() interface{} {
return n.Build
}
func (n BuildNode) String() string {
return string(BuildNodeName(n.Build))
}
func (n BuildNode) ResourceString() string {
return "build/" + n.Build.Name
}
func (*BuildNode) Kind() string {
return BuildNodeKind
}