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 # Action performed by the event.
42 fun action
: String do return json
["action"].as(String)
45 fun action
=(action
: String) do json
["action"] = action
47 # Repo where this event occured.
49 return new Repo.from_json
(api
, json
["repository"].as(JsonObject))
53 fun repo
=(repo
: Repo) do json
["repository"] = repo
.json
56 # Triggered when a commit comment is created.
57 class CommitCommentEvent
60 # The `Comment` itself.
61 fun comment
: CommitComment do
62 return new CommitComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
66 fun comment
=(comment
: CommitComment) do json
["comment"] = comment
.json
69 # Triggered when a repository, branch, or tag is created.
73 # Oject type that was created.
75 # Can be one of `repository`, `branch`, or `tag`.
76 fun ref_type
: String do return json
["ref_type"].as(String)
79 fun ref_type
=(ref_type
: String) do json
["ref_type"] = ref_type
81 # Git ref (or null if only a repository was created).
82 fun ref
: String do return json
["ref"].as(String)
85 fun ref
=(ref
: String) do json
["ref"] = ref
87 # Name of the repo's default branch (usually master).
88 fun master_branch
: String do return json
["master_branch"].as(String)
91 fun master_branch
=(master_branch
: String) do json
["master_branch"] = master_branch
93 # Repo's current description.
94 fun description
: String do return json
["description"].as(String)
97 fun description
=(description
: String) do json
["description"] = description
100 # Triggered when a branch or a tag is deleted.
104 # Object type that was deleted.
106 # Can be one of `repository`, `branch`, or `tag`.
107 fun ref_type
: String do return json
["ref_type"].as(String)
110 fun ref_type
=(ref_type
: String) do json
["ref_type"] = ref_type
112 # Git ref (or null if only a repository was deleted).
113 fun ref
: String do return json
["ref"].as(String)
116 fun ref
=(ref
: String) do json
["ref"] = ref
119 # Triggered when a new snapshot is deployed.
121 # Deployement are mainly used with integration testing servers.
122 class DeploymentEvent
125 # Commit SHA for which this deployment was created.
126 fun sha
: String do return json
["sha"].as(String)
129 fun sha
=(sha
: String) do json
["sha"] = sha
131 # Name of repository for this deployment, formatted as :owner/:repo.
132 fun name
: String do return json
["name"].as(String)
135 fun name
=(name
: String) do json
["name"] = name
137 # Optional extra information for this deployment.
138 fun payload
: nullable String do
139 var res
= json
.get_or_null
("payload")
140 if res
isa String then return res
else return null
144 fun payload
=(payload
: nullable String) do json
["payload"] = payload
146 # Optional environment to deploy to.
147 # Default: "production"
148 fun environment
: nullable String do
149 var res
= json
.get_or_null
("environment")
150 if res
isa String then return res
else return null
154 fun environment
=(environment
: nullable String) do json
["environment"] = environment
156 # Optional human-readable description added to the deployment.
157 fun description
: nullable String do
158 var res
= json
.get_or_null
("description")
159 if res
isa String then return res
else return null
163 fun description
=(description
: nullable String) do json
["description"] = description
166 # Triggered when a deployement's status changes.
167 class DeploymentStatusEvent
170 # New deployment state.
172 # Can be `pending`, `success`, `failure`, or `error`.
173 fun state
: String do return json
["state"].as(String)
175 # Optional link added to the status.
176 fun target_url
: nullable String do
177 var res
= json
.get_or_null
("target_url")
178 if res
isa String then return res
else return null
182 fun target_url
=(target_url
: nullable String) do json
["target_url"] = target_url
184 # Deployment hash that this status is associated with.
185 fun deployment
: String do return json
["deployment"].as(String)
188 fun deployment
=(deployment
: String) do json
["deployment"] = deployment
190 # Optional human-readable description added to the status.
191 fun description
: nullable String do
192 var res
= json
.get_or_null
("description")
193 if res
isa String then return res
else return null
197 fun description
=(description
: nullable String) do json
["description"] = description
200 # Triggered when a user forks a repository.
204 # Created repository.
205 fun forkee
: Repo do return new Repo.from_json
(api
, json
["forkee"].as(JsonObject))
208 fun forkee
=(forkee
: Repo) do json
["forkee"] = forkee
.json
211 # Triggered when an issue comment is created.
212 class IssueCommentEvent
215 # `Issue` the comment belongs to.
217 return new Issue.from_json
(api
, repo
, json
["issue"].as(JsonObject))
221 fun issue
=(issue
: Issue) do json
["issue"] = issue
.json
223 # The `Comment` itself.
224 fun comment
: IssueComment do
225 return new IssueComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
229 fun comment
=(comment
: IssueComment) do json
["comment"] = comment
.json
232 # Triggered when an event occurs on an issue.
234 # Triggered when an issue is assigned, unassigned, labeled, unlabeled,
235 # opened, closed or reopened.
239 # The `Issue` itself.
240 fun issue
: Issue do return new Issue.from_json
(api
, repo
, json
["issue"].as(JsonObject))
243 fun issue
=(issue
: Issue) do json
["issue"] = issue
.json
245 # Optional `Label` that was added or removed from the issue.
246 fun lbl
: nullable Label do
247 var res
= json
.get_or_null
("label")
248 if res
isa JsonObject then return new Label.from_json
(api
, repo
, res
) else return null
252 fun lbl
=(lbl
: nullable Label) do
256 json
["lbl"] = lbl
.json
260 # Optional `User` that was assigned or unassigned from the issue.
261 fun assignee
: nullable User do
262 var res
= json
.get_or_null
("assignee")
263 if res
isa JsonObject then return new User.from_json
(api
, res
) else return null
267 fun assignee
=(assignee
: nullable User) do
268 if assignee
== null then
269 json
["assignee"] = null
271 json
["assignee"] = assignee
.json
276 # Triggered when a user is added as a collaborator to a repository.
280 # `User` that was added.
281 fun member
: User do return new User.from_json
(api
, json
["member"].as(JsonObject))
284 fun member
=(member
: User) do json
["member"] = member
.json
287 # Triggered when an event occurs on a pull request.
289 # Triggered when a pull request is assigned, unassigned,
290 # labeled, unlabeled, opened, closed, reopened, or synchronized.
291 class PullRequestEvent
294 # The pull request number.
295 fun number
: Int do return json
["number"].as(Int)
298 fun number
=(number
: Int) do json
["number"] = number
300 # The `PullRequest` itself.
301 fun pull
: PullRequest do
302 return new PullRequest.from_json
(api
, repo
, json
["pull_request"].as(JsonObject))
306 fun pull
=(pull
: PullRequest) do json
["pull_request"] = pull
.json
309 # Triggered when a comment is created on a pull request diff.
310 class PullRequestReviewCommentEvent
313 # The `Comment` itself.
314 fun comment
: ReviewComment do
315 return new ReviewComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
319 fun comment
=(comment
: ReviewComment) do json
["comment"] = comment
.json
321 # `PullRequest` the `comment` belongs to.
322 fun pull
: PullRequest do
323 return new PullRequest.from_json
(api
, repo
, json
["pull_request"].as(JsonObject))
327 fun pull
=(pull
: PullRequest) do json
["pull_request"] = pull
.json
330 # Triggered when a repository branch is pushed to.
334 # SHA of the HEAD commit on the repository.
335 fun head
: String do return json
["head"].as(String)
338 fun head
=(head
: String) do json
["head"] = head
340 # Full Git ref that was pushed.
342 # Example: “refs/heads/master”
343 fun ref
: String do return json
["ref"].as(String)
346 fun ref
=(ref
: String) do json
["ref"] = ref
348 # Number of commits in the push.
349 fun size
: Int do return json
["size"].as(Int)
352 fun size
=(size
: Int) do json
["size"] = size
354 # Array of pushed commits.
355 fun commits
: Array[Commit] do
356 var res
= new Array[Commit]
357 var arr
= json
["commits"].as(JsonArray)
359 if not obj
isa JsonObject then continue
360 res
.add api
.load_commit
(repo
, obj
["sha"].as(String)).as(not null)
366 fun commits
=(commits
: Array[Commit]) do
367 var arr
= new JsonArray
368 for commit
in commits
do arr
.add commit
.json
369 json
["commits"] = arr
373 # Triggered when the status of a Git commit changes.
377 # The `Commit` itself.
378 fun commit
: Commit do
379 return api
.load_commit
(repo
, json
["sha"].as(String)).as(not null)
383 fun commit
=(commit
: Commit) do json
["sha"] = commit
.sha
387 # Can be `pending`, `success`, `failure`, or `error`.
388 fun state
: String do return json
["state"].as(String)
391 fun state
=(state
: String) do json
["state"] = state
393 # Optional human-readable description added to the status.
394 fun description
: nullable String do
395 var res
= json
.get_or_null
("description")
396 if res
isa String then return res
else return null
400 fun description
=(description
: nullable String) do json
["description"] = description
402 # Optional link added to the status.
403 fun target_url
: nullable String do
404 var res
= json
.get_or_null
("target_url")
405 if res
isa String then return res
else return null
409 fun target_url
=(target_url
: nullable String) do json
["target_url"] = target_url
411 # Array of branches containing the status' SHA.
413 # Each branch contains the given SHA,
414 # but the SHA may or may not be the head of the branch.
416 # The array includes a maximum of 10 branches.
417 fun branches
: Array[Branch] do
418 var res
= new Array[Branch]
419 var arr
= json
["branches"].as(JsonArray)
421 if not obj
isa JsonObject then continue
422 res
.add api
.load_branch
(repo
, obj
["name"].as(String)).as(not null)
428 fun branches
=(branches
: Array[Commit]) do
429 var arr
= new JsonArray
430 for branch
in branches
do arr
.add branch
.json
431 json
["branches"] = arr