2dc0af75372e0a1f0261bf68470863dbe4932cbf
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/>
21 intrude import json
::serialization
28 # Event ID from Github.
29 var id
: nullable String is writable
31 # Action performed by the event.
32 var action
: nullable String is writable
34 # Repo where this event occured.
35 var repo
: Repo is writable
37 redef fun to_json
do return serialize_to_json
40 # Triggered when a commit comment is created.
41 class CommitCommentEvent
45 # The `Comment` itself.
46 var comment
: CommitComment is writable
49 # Triggered when a repository, branch, or tag is created.
54 # Oject type that was created.
56 # Can be one of `repository`, `branch`, or `tag`.
57 var ref_type
: String is writable
59 # Git ref (or null if only a repository was created).
60 var ref
: String is writable
62 # Name of the repo's default branch (usually master).
63 var master_branch
: String is writable
65 # Repo's current description.
66 var description
: nullable String is writable
69 # Triggered when a branch or a tag is deleted.
74 # Object type that was deleted.
76 # Can be one of `repository`, `branch`, or `tag`.
77 var ref_type
: String is writable
79 # Git ref (or null if only a repository was deleted).
80 var ref
: String is writable
83 # Triggered when a new snapshot is deployed.
85 # Deployement are mainly used with integration testing servers.
90 # Commit SHA for which this deployment was created.
91 var sha
: String is writable
93 # Name of repository for this deployment, formatted as :owner/:repo.
94 var name
: String is writable
96 # Optional extra information for this deployment.
97 var payload
: nullable String is writable
99 # Optional environment to deploy to.
100 # Default: "production"
101 var environment
: nullable String is writable
103 # Optional human-readable description added to the deployment.
104 var description
: nullable String is writable
107 # Triggered when a deployement's status changes.
108 class DeploymentStatusEvent
112 # New deployment state.
114 # Can be `pending`, `success`, `failure`, or `error`.
115 var state
: String is writable
117 # Optional link added to the status.
118 var target_url
: nullable String is writable
120 # Deployment hash that this status is associated with.
121 var deployment
: String is writable
123 # Optional human-readable description added to the status.
124 var description
: nullable String is writable
127 # Triggered when a user forks a repository.
132 # Created repository.
133 var forkee
: Repo is writable
136 # Triggered when an issue comment is created.
137 class IssueCommentEvent
141 # `Issue` the comment belongs to.
142 var issue
: Issue is writable
144 # The `Comment` itself.
145 var comment
: IssueComment is writable
148 # Triggered when an event occurs on an issue.
150 # Triggered when an issue is assigned, unassigned, labeled, unlabeled,
151 # opened, closed or reopened.
156 # The `Issue` itself.
157 var issue
: Issue is writable
159 # Optional `Label` that was added or removed from the issue.
160 var lbl
: nullable Label is writable, serialize_as
("label")
162 # Optional `User` that was assigned or unassigned from the issue.
163 var assignee
: nullable User is writable
166 # Triggered when a user is added as a collaborator to a repository.
171 # `User` that was added.
172 var member
: User is writable
175 # Triggered when an event occurs on a pull request.
177 # Triggered when a pull request is assigned, unassigned,
178 # labeled, unlabeled, opened, closed, reopened, or synchronized.
179 class PullRequestEvent
183 # The pull request number.
184 var number
: Int is writable
186 # The `PullRequest` itself.
187 var pull
: PullRequest is writable
190 # Triggered when a comment is created on a pull request diff.
191 class PullRequestReviewCommentEvent
195 # The `Comment` itself.
196 var comment
: ReviewComment is writable
198 # `PullRequest` the `comment` belongs to.
199 var pull
: PullRequest is writable
202 # Triggered when a repository branch is pushed to.
207 # SHA of the HEAD commit on the repository.
208 var head_commit
: Commit is writable
210 # Full Git ref that was pushed.
212 # Example: “refs/heads/master”
213 var ref
: String is writable
215 # Number of commits in the push.
216 var size
: nullable Int is writable
218 # Array of pushed commits.
219 var commits
= new Array[Commit] is writable, optional
222 # Triggered when the status of a Git commit changes.
227 # The `Commit` itself.
228 var sha
: String is writable
232 # Can be `pending`, `success`, `failure`, or `error`.
233 var state
: String is writable
235 # Optional human-readable description added to the status.
236 var description
: nullable String is writable
238 # Optional link added to the status.
239 var target_url
: nullable String is writable
241 # Array of branches containing the status' SHA.
243 # Each branch contains the given SHA,
244 # but the SHA may or may not be the head of the branch.
246 # The array includes a maximum of 10 branches.
247 var branches
= new Array[Branch] is writable, optional
250 redef class GithubDeserializer
252 redef fun class_name_heuristic
(json_object
) do
253 if json_object
.has_key
("action") and json_object
.has_key
("commit") and json_object
.has_key
("comment") then
254 return "CommitCommentEvent"
255 else if json_object
.has_key
("ref") and json_object
.has_key
("master_branch") then
257 else if json_object
.has_key
("ref") and json_object
.has_key
("ref_type") then
259 else if json_object
.has_key
("action") and json_object
.has_key
("sha") then
260 return "DeploymentEvent"
261 else if json_object
.has_key
("action") and json_object
.has_key
("state") then
262 return "DeploymentStatusEvent"
263 else if json_object
.has_key
("action") and json_object
.has_key
("forkee") then
265 else if json_object
.has_key
("action") and json_object
.has_key
("issue") and json_object
.has_key
("comment") then
266 return "IssueCommentEvent"
267 else if json_object
.has_key
("action") and json_object
.has_key
("issue") then
269 else if json_object
.has_key
("action") and json_object
.has_key
("member") then
271 else if json_object
.has_key
("action") and json_object
.has_key
("number") then
272 return "PullRequestEvent"
273 else if json_object
.has_key
("action") and json_object
.has_key
("pull") and json_object
.has_key
("comment") then
274 return "PullRequestReviewCommentEvent"
275 else if json_object
.has_key
("head_commit") and json_object
.has_key
("commits") then
277 else if json_object
.has_key
("action") and json_object
.has_key
("branches") then
279 else if json_object
.has_key
("action") and json_object
.has_key
("issue") then