1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Events are emitted by Github Hooks.
17 # See <https://developer.github.com/v3/activity/events/types/>
28 # Json representation of `self`.
29 var json
: JsonObject is noinit
35 # Init `self` from a `json` object.
36 init from_json
(api
: GithubAPI, json
: JsonObject) do
41 # Event ID from Github.
42 fun id
: String do return json
["id"].as(String)
45 fun id
=(id
: String) do json
["id"] = id
47 # Action performed by the event.
48 fun action
: String do return json
["action"].as(String)
51 fun action
=(action
: String) do json
["action"] = action
53 # Repo where this event occured.
55 return new Repo.from_json
(api
, json
["repository"].as(JsonObject))
59 fun repo
=(repo
: Repo) do json
["repository"] = repo
.json
62 # Triggered when a commit comment is created.
63 class CommitCommentEvent
66 # The `Comment` itself.
67 fun comment
: CommitComment do
68 return new CommitComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
72 fun comment
=(comment
: CommitComment) do json
["comment"] = comment
.json
75 # Triggered when a repository, branch, or tag is created.
79 # Oject type that was created.
81 # Can be one of `repository`, `branch`, or `tag`.
82 fun ref_type
: String do return json
["ref_type"].as(String)
85 fun ref_type
=(ref_type
: String) do json
["ref_type"] = ref_type
87 # Git ref (or null if only a repository was created).
88 fun ref
: String do return json
["ref"].as(String)
91 fun ref
=(ref
: String) do json
["ref"] = ref
93 # Name of the repo's default branch (usually master).
94 fun master_branch
: String do return json
["master_branch"].as(String)
97 fun master_branch
=(master_branch
: String) do json
["master_branch"] = master_branch
99 # Repo's current description.
100 fun description
: String do return json
["description"].as(String)
103 fun description
=(description
: String) do json
["description"] = description
106 # Triggered when a branch or a tag is deleted.
110 # Object type that was deleted.
112 # Can be one of `repository`, `branch`, or `tag`.
113 fun ref_type
: String do return json
["ref_type"].as(String)
116 fun ref_type
=(ref_type
: String) do json
["ref_type"] = ref_type
118 # Git ref (or null if only a repository was deleted).
119 fun ref
: String do return json
["ref"].as(String)
122 fun ref
=(ref
: String) do json
["ref"] = ref
125 # Triggered when a new snapshot is deployed.
127 # Deployement are mainly used with integration testing servers.
128 class DeploymentEvent
131 # Commit SHA for which this deployment was created.
132 fun sha
: String do return json
["sha"].as(String)
135 fun sha
=(sha
: String) do json
["sha"] = sha
137 # Name of repository for this deployment, formatted as :owner/:repo.
138 fun name
: String do return json
["name"].as(String)
141 fun name
=(name
: String) do json
["name"] = name
143 # Optional extra information for this deployment.
144 fun payload
: nullable String do
145 var res
= json
.get_or_null
("payload")
146 if res
isa String then return res
else return null
150 fun payload
=(payload
: nullable String) do json
["payload"] = payload
152 # Optional environment to deploy to.
153 # Default: "production"
154 fun environment
: nullable String do
155 var res
= json
.get_or_null
("environment")
156 if res
isa String then return res
else return null
160 fun environment
=(environment
: nullable String) do json
["environment"] = environment
162 # Optional human-readable description added to the deployment.
163 fun description
: nullable String do
164 var res
= json
.get_or_null
("description")
165 if res
isa String then return res
else return null
169 fun description
=(description
: nullable String) do json
["description"] = description
172 # Triggered when a deployement's status changes.
173 class DeploymentStatusEvent
176 # New deployment state.
178 # Can be `pending`, `success`, `failure`, or `error`.
179 fun state
: String do return json
["state"].as(String)
181 # Optional link added to the status.
182 fun target_url
: nullable String do
183 var res
= json
.get_or_null
("target_url")
184 if res
isa String then return res
else return null
188 fun target_url
=(target_url
: nullable String) do json
["target_url"] = target_url
190 # Deployment hash that this status is associated with.
191 fun deployment
: String do return json
["deployment"].as(String)
194 fun deployment
=(deployment
: String) do json
["deployment"] = deployment
196 # Optional human-readable description added to the status.
197 fun description
: nullable String do
198 var res
= json
.get_or_null
("description")
199 if res
isa String then return res
else return null
203 fun description
=(description
: nullable String) do json
["description"] = description
206 # Triggered when a user forks a repository.
210 # Created repository.
211 fun forkee
: Repo do return new Repo.from_json
(api
, json
["forkee"].as(JsonObject))
214 fun forkee
=(forkee
: Repo) do json
["forkee"] = forkee
.json
217 # Triggered when an issue comment is created.
218 class IssueCommentEvent
221 # `Issue` the comment belongs to.
223 return new Issue.from_json
(api
, repo
, json
["issue"].as(JsonObject))
227 fun issue
=(issue
: Issue) do json
["issue"] = issue
.json
229 # The `Comment` itself.
230 fun comment
: IssueComment do
231 return new IssueComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
235 fun comment
=(comment
: IssueComment) do json
["comment"] = comment
.json
238 # Triggered when an event occurs on an issue.
240 # Triggered when an issue is assigned, unassigned, labeled, unlabeled,
241 # opened, closed or reopened.
245 # The `Issue` itself.
246 fun issue
: Issue do return new Issue.from_json
(api
, repo
, json
["issue"].as(JsonObject))
249 fun issue
=(issue
: Issue) do json
["issue"] = issue
.json
251 # Optional `Label` that was added or removed from the issue.
252 fun lbl
: nullable Label do
253 var res
= json
.get_or_null
("label")
254 if res
isa JsonObject then return new Label.from_json
(api
, repo
, res
) else return null
258 fun lbl
=(lbl
: nullable Label) do
262 json
["lbl"] = lbl
.json
266 # Optional `User` that was assigned or unassigned from the issue.
267 fun assignee
: nullable User do
268 var res
= json
.get_or_null
("assignee")
269 if res
isa JsonObject then return new User.from_json
(api
, res
) else return null
273 fun assignee
=(assignee
: nullable User) do
274 if assignee
== null then
275 json
["assignee"] = null
277 json
["assignee"] = assignee
.json
282 # Triggered when a user is added as a collaborator to a repository.
286 # `User` that was added.
287 fun member
: User do return new User.from_json
(api
, json
["member"].as(JsonObject))
290 fun member
=(member
: User) do json
["member"] = member
.json
293 # Triggered when an event occurs on a pull request.
295 # Triggered when a pull request is assigned, unassigned,
296 # labeled, unlabeled, opened, closed, reopened, or synchronized.
297 class PullRequestEvent
300 # The pull request number.
301 fun number
: Int do return json
["number"].as(Int)
304 fun number
=(number
: Int) do json
["number"] = number
306 # The `PullRequest` itself.
307 fun pull
: PullRequest do
308 return new PullRequest.from_json
(api
, repo
, json
["pull_request"].as(JsonObject))
312 fun pull
=(pull
: PullRequest) do json
["pull_request"] = pull
.json
315 # Triggered when a comment is created on a pull request diff.
316 class PullRequestReviewCommentEvent
319 # The `Comment` itself.
320 fun comment
: ReviewComment do
321 return new ReviewComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
325 fun comment
=(comment
: ReviewComment) do json
["comment"] = comment
.json
327 # `PullRequest` the `comment` belongs to.
328 fun pull
: PullRequest do
329 return new PullRequest.from_json
(api
, repo
, json
["pull_request"].as(JsonObject))
333 fun pull
=(pull
: PullRequest) do json
["pull_request"] = pull
.json
336 # Triggered when a repository branch is pushed to.
340 # SHA of the HEAD commit on the repository.
341 fun head
: String do return json
["head"].as(String)
344 fun head
=(head
: String) do json
["head"] = head
346 # Full Git ref that was pushed.
348 # Example: “refs/heads/master”
349 fun ref
: String do return json
["ref"].as(String)
352 fun ref
=(ref
: String) do json
["ref"] = ref
354 # Number of commits in the push.
355 fun size
: Int do return json
["size"].as(Int)
358 fun size
=(size
: Int) do json
["size"] = size
360 # Array of pushed commits.
361 fun commits
: Array[Commit] do
362 var res
= new Array[Commit]
363 var arr
= json
["commits"].as(JsonArray)
365 if not obj
isa JsonObject then continue
366 res
.add api
.load_commit
(repo
, obj
["sha"].as(String)).as(not null)
372 fun commits
=(commits
: Array[Commit]) do
373 var arr
= new JsonArray
374 for commit
in commits
do arr
.add commit
.json
375 json
["commits"] = arr
379 # Triggered when the status of a Git commit changes.
383 # The `Commit` itself.
384 fun commit
: Commit do
385 return api
.load_commit
(repo
, json
["sha"].as(String)).as(not null)
389 fun commit
=(commit
: Commit) do json
["sha"] = commit
.sha
393 # Can be `pending`, `success`, `failure`, or `error`.
394 fun state
: String do return json
["state"].as(String)
397 fun state
=(state
: String) do json
["state"] = state
399 # Optional human-readable description added to the status.
400 fun description
: nullable String do
401 var res
= json
.get_or_null
("description")
402 if res
isa String then return res
else return null
406 fun description
=(description
: nullable String) do json
["description"] = description
408 # Optional link added to the status.
409 fun target_url
: nullable String do
410 var res
= json
.get_or_null
("target_url")
411 if res
isa String then return res
else return null
415 fun target_url
=(target_url
: nullable String) do json
["target_url"] = target_url
417 # Array of branches containing the status' SHA.
419 # Each branch contains the given SHA,
420 # but the SHA may or may not be the head of the branch.
422 # The array includes a maximum of 10 branches.
423 fun branches
: Array[Branch] do
424 var res
= new Array[Branch]
425 var arr
= json
["branches"].as(JsonArray)
427 if not obj
isa JsonObject then continue
428 res
.add api
.load_branch
(repo
, obj
["name"].as(String)).as(not null)
434 fun branches
=(branches
: Array[Commit]) do
435 var arr
= new JsonArray
436 for branch
in branches
do arr
.add branch
.json
437 json
["branches"] = arr