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