-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
types.go
207 lines (177 loc) · 5.42 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package github
import (
"strings"
)
// These are possible State entries for a Status.
const (
StatusPending = "pending"
StatusSuccess = "success"
StatusError = "error"
StatusFailure = "failure"
)
// Possible contents for reactions.
const (
ReactionThumbsUp = "+1"
ReactionThumbsDown = "-1"
ReactionLaugh = "laugh"
ReactionConfused = "confused"
ReactionHeart = "heart"
ReactionHooray = "hooray"
)
type Reaction struct {
Content string `json:"content"`
}
// Status is used to set a commit status line.
type Status struct {
State string `json:"state"`
TargetURL string `json:"target_url,omitempty"`
Description string `json:"description,omitempty"`
Context string `json:"context,omitempty"`
}
// User is a GitHub user account.
type User struct {
Login string `json:"login"`
Name string `json:"name"`
}
// PullRequestEvent is what GitHub sends us when a PR is changed.
type PullRequestEvent struct {
Action string `json:"action"`
Number int `json:"number"`
PullRequest PullRequest `json:"pull_request"`
Label Label `json:"label"`
}
// PullRequest contains information about a PullRequest.
type PullRequest struct {
Number int `json:"number"`
HTMLURL string `json:"html_url"`
User User `json:"user"`
Base PullRequestBranch `json:"base"`
Head PullRequestBranch `json:"head"`
Body string `json:"body"`
RequestedReviewers []User `json:"requested_reviewers"`
}
// PullRequestBranch contains information about a particular branch in a PR.
type PullRequestBranch struct {
Ref string `json:"ref"`
SHA string `json:"sha"`
Repo Repo `json:"repo"`
}
type Label struct {
URL string `json:"url"`
Name string `json:"name"`
Color string `json:"color"`
}
// PullRequestChange contains information about what a PR changed.
type PullRequestChange struct {
SHA string `json:"sha"`
Filename string `json:"filename"`
Status string `json:"added"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Changes int `json:"changes"`
Patch string `json:"patch"`
}
// Repo contains general repository information.
type Repo struct {
Owner User `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
HTMLURL string `json:"html_url"`
}
type IssueEvent struct {
Action string `json:"action"`
Issue Issue `json:"issue"`
Repo Repo `json:"repository"`
}
type IssueCommentEvent struct {
Action string `json:"action"`
Issue Issue `json:"issue"`
Comment IssueComment `json:"comment"`
Repo Repo `json:"repository"`
}
type Issue struct {
User User `json:"user"`
Number int `json:"number"`
Title string `json:"title"`
State string `json:"state"`
HTMLURL string `json:"html_url"`
Labels []Label `json:"labels"`
Assignees []User `json:"assignees"`
Body string `json:"body"`
// This will be non-nil if it is a pull request.
PullRequest *struct{} `json:"pull_request,omitempty"`
}
func (i Issue) IsAssignee(login string) bool {
for _, assignee := range i.Assignees {
if login == assignee.Login {
return true
}
}
return false
}
func (i Issue) IsAuthor(login string) bool {
return i.User.Login == login
}
func (i Issue) IsPullRequest() bool {
return i.PullRequest != nil
}
func (i Issue) HasLabel(labelToFind string) bool {
for _, label := range i.Labels {
if strings.ToLower(label.Name) == strings.ToLower(labelToFind) {
return true
}
}
return false
}
type IssueComment struct {
ID int `json:"id,omitempty"`
Body string `json:"body"`
User User `json:"user,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
}
type StatusEvent struct {
SHA string `json:"sha,omitempty"`
State string `json:"state,omitempty"`
Description string `json:"description,omitempty"`
TargetURL string `json:"target_url,omitempty"`
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Context string `json:"context,omitempty"`
Sender User `json:"sender,omitempty"`
Repo Repo `json:"repository,omitempty"`
}
// IssuesSearchResult represents the result of an issues search.
type IssuesSearchResult struct {
Total int `json:"total_count,omitempty"`
Issues []Issue `json:"items,omitempty"`
}
type PushEvent struct {
Ref string `json:"ref"`
Before string `json:"before"`
After string `json:"after"`
Commits []Commit `json:"commits"`
Repo Repo `json:"repository"`
}
func (pe PushEvent) Branch() string {
refs := strings.Split(pe.Ref, "/")
return refs[len(refs)-1]
}
type Commit struct {
ID string `json:"id"`
Message string `json:"message"`
Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`
}