+ var res = json.get_or_null("closed_at")
+ if res isa String then return new ISODate.from_string(res)
+ return null
+ end
+end
+
+# A Github comment
+#
+# There is two kinds of comments:
+#
+# * `CommitComment` are made on a commit page.
+# * `IssueComment` are made on an issue or pull request page.
+# * `ReviewComment` are made on the diff associated to a pull request.
+abstract class Comment
+ super RepoEntity
+
+ # Identifier of this comment.
+ var id: Int
+
+ redef init from_json(api, repo, json) do
+ self.id = json["id"].as(Int)
+ super
+ end
+
+ # User that made this comment.
+ fun user: User do
+ return new User.from_json(api, json["user"].as(JsonObject))
+ end
+
+ # Creation time in ISODate format.
+ fun created_at: ISODate do
+ return new ISODate.from_string(json["created_at"].as(String))
+ end
+
+ # Last update time in ISODate format (if any).
+ fun updated_at: nullable ISODate do
+ var res = json.get_or_null("updated_at")
+ if res isa String then return new ISODate.from_string(res)
+ return null
+ end
+
+ # Comment body text.
+ fun body: String do return json["body"].as(String)
+
+ # 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
+
+ redef var key is lazy do return "{repo.key}/comments/{id}"
+
+ # Commented commit.
+ fun commit: Commit do
+ return api.load_commit(repo, json["commit_id"].as(String)).as(not null)
+ end
+
+ # Position of the comment on the line.
+ fun position: nullable String do
+ var res = json.get_or_null("position")
+ if res isa String then return res
+ return null
+ end
+
+ # Line of the comment.
+ fun line: nullable String do
+ var res = json.get_or_null("line")
+ if res isa String then return res
+ return null
+ end
+
+ # Path of the commented file.
+ fun path: String do return json["path"].as(String)
+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
+
+ redef var key is lazy do return "{repo.key}/issues/comments/{id}"
+
+ # Issue that contains `self`.
+ fun issue: Issue do
+ var number = issue_url.split("/").last.to_i
+ return api.load_issue(repo, number).as(not null)
+ end
+
+ # Link to the issue document on API.
+ fun issue_url: String do return json["issue_url"].as(String)
+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
+
+ redef var key is lazy do return "{repo.key}/pulls/comments/{id}"
+
+ # Pull request that contains `self`.
+ fun pull: PullRequest do
+ var number = pull_request_url.split("/").last.to_i
+ return api.load_pull(repo, number).as(not null)
+ end
+
+ # Link to the pull request on API.
+ fun pull_request_url: String do return json["pull_request_url"].as(String)
+
+ # Diff hunk.
+ fun diff_hunk: String do return json["diff_hunk"].as(String)
+
+ # Path of commented file.
+ fun path: String do return json["path"].as(String)
+
+ # Position of the comment on the file.
+ fun position: Int do return json["position"].as(Int)
+
+ # Original position in the diff.
+ fun original_position: Int do return json["original_position"].as(Int)
+
+ # Commit referenced by this comment.
+ fun commit_id: String do return json["commit_id"].as(String)
+
+ # Original commit id.
+ fun original_commit_id: String do return json["original_commit_id"].as(String)
+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 RepoEntity
+
+ redef var key is lazy do return "{repo.key}/issues/events/{id}"
+
+ # Event id on Github.
+ var id: Int
+
+ redef init from_json(api, repo, json) do
+ self.id = json["id"].as(Int)
+ super
+ end
+
+ # Issue that contains `self`.
+ fun issue: Issue do
+ return new Issue.from_json(api, repo, json["issue"].as(JsonObject))