+ # Comment body text.
+ var body: String is writable
+
+ # Does the comment contain an acknowledgement (+1)
+ fun is_ack: Bool do
+ return body.has("\\+1\\b".to_re) or body.has(":+1:") or body.has(":shipit:")
+ end
+end
+
+# A comment made on a commit.
+class CommitComment
+ super Comment
+ serialize
+
+ # Commented commit.
+ var commit_id: String is writable
+
+ # Position of the comment on the line.
+ var position: nullable Int is writable
+
+ # Line of the comment.
+ var line: nullable Int is writable
+
+ # Path of the commented file.
+ var path: nullable String is writable
+end
+
+# Comments made on Github issue and pull request pages.
+#
+# Should be accessed from `GithubAPI::load_issue_comment`.
+#
+# See <https://developer.github.com/v3/issues/comments/>.
+class IssueComment
+ super Comment
+ serialize
+
+ # Issue that contains `self`.
+ fun issue_number: Int do return issue_url.split("/").last.to_i
+
+ # Link to the issue document on API.
+ var issue_url: String is writable
+end
+
+# Comments made on Github pull request diffs.
+#
+# Should be accessed from `GithubAPI::load_diff_comment`.
+#
+# See <https://developer.github.com/v3/pulls/comments/>.
+class ReviewComment
+ super Comment
+ serialize
+
+ # Pull request that contains `self`.
+ fun pull_number: Int do return pull_request_url.split("/").last.to_i
+
+ # Link to the pull request on API.
+ var pull_request_url: String is writable
+
+ # Diff hunk.
+ var diff_hunk: String is writable
+
+ # Path of commented file.
+ var path: String is writable
+
+ # Position of the comment on the file.
+ var position: nullable Int is writable
+
+ # Original position in the diff.
+ var original_position: Int is writable
+
+ # Commit referenced by this comment.
+ var commit_id: String is writable
+
+ # Original commit id.
+ var original_commit_id: String is writable
+end
+
+# An event that occurs on a Github `Issue`.
+#
+# Should be accessed from `GithubAPI::load_issue_event`.
+#
+# See <https://developer.github.com/v3/issues/events/>.
+class IssueEvent
+ super GithubEntity
+ serialize
+
+ # Event id on Github.
+ var id: Int is writable
+
+ # User that initiated the event.
+ var actor: User is writable
+
+ # Creation time as String.
+ var created_at: String is writable
+
+ # Creation time as ISODate.
+ fun iso_created_at: nullable ISODate do
+ return new ISODate.from_string(created_at)
+ end
+
+ # Event descriptor.
+ var event: String is writable
+
+ # Commit linked to this event (if any).
+ var commit_id: nullable String is writable
+
+ # Label linked to this event (if any).
+ var labl: nullable Label is writable, serialize_as("label")
+
+ # User linked to this event (if any).
+ var assignee: nullable User is writable
+
+ # Milestone linked to this event (if any).
+ var milestone: nullable Milestone is writable
+
+ # Rename linked to this event (if any).
+ var rename: nullable RenameAction is writable
+end
+
+# A rename action maintains the name before and after a renaming action.
+class RenameAction
+ serialize
+
+ # Name before renaming.
+ var from: String is writable
+
+ # Name after renaming.
+ var to: String is writable
+end
+
+#
+# Should be accessed from `Repo::contrib_stats`.
+#
+# See <https://developer.github.com/v3/repos/statistics/>.
+class ContributorStats
+ super Comparable
+ serialize
+
+ redef type OTHER: ContributorStats
+
+ # Github API client.
+ var api: GithubAPI is writable
+
+ # User these statistics are about.
+ var author: User is writable
+
+ # Total number of commit.
+ var total: Int is writable
+
+ # Are of weeks of activity with detailed statistics.
+ var weeks: JsonArray is writable
+
+ # ContributorStats can be compared on the total amount of commits.
+ redef fun <(o) do return total < o.total
+end
+
+# A Github file representation.
+#
+# Mostly a wrapper around a json object.
+class GithubFile
+ serialize
+
+ # File name.
+ var filename: String is writable
+end
+
+# Make ISO Datew serilizable
+redef class ISODate
+ serialize
+end
+
+# JsonDeserializer specific for Github objects.
+class GithubDeserializer
+ super JsonDeserializer
+
+ redef fun class_name_heuristic(json_object) do
+ if json_object.has_key("login") then
+ return "User"
+ else if json_object.has_key("full_name") then
+ return "Repo"
+ else if json_object.has_key("name") and json_object.has_key("commit") then
+ return "Branch"
+ else if json_object.has_key("sha") and json_object.has_key("ref") then
+ return "PullRef"
+ else if (json_object.has_key("sha") and json_object.has_key("commit")) or (json_object.has_key("id") and json_object.has_key("tree_id")) then
+ return "Commit"
+ else if json_object.has_key("sha") and json_object.has_key("tree") then
+ return "GitCommit"
+ else if json_object.has_key("name") and json_object.has_key("date") then
+ return "GitUser"
+ else if json_object.has_key("number") and json_object.has_key("patch_url") then
+ return "PullRequest"
+ else if json_object.has_key("open_issues") and json_object.has_key("closed_issues") then
+ return "Milestone"
+ else if json_object.has_key("number") and json_object.has_key("title") then
+ return "Issue"
+ else if json_object.has_key("color") then
+ return "Label"
+ else if json_object.has_key("event") then
+ return "IssueEvent"
+ else if json_object.has_key("original_commit_id") then
+ return "ReviewComment"
+ else if json_object.has_key("commit_id") then
+ return "CommitComment"
+ else if json_object.has_key("issue_url") then
+ return "IssueComment"
+ end
+ return null
+ end
+
+ redef fun deserialize_class(name) do
+ if name == "Issue" then
+ var issue = super.as(Issue)
+ if path.last.has_key("pull_request") then
+ issue.is_pull_request = true
+ end
+ return issue
+ else if name == "Commit" then
+ var commit = super.as(Commit)
+ var git_commit = commit.commit
+ if git_commit != null then commit.message = git_commit.message
+ return commit
+ end
+ return super