-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
101 lines (89 loc) · 2.41 KB
/
models.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
package resource
import (
"errors"
"strconv"
"time"
"github.com/shurcooL/githubv4"
)
// Source represents the configuration for the resource.
type Source struct {
Repository string `json:"repository"`
AccessToken string `json:"access_token"`
V3Endpoint string `json:"v3_endpoint"`
V4Endpoint string `json:"v4_endpoint"`
Paths []string `json:"path"`
IgnorePaths []string `json:"ignore_path"`
DisableCISkip string `json:"disable_ci_skip"`
}
// Validate the source configuration.
func (s *Source) Validate() error {
if s.AccessToken == "" {
return errors.New("access_token must be set")
}
if s.Repository == "" {
return errors.New("repository must be set")
}
if s.V3Endpoint != "" && s.V4Endpoint == "" {
return errors.New("v4_endpoint must be set together with v3_endpoint")
}
if s.V4Endpoint != "" && s.V3Endpoint == "" {
return errors.New("v3_endpoint must be set together with v4_endpoint")
}
return nil
}
// Metadata output from get/put steps.
type Metadata []*MetadataField
// Add a MetadataField to the Metadata.
func (m *Metadata) Add(name, value string) {
*m = append(*m, &MetadataField{Name: name, Value: value})
}
// MetadataField ...
type MetadataField struct {
Name string `json:"name"`
Value string `json:"value"`
}
// Version communicated with Concourse. ID is the Github Global ID.
type Version struct {
PR string `json:"pr"`
Commit string `json:"commit"`
CommittedDate time.Time `json:"committed,omitempty"`
}
// NewVersion constructs a new Version.
func NewVersion(p *PullRequest) Version {
return Version{
PR: strconv.Itoa(p.Number),
Commit: p.Tip.OID,
CommittedDate: p.Tip.CommittedDate.Time,
}
}
// PullRequest represents a pull request and includes the tip (commit).
type PullRequest struct {
PullRequestObject
Tip CommitObject
}
// PullRequestObject represents the GraphQL commit node.
// https://developer.github.com/v4/object/commit/
type PullRequestObject struct {
ID string
Number int
Title string
URL string
BaseRefName string
HeadRefName string
Repository struct {
URL string
}
}
// CommitObject represents the GraphQL commit node.
// https://developer.github.com/v4/object/commit/
type CommitObject struct {
ID string
OID string
CommittedDate githubv4.DateTime
Message string
Author struct {
User struct {
Login string
}
}
}