Merge: fix ci nitunit some
[nit.git] / lib / github / events.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Events are emitted by Github Hooks.
16 #
17 # See <https://developer.github.com/v3/activity/events/types/>
18 module events
19
20 import api
21 intrude import json
22
23 # Github event stub.
24 class GithubEvent
25 serialize
26
27 # Event ID from Github.
28 var id: nullable String is writable
29
30 # Action performed by the event.
31 var action: nullable String is writable
32
33 # Repo where this event occured.
34 var repo: Repo is writable
35 end
36
37 # Triggered when a commit comment is created.
38 class CommitCommentEvent
39 super GithubEvent
40 serialize
41
42 # The `Comment` itself.
43 var comment: CommitComment is writable
44 end
45
46 # Triggered when a repository, branch, or tag is created.
47 class CreateEvent
48 super GithubEvent
49 serialize
50
51 # Oject type that was created.
52 #
53 # Can be one of `repository`, `branch`, or `tag`.
54 var ref_type: String is writable
55
56 # Git ref (or null if only a repository was created).
57 var ref: String is writable
58
59 # Name of the repo's default branch (usually master).
60 var master_branch: String is writable
61
62 # Repo's current description.
63 var description: nullable String is writable
64 end
65
66 # Triggered when a branch or a tag is deleted.
67 class DeleteEvent
68 super GithubEvent
69 serialize
70
71 # Object type that was deleted.
72 #
73 # Can be one of `repository`, `branch`, or `tag`.
74 var ref_type: String is writable
75
76 # Git ref (or null if only a repository was deleted).
77 var ref: String is writable
78 end
79
80 # Triggered when a new snapshot is deployed.
81 #
82 # Deployement are mainly used with integration testing servers.
83 class DeploymentEvent
84 super GithubEvent
85 serialize
86
87 # Commit SHA for which this deployment was created.
88 var sha: String is writable
89
90 # Name of repository for this deployment, formatted as :owner/:repo.
91 var name: String is writable
92
93 # Optional extra information for this deployment.
94 var payload: nullable String is writable
95
96 # Optional environment to deploy to.
97 # Default: "production"
98 var environment: nullable String is writable
99
100 # Optional human-readable description added to the deployment.
101 var description: nullable String is writable
102 end
103
104 # Triggered when a deployement's status changes.
105 class DeploymentStatusEvent
106 super GithubEvent
107 serialize
108
109 # New deployment state.
110 #
111 # Can be `pending`, `success`, `failure`, or `error`.
112 var state: String is writable
113
114 # Optional link added to the status.
115 var target_url: nullable String is writable
116
117 # Deployment hash that this status is associated with.
118 var deployment: String is writable
119
120 # Optional human-readable description added to the status.
121 var description: nullable String is writable
122 end
123
124 # Triggered when a user forks a repository.
125 class ForkEvent
126 super GithubEvent
127 serialize
128
129 # Created repository.
130 var forkee: Repo is writable
131 end
132
133 # Triggered when an issue comment is created.
134 class IssueCommentEvent
135 super GithubEvent
136 serialize
137
138 # `Issue` the comment belongs to.
139 var issue: Issue is writable
140
141 # The `Comment` itself.
142 var comment: IssueComment is writable
143 end
144
145 # Triggered when an event occurs on an issue.
146 #
147 # Triggered when an issue is assigned, unassigned, labeled, unlabeled,
148 # opened, closed or reopened.
149 class IssuesEvent
150 super GithubEvent
151 serialize
152
153 # The `Issue` itself.
154 var issue: Issue is writable
155
156 # Optional `Label` that was added or removed from the issue.
157 var lbl: nullable Label is writable, serialize_as("label")
158
159 # Optional `User` that was assigned or unassigned from the issue.
160 var assignee: nullable User is writable
161 end
162
163 # Triggered when a user is added as a collaborator to a repository.
164 class MemberEvent
165 super GithubEvent
166 serialize
167
168 # `User` that was added.
169 var member: User is writable
170 end
171
172 # Triggered when an event occurs on a pull request.
173 #
174 # Triggered when a pull request is assigned, unassigned,
175 # labeled, unlabeled, opened, closed, reopened, or synchronized.
176 class PullRequestEvent
177 super GithubEvent
178 serialize
179
180 # The pull request number.
181 var number: Int is writable
182
183 # The `PullRequest` itself.
184 var pull: PullRequest is writable
185 end
186
187 # Triggered when a comment is created on a pull request diff.
188 class PullRequestPullCommentEvent
189 super GithubEvent
190 serialize
191
192 # The `Comment` itself.
193 var comment: PullComment is writable
194
195 # `PullRequest` the `comment` belongs to.
196 var pull: PullRequest is writable
197 end
198
199 # Triggered when a repository branch is pushed to.
200 class PushEvent
201 super GithubEvent
202 serialize
203
204 # SHA of the HEAD commit on the repository.
205 var head_commit: Commit is writable
206
207 # Full Git ref that was pushed.
208 #
209 # Example: “refs/heads/master”
210 var ref: String is writable
211
212 # Number of commits in the push.
213 var size: nullable Int is writable
214
215 # Array of pushed commits.
216 var commits = new Array[Commit] is writable, optional
217 end
218
219 # Triggered when the status of a Git commit changes.
220 class StatusEvent
221 super GithubEvent
222 serialize
223
224 # The `Commit` itself.
225 var sha: String is writable
226
227 # New state.
228 #
229 # Can be `pending`, `success`, `failure`, or `error`.
230 var state: String is writable
231
232 # Optional human-readable description added to the status.
233 var description: nullable String is writable
234
235 # Optional link added to the status.
236 var target_url: nullable String is writable
237
238 # Array of branches containing the status' SHA.
239 #
240 # Each branch contains the given SHA,
241 # but the SHA may or may not be the head of the branch.
242 #
243 # The array includes a maximum of 10 branches.
244 var branches = new Array[Branch] is writable, optional
245 end
246
247 redef class GithubDeserializer
248
249 redef fun class_name_heuristic(json_object) do
250 if json_object.has_key("action") and json_object.has_key("commit") and json_object.has_key("comment") then
251 return "CommitCommentEvent"
252 else if json_object.has_key("ref") and json_object.has_key("master_branch") then
253 return "CreateEvent"
254 else if json_object.has_key("ref") and json_object.has_key("ref_type") then
255 return "DeleteEvent"
256 else if json_object.has_key("action") and json_object.has_key("sha") then
257 return "DeploymentEvent"
258 else if json_object.has_key("action") and json_object.has_key("state") then
259 return "DeploymentStatusEvent"
260 else if json_object.has_key("action") and json_object.has_key("forkee") then
261 return "ForkEvent"
262 else if json_object.has_key("action") and json_object.has_key("issue") and json_object.has_key("comment") then
263 return "IssueCommentEvent"
264 else if json_object.has_key("action") and json_object.has_key("issue") then
265 return "IssuesEvent"
266 else if json_object.has_key("action") and json_object.has_key("member") then
267 return "MemberEvent"
268 else if json_object.has_key("action") and json_object.has_key("number") then
269 return "PullRequestEvent"
270 else if json_object.has_key("action") and json_object.has_key("pull") and json_object.has_key("comment") then
271 return "PullRequestPullCommentEvent"
272 else if json_object.has_key("head_commit") and json_object.has_key("commits") then
273 return "PushEvent"
274 else if json_object.has_key("action") and json_object.has_key("branches") then
275 return "StatusEvent"
276 else if json_object.has_key("action") and json_object.has_key("issue") then
277 return "GithubEvent"
278 end
279 return super
280 end
281 end