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"].to_s
44 # Repo where this event occured.
46 return new Repo.from_json
(api
, json
["repository"].as(JsonObject))
50 # Triggered when a commit comment is created.
51 class CommitCommentEvent
54 # The `Comment` itself.
55 fun comment
: CommitComment do
56 return new CommitComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
60 # Triggered when a repository, branch, or tag is created.
64 # Oject type that was created.
66 # Can be one of `repository`, `branch`, or `tag`.
67 fun ref_type
: String do return json
["ref_type"].to_s
69 # Git ref (or null if only a repository was created).
70 fun ref
: String do return json
["ref"].to_s
72 # Name of the repo's default branch (usually master).
73 fun master_branch
: String do return json
["master_branch"].to_s
75 # Repo's current description.
76 fun description
: String do return json
["description"].to_s
79 # Triggered when a branch or a tag is deleted.
83 # Object type that was deleted.
85 # Can be one of `repository`, `branch`, or `tag`.
86 fun ref_type
: String do return json
["ref_type"].to_s
88 # Git ref (or null if only a repository was deleted).
89 fun ref
: String do return json
["ref"].to_s
92 # Triggered when a new snapshot is deployed.
94 # Deployement are mainly used with integration testing servers.
98 # Commit SHA for which this deployment was created.
99 fun sha
: String do return json
["sha"].to_s
101 # Name of repository for this deployment, formatted as :owner/:repo.
102 fun name
: String do return json
["name"].to_s
104 # Optional extra information for this deployment.
105 fun payload
: nullable String do
106 if not json
.has_key
("payload") then return null
107 return json
["payload"].to_s
110 # Optional environment to deploy to.
111 # Default: "production"
112 fun environment
: nullable String do
113 if not json
.has_key
("environment") then return null
114 return json
["environment"].to_s
117 # Optional human-readable description added to the deployment.
118 fun description
: nullable String do
119 if not json
.has_key
("description") then return null
120 return json
["description"].to_s
124 # Triggered when a deployement's status changes.
125 class DeploymentStatusEvent
128 # New deployment state.
130 # Can be `pending`, `success`, `failure`, or `error`.
131 fun state
: String do return json
["state"].to_s
133 # Optional link added to the status.
134 fun target_url
: nullable String do
135 if not json
.has_key
("target_url") then return null
136 return json
["target_url"].to_s
139 # Deployment hash that this status is associated with.
140 fun deployment
: String do return json
["deployment"].to_s
142 # Optional human-readable description added to the status.
143 fun description
: nullable String do
144 if not json
.has_key
("description") then return null
145 return json
["description"].to_s
149 # Triggered when a user forks a repository.
153 # Created repository.
154 fun forkee
: Repo do return new Repo.from_json
(api
, json
["forkee"].as(JsonObject))
157 # Triggered when an issue comment is created.
158 class IssueCommentEvent
161 # `Issue` the comment belongs to.
163 return new Issue.from_json
(api
, repo
, json
["issue"].as(JsonObject))
166 # The `Comment` itself.
167 fun comment
: IssueComment do
168 return new IssueComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
172 # Triggered when an event occurs on an issue.
174 # Triggered when an issue is assigned, unassigned, labeled, unlabeled,
175 # opened, closed or reopened.
179 # The `Issue` itself.
180 fun issue
: Issue do return new Issue.from_json
(api
, repo
, json
["issue"].as(JsonObject))
182 # Optional `Label` that was added or removed from the issue.
183 fun lbl
: nullable Label do
184 if not json
.has_key
("label") then return null
185 return new Label.from_json
(api
, repo
, json
["label"].as(JsonObject))
188 # Optional `User` that was assigned or unassigned from the issue.
189 fun assignee
: nullable User do
190 if not json
.has_key
("assignee") then return null
191 return new User.from_json
(api
, json
["assignee"].as(JsonObject))
195 # Triggered when a user is added as a collaborator to a repository.
199 # `User` that was added.
200 fun member
: User do return new User.from_json
(api
, json
["member"].as(JsonObject))
203 # Triggered when an event occurs on a pull request.
205 # Triggered when a pull request is assigned, unassigned,
206 # labeled, unlabeled, opened, closed, reopened, or synchronized.
207 class PullRequestEvent
210 # The pull request number.
211 fun number
: Int do return json
["number"].as(Int)
213 # The `PullRequest` itself.
214 fun pull
: PullRequest do
215 return new PullRequest.from_json
(api
, repo
, json
["pull_request"].as(JsonObject))
219 # Triggered when a comment is created on a pull request diff.
220 class PullRequestReviewCommentEvent
223 # The `Comment` itself.
224 fun comment
: ReviewComment do
225 return new ReviewComment.from_json
(api
, repo
, json
["comment"].as(JsonObject))
228 # `PullRequest` the `comment` belongs to.
229 fun pull
: PullRequest do
230 return new PullRequest.from_json
(api
, repo
, json
["pull_request"].as(JsonObject))
234 # Triggered when a repository branch is pushed to.
238 # SHA of the HEAD commit on the repository.
239 fun head
: String do return json
["head"].to_s
241 # Full Git ref that was pushed.
243 # Example: “refs/heads/master”
244 fun ref
: String do return json
["ref"].to_s
246 # Number of commits in the push.
247 fun size
: Int do return json
["size"].as(Int)
249 # Array of pushed commits.
250 fun commits
: Array[Commit] do
251 var res
= new Array[Commit]
252 var arr
= json
["commits"].as(JsonArray)
254 if not obj
isa JsonObject then continue
255 res
.add api
.load_commit
(repo
, obj
["sha"].to_s
).as(not null)
261 # Triggered when the status of a Git commit changes.
265 # The `Commit` itself.
266 fun commit
: Commit do
267 return api
.load_commit
(repo
, json
["sha"].to_s
).as(not null)
272 # Can be `pending`, `success`, `failure`, or `error`.
273 fun state
: String do return json
["state"].to_s
275 # Optional human-readable description added to the status.
276 fun description
: nullable String do
277 if not json
.has_key
("description") then return null
278 return json
["description"].to_s
281 # Optional link added to the status.
282 fun target_url
: nullable String do
283 if not json
.has_key
("target_url") then return null
284 return json
["target_url"].to_s
287 # Array of branches containing the status' SHA.
289 # Each branch contains the given SHA,
290 # but the SHA may or may not be the head of the branch.
292 # The array includes a maximum of 10 branches.
293 fun branches
: Array[Branch] do
294 var res
= new Array[Branch]
295 var arr
= json
["branches"].as(JsonArray)
297 if not obj
isa JsonObject then continue
298 res
.add api
.load_branch
(repo
, obj
["name"].to_s
).as(not null)