-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
122 lines (108 loc) · 3.21 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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:"paths"`
IgnorePaths []string `json:"ignore_paths"`
DisableCISkip bool `json:"disable_ci_skip"`
SkipSSLVerification bool `json:"skip_ssl_verification"`
DisableForks bool `json:"disable_forks"`
GitCryptKey string `json:"git_crypt_key"`
BaseBranch string `json:"base_branch"`
RequiredReviewApprovals int `json:"required_review_approvals"`
Labels []string `json:"labels"`
}
// 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.
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
ApprovedReviewCount int
Labels []LabelObject
}
// PullRequestObject represents the GraphQL commit node.
// https://developer.github.com/v4/object/pullrequest/
type PullRequestObject struct {
ID string
Number int
Title string
URL string
BaseRefName string
HeadRefName string
Repository struct {
URL string
}
IsCrossRepository bool
}
// 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
}
}
}
// ChangedFileObject represents the GraphQL FilesChanged node.
// https://developer.github.com/v4/object/pullrequestchangedfile/
type ChangedFileObject struct {
Path string
}
// LabelObject represents the GraphQL label node.
// https://developer.github.com/v4/object/label
type LabelObject struct {
Name string
}