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 # Nit object oriented interface to [Github api](https://developer.github.com/v3/).
17 # This modules reifies Github API elements as Nit classes.
19 # For most use-cases you need to use the `GithubAPI` client.
23 intrude import json
::serialization_read
25 # Client to Github API
27 # To access the API you need an instance of a `GithubAPI` client.
30 # # Get Github authentification token.
31 # var token = get_github_oauth
32 # assert not token.is_empty
35 # var api = new GithubAPI(token)
38 # The API client allows you to get Github API entities.
41 # var repo = api.load_repo("nitlang/nit")
43 # assert repo.name == "nit"
45 # var user = api.load_user("Morriar")
47 # assert user.login == "Morriar"
51 # Github API OAuth token
53 # To access your private ressources, you must
54 # [authenticate](https://developer.github.com/guides/basics-of-authentication/).
56 # For client applications, Github recommands to use the
57 # [OAuth tokens](https://developer.github.com/v3/oauth/) authentification method.
61 # Be aware that there is [rate limits](https://developer.github.com/v3/rate_limit/)
62 # associated to the key.
65 # Github API base url.
67 # Default is `https://api.github.com` and should not be changed.
68 var api_url
= "https://api.github.com"
70 # User agent used for HTTP requests.
72 # Default is `nit_github_api`.
74 # See <https://developer.github.com/v3/#user-agent-required>
75 var user_agent
= "nit_github_api"
79 # Internal Curl instance used to perform API calls.
80 private var ghcurl
: GithubCurl is noinit
84 # * `0`: only errors (default)
86 var verbose_lvl
= 0 is public
writable
89 ghcurl
= new GithubCurl(auth
, user_agent
)
92 # Deserialize an object
93 fun deserialize
(string
: String): nullable Object do
94 var deserializer
= new GithubDeserializer(string
)
95 var res
= deserializer
.deserialize
96 # print deserializer.errors.join("\n") # DEBUG
100 # Execute a GET request on Github API.
102 # This method returns raw json data.
103 # See other `load_*` methods to use more expressive types.
105 # var api = new GithubAPI(get_github_oauth)
106 # var obj = api.get("/repos/nitlang/nit")
107 # assert obj isa JsonObject
108 # assert obj["name"] == "nit"
110 # Returns `null` in case of `error`.
112 # obj = api.get("/foo/bar/baz")
114 # assert api.was_error
115 # var err = api.last_error
116 # assert err isa GithubError
117 # assert err.name == "GithubAPIError"
118 # assert err.message == "Not Found"
119 fun get
(path
: String): nullable Jsonable do
120 path
= sanitize_uri
(path
)
121 var res
= ghcurl
.get_and_parse
("{api_url}{path}")
122 if res
isa Error then
131 # Display a message depending on `verbose_lvl`.
132 fun message
(lvl
: Int, message
: String) do
133 if lvl
<= verbose_lvl
then print message
136 # Escape `uri` in an acceptable format for Github.
137 private fun sanitize_uri
(uri
: String): String do
138 # TODO better URI escape.
139 return uri
.replace
(" ", "%20")
142 # Last error occured during Github API communications.
143 var last_error
: nullable Error = null is public
writable
145 # Does the last request provoqued an error?
146 var was_error
= false is protected writable
148 # Load the json object from Github.
149 # See `GithubEntity::load_from_github`.
150 protected fun load_from_github
(key
: String): nullable GithubEntity do
151 message
(1, "Get {key} (github)")
153 if was_error
then return null
154 return deserialize
(res
.as(JsonObject).to_json
).as(nullable GithubEntity)
157 # Get the Github logged user from `auth` token.
159 # Loads the `User` from the API or returns `null` if the user cannot be found.
162 # var api = new GithubAPI(get_github_oauth)
163 # var user = api.load_auth_user
164 # assert user.login == "Morriar"
166 fun load_auth_user
: nullable User do
167 var user
= load_from_github
("/user")
168 if was_error
then return null
169 return user
.as(nullable User)
172 # Get the Github user with `login`
174 # Loads the `User` from the API or returns `null` if the user cannot be found.
176 # var api = new GithubAPI(get_github_oauth)
177 # var user = api.load_user("Morriar")
178 # print user or else "null"
179 # assert user.login == "Morriar"
180 fun load_user
(login
: String): nullable User do
181 return load_from_github
("/users/{login}").as(nullable User)
184 # Get the Github repo with `full_name`.
186 # Loads the `Repo` from the API or returns `null` if the repo cannot be found.
188 # var api = new GithubAPI(get_github_oauth)
189 # var repo = api.load_repo("nitlang/nit")
190 # assert repo.name == "nit"
191 # assert repo.owner.login == "nitlang"
192 # assert repo.default_branch == "master"
193 fun load_repo
(full_name
: String): nullable Repo do
194 return load_from_github
("/repos/{full_name}").as(nullable Repo)
197 # List of branches associated with their names.
198 fun load_repo_branches
(repo
: Repo): Array[Branch] do
199 message
(1, "Get branches for {repo.full_name}")
200 var array
= get
("/repos/{repo.full_name}/branches")
201 var res
= new Array[Branch]
202 if not array
isa JsonArray then return res
203 var deser
= deserialize
(array
.to_json
)
204 if deser
isa Array[Object] then return res
# empty array
205 return deser
.as(Array[Branch])
208 # List of issues associated with their ids.
209 fun load_repo_issues
(repo
: Repo): Array[Issue] do
210 message
(1, "Get issues for {repo.full_name}")
211 var res
= new Array[Issue]
212 var issue
= load_repo_last_issue
(repo
)
213 if issue
== null then return res
215 while issue
!= null and issue
.number
> 1 do
216 issue
= load_issue
(repo
, issue
.number
- 1)
217 if issue
== null then continue
223 # Search issues in this repo form an advanced query.
228 # var issues = repo.search_issues("is:open label:need_review")
231 # See <https://developer.github.com/v3/search/#search-issues>.
232 fun search_repo_issues
(repo
: Repo, query
: String): Array[Issue] do
233 query
= "/search/issues?q={query} repo:{repo.full_name}"
234 var res
= new Array[Issue]
235 var response
= get
(query
)
236 if was_error
then return res
237 var arr
= response
.as(JsonObject)["items"].as(JsonArray)
238 return deserialize
(arr
.to_json
).as(Array[Issue])
241 # Get the last published issue.
242 fun load_repo_last_issue
(repo
: Repo): nullable Issue do
243 var array
= get
("/repos/{repo.full_name}/issues")
244 if not array
isa JsonArray then return null
245 if array
.is_empty
then return null
246 var obj
= array
.first
247 if not obj
isa JsonObject then return null
248 return deserialize
(obj
.to_json
).as(nullable Issue)
251 # List of labels associated with their names.
252 fun load_repo_labels
(repo
: Repo): Array[Label] do
253 message
(1, "Get labels for {repo.full_name}")
254 var array
= get
("repos/{repo.full_name}/labels")
255 if not array
isa JsonArray then return new Array[Label]
256 return deserialize
(array
.to_json
).as(Array[Label])
259 # List of milestones associated with their ids.
260 fun load_repo_milestones
(repo
: Repo): Array[Milestone] do
261 message
(1, "Get milestones for {repo.full_name}")
262 var array
= get
("/repos/{repo.full_name}/milestones")
263 if not array
isa JsonArray then return new Array[Milestone]
264 return deserialize
(array
.to_json
).as(Array[Milestone])
267 # List of pull-requests associated with their ids.
269 # Implementation notes: because PR numbers are not consecutive,
270 # PR are loaded from pages.
271 # See: https://developer.github.com/v3/pulls/#list-pull-requests
272 fun load_repo_pulls
(repo
: Repo): Array[PullRequest] do
273 message
(1, "Get pulls for {repo.full_name}")
274 var key
= "/repos/{repo.full_name}"
275 var res
= new Array[PullRequest]
278 var array
= get
("{key}/pulls?page={page}").as(JsonArray)
279 if array
.is_empty
then break
281 if not obj
isa JsonObject then continue
282 var pr
= deserialize
(array
.to_json
).as(nullable PullRequest)
283 if pr
== null then continue
291 # List of contributor related statistics.
292 fun load_repo_contrib_stats
(repo
: Repo): Array[ContributorStats] do
293 message
(1, "Get contributor stats for {repo.full_name}")
294 var res
= new Array[ContributorStats]
295 var array
= get
("/repos/{repo.full_name}/stats/contributors")
296 if not array
isa JsonArray then return res
297 return deserialize
(array
.to_json
).as(Array[ContributorStats])
300 # Get the Github branch with `name`.
302 # Returns `null` if the branch cannot be found.
304 # var api = new GithubAPI(get_github_oauth)
305 # var repo = api.load_repo("nitlang/nit")
306 # assert repo != null
307 # var branch = api.load_branch(repo, "master")
308 # assert branch.name == "master"
309 # assert branch.commit isa Commit
310 fun load_branch
(repo
: Repo, name
: String): nullable Branch do
311 return load_from_github
("/repos/{repo.full_name}/branches/{name}").as(nullable Branch)
314 # List all commits in `self`.
316 # This can be long depending on the branch size.
317 # Commit are returned in an unspecified order.
318 fun load_branch_commits
(branch
: Branch): Array[Commit] do
319 var res
= new Array[Commit]
320 var done
= new HashSet[String]
321 var todos
= new Array[Commit]
322 todos
.add branch
.commit
324 if todos
.is_empty
then break
325 var commit
= todos
.pop
326 if done
.has
(commit
.sha
) then continue
329 var parents
= commit
.parents
330 if parents
== null then continue
331 for parent
in parents
do
338 # Get the Github commit with `sha`.
340 # Returns `null` if the commit cannot be found.
342 # var api = new GithubAPI(get_github_oauth)
343 # var repo = api.load_repo("nitlang/nit")
344 # assert repo != null
345 # var commit = api.load_commit(repo, "64ce1f")
346 # assert commit isa Commit
347 fun load_commit
(repo
: Repo, sha
: String): nullable Commit do
348 return load_from_github
("/repos/{repo.full_name}/commits/{sha}").as(nullable Commit)
351 # Get the Github issue #`number`.
353 # Returns `null` if the issue cannot be found.
355 # var api = new GithubAPI(get_github_oauth)
356 # var repo = api.load_repo("nitlang/nit")
357 # assert repo != null
358 # var issue = api.load_issue(repo, 1)
359 # assert issue.title == "Doc"
360 fun load_issue
(repo
: Repo, number
: Int): nullable Issue do
361 return load_from_github
("/repos/{repo.full_name}/issues/{number}").as(nullable Issue)
364 # List of event on this issue.
365 fun load_issue_comments
(repo
: Repo, issue
: Issue): Array[IssueComment] do
366 var res
= new Array[IssueComment]
367 var count
= issue
.comments
or else 0
370 var array
= get
("/repos/{repo.full_name}/issues/{issue.number}/comments?page={page}")
371 if not array
isa JsonArray then break
372 if array
.is_empty
then break
374 if not obj
isa JsonObject then continue
375 var id
= obj
["id"].as(Int)
376 var comment
= load_issue_comment
(repo
, id
)
377 if comment
== null then continue
380 if res
.length
>= count
then break
386 # List of events on this issue.
387 fun load_issue_events
(repo
: Repo, issue
: Issue): Array[IssueEvent] do
388 var res
= new Array[IssueEvent]
389 var key
= "/repos/{repo.full_name}/issues/{issue.number}"
392 var array
= get
("{key}/events?page={page}")
393 if not array
isa JsonArray or array
.is_empty
then break
395 if not obj
isa JsonObject then continue
396 var event
= deserialize
(obj
.to_json
).as(nullable IssueEvent)
397 if event
== null then continue
405 # Get the Github pull request #`number`.
407 # Returns `null` if the pull request cannot be found.
409 # var api = new GithubAPI(get_github_oauth)
410 # var repo = api.load_repo("nitlang/nit")
411 # assert repo != null
412 # var pull = api.load_pull(repo, 1)
413 # assert pull.title == "Doc"
414 # assert pull.user.login == "Morriar"
415 fun load_pull
(repo
: Repo, number
: Int): nullable PullRequest do
416 return load_from_github
("/repos/{repo.full_name}/pulls/{number}").as(nullable PullRequest)
419 # Get the Github label with `name`.
421 # Returns `null` if the label cannot be found.
423 # var api = new GithubAPI(get_github_oauth)
424 # var repo = api.load_repo("nitlang/nit")
425 # assert repo != null
426 # var labl = api.load_label(repo, "ok_will_merge")
427 # assert labl != null
428 fun load_label
(repo
: Repo, name
: String): nullable Label do
429 return load_from_github
("/repos/{repo.full_name}/labels/{name}").as(nullable Label)
432 # Get the Github milestone with `id`.
434 # Returns `null` if the milestone cannot be found.
436 # var api = new GithubAPI(get_github_oauth)
437 # var repo = api.load_repo("nitlang/nit")
438 # assert repo != null
439 # var stone = api.load_milestone(repo, 4)
440 # assert stone.title == "v1.0prealpha"
441 fun load_milestone
(repo
: Repo, id
: Int): nullable Milestone do
442 return load_from_github
("/repos/{repo.full_name}/milestones/{id}").as(nullable Milestone)
445 # Get the Github issue event with `id`.
447 # Returns `null` if the event cannot be found.
449 # var api = new GithubAPI(get_github_oauth)
450 # var repo = api.load_repo("nitlang/nit")
451 # assert repo isa Repo
452 # var event = api.load_issue_event(repo, 199674194)
453 # assert event isa IssueEvent
454 # assert event.actor.login == "privat"
455 # assert event.event == "labeled"
456 # assert event.labl isa Label
457 # assert event.labl.name == "need_review"
458 fun load_issue_event
(repo
: Repo, id
: Int): nullable IssueEvent do
459 return load_from_github
("/repos/{repo.full_name}/issues/events/{id}").as(nullable IssueEvent)
462 # Get the Github commit comment with `id`.
464 # Returns `null` if the comment cannot be found.
466 # var api = new GithubAPI(get_github_oauth)
467 # var repo = api.load_repo("nitlang/nit")
468 # assert repo != null
469 # var comment = api.load_commit_comment(repo, 8982707)
470 # assert comment.user.login == "Morriar"
471 # assert comment.body == "For testing purposes...\n"
472 # assert comment.commit_id == "7eacb86d1e24b7e72bc9ac869bf7182c0300ceca"
473 fun load_commit_comment
(repo
: Repo, id
: Int): nullable CommitComment do
474 return load_from_github
("/repos/{repo.full_name}/comments/{id}").as(nullable CommitComment)
477 # Get the Github issue comment with `id`.
479 # Returns `null` if the comment cannot be found.
481 # var api = new GithubAPI(get_github_oauth)
482 # var repo = api.load_repo("nitlang/nit")
483 # assert repo != null
484 # var comment = api.load_issue_comment(repo, 6020149)
485 # assert comment.user.login == "privat"
486 # assert comment.created_at.to_s == "2012-05-30T20:16:54Z"
487 # assert comment.issue_number == 10
488 fun load_issue_comment
(repo
: Repo, id
: Int): nullable IssueComment do
489 return load_from_github
("/repos/{repo.full_name}/issues/comments/{id}").as(nullable IssueComment)
492 # Get the Github diff comment with `id`.
494 # Returns `null` if the comment cannot be found.
496 # var api = new GithubAPI(get_github_oauth)
497 # var repo = api.load_repo("nitlang/nit")
498 # assert repo != null
499 # var comment = api.load_review_comment(repo, 21010363)
500 # assert comment.path == "src/modelize/modelize_property.nit"
501 # assert comment.original_position == 26
502 # assert comment.pull_number == 945
503 fun load_review_comment
(repo
: Repo, id
: Int): nullable ReviewComment do
504 return load_from_github
("/repos/{repo.full_name}/pulls/comments/{id}").as(nullable ReviewComment)
508 # Something returned by the Github API.
510 # Mainly a Nit wrapper around a JSON objet.
511 abstract class GithubEntity
516 var html_url
: nullable String is writable
521 # Provides access to [Github user data](https://developer.github.com/v3/users/).
522 # Should be accessed from `GithubAPI::load_user`.
528 var login
: String is writable
530 # Avatar image url for this user.
531 var avatar_url
: nullable String is writable
533 # User public name if any.
534 var name
: nullable String is writable
536 # User public email if any.
537 var email
: nullable String is writable
539 # User public blog if any.
540 var blog
: nullable String is writable
543 # A Github repository.
545 # Provides access to [Github repo data](https://developer.github.com/v3/repos/).
546 # Should be accessed from `GithubAPI::load_repo`.
551 # Repo full name on Github.
552 var full_name
: String is writable
554 # Repo short name on Github.
555 var name
: String is writable
557 # Get the repo owner.
558 var owner
: User is writable
560 # Repo default branch name.
561 var default_branch
: String is writable
566 # Should be accessed from `GithubAPI::load_branch`.
568 # See <https://developer.github.com/v3/repos/#list-branches>.
574 var name
: String is writable
576 # Get the last commit of `self`.
577 var commit
: Commit is writable
582 # Should be accessed from `GithubAPI::load_commit`.
584 # See <https://developer.github.com/v3/repos/commits/>.
590 var sha
: String is writable
592 # Parent commits of `self`.
593 var parents
: nullable Array[Commit] = null is writable
595 # Author of the commit.
596 var author
: nullable GitUser is writable
598 # Committer of the commit.
599 var committer
: nullable GitUser is writable
601 # Authoring date as String.
602 var author_date
: nullable String is writable
604 # Authoring date as ISODate.
605 fun iso_author_date
: nullable ISODate do
606 var author_date
= self.author_date
607 if author_date
== null then return null
608 return new ISODate.from_string
(author_date
)
611 # Commit date as String.
612 var commit_date
: nullable String is writable
614 # Commit date as ISODate.
615 fun iso_commit_date
: nullable ISODate do
616 var commit_date
= self.commit_date
617 if commit_date
== null then return null
618 return new ISODate.from_string
(commit_date
)
621 # List files staged in this commit.
622 var files
: nullable Array[GithubFile] = null is optional
, writable
625 var message
: nullable String is writable
627 # Git commit representation linked to this commit.
628 var commit
: nullable GitCommit
631 # A Git Commit representation
637 var sha
: nullable String is writable
639 # Parent commits of `self`.
640 var parents
: nullable Array[GitCommit] = null is writable
642 # Author of the commit.
643 var author
: nullable GitUser is writable
645 # Committer of the commit.
646 var committer
: nullable GitUser is writable
649 var message
: nullable String is writable
652 # Git user authoring data
658 var date
: nullable String = null is writable
660 # Authoring date as ISODate.
661 fun iso_date
: nullable ISODate do
663 if date
== null then return null
664 return new ISODate.from_string
(date
)
670 # Should be accessed from `GithubAPI::load_issue`.
672 # See <https://developer.github.com/v3/issues/>.
678 var number
: Int is writable
681 var id
: nullable Int is writable
684 var title
: String is writable
686 # User that created this issue.
687 var user
: nullable User is writable
689 # List of labels on this issue associated to their names.
690 var labels
: nullable Array[Label] is writable
692 # State of the issue on Github.
693 var state
: String is writable
695 # Is the issue locked?
696 var locked
: nullable Bool is writable
698 # Assigned `User` (if any).
699 var assignee
: nullable User is writable
701 # `Milestone` (if any).
702 var milestone
: nullable Milestone is writable
704 # Number of comments on this issue.
705 var comments
: nullable Int is writable
707 # Creation time as String.
708 var created_at
: String is writable
710 # Creation time as ISODate.
711 fun iso_created_at
: ISODate do
712 return new ISODate.from_string
(created_at
)
715 # Last update time as String (if any).
716 var updated_at
: nullable String is writable
718 # Last update date as ISODate.
719 fun iso_updated_at
: nullable ISODate do
720 var updated_at
= self.updated_at
721 if updated_at
== null then return null
722 return new ISODate.from_string
(updated_at
)
725 # Close time as String (if any).
726 var closed_at
: nullable String is writable
728 # Close time as ISODate.
729 fun iso_closed_at
: nullable ISODate do
730 var closed_at
= self.closed_at
731 if closed_at
== null then return null
732 return new ISODate.from_string
(closed_at
)
735 # Full description of the issue.
736 var body
: nullable String is writable
738 # User that closed this issue (if any).
739 var closed_by
: nullable User is writable
741 # Is this issue linked to a pull request?
742 var is_pull_request
: Bool = false is writable
745 # A Github pull request.
747 # Should be accessed from `GithubAPI::load_pull`.
749 # PullRequest are basically Issues with more data.
750 # See <https://developer.github.com/v3/pulls/>.
755 # Merge time as String (if any).
756 var merged_at
: nullable String is writable
758 # Merge time as ISODate.
759 fun iso_merged_at
: nullable ISODate do
760 var merged_at
= self.merged_at
761 if merged_at
== null then return null
762 return new ISODate.from_string
(merged_at
)
766 var merge_commit_sha
: nullable String is writable
768 # Count of comments made on the pull request diff.
769 var review_comments
: Int is writable
771 # Pull request head (can be a commit SHA or a branch name).
772 var head
: PullRef is writable
774 # Pull request base (can be a commit SHA or a branch name).
775 var base
: PullRef is writable
777 # Is this pull request merged?
778 var merged
: Bool is writable
780 # Is this pull request mergeable?
781 var mergeable
: nullable Bool is writable
783 # Mergeable state of this pull request.
785 # See <https://developer.github.com/v3/pulls/#list-pull-requests>.
786 var mergeable_state
: String is writable
788 # User that merged this pull request (if any).
789 var merged_by
: nullable User is writable
791 # Count of commits in this pull request.
792 var commits
: Int is writable
795 var additions
: Int is writable
797 # Deleted line count.
798 var deletions
: Int is writable
800 # Changed files count.
801 var changed_files
: Int is writable
804 var patch_url
: nullable String is writable
807 # A pull request reference (used for head and base).
811 # Label pointed by `self`.
812 var labl
: String is writable, serialize_as
("label")
814 # Reference pointed by `self`.
815 var ref
: String is writable
817 # Commit SHA pointed by `self`.
818 var sha
: String is writable
820 # User pointed by `self`.
821 var user
: User is writable
823 # Repo pointed by `self` (if any).
825 # A `null` value means the `repo` was deleted.
826 var repo
: nullable Repo is writable
831 # Should be accessed from `GithubAPI::load_label`.
833 # See <https://developer.github.com/v3/issues/labels/>.
839 var name
: String is writable
842 var color
: String is writable
845 # A Github milestone.
847 # Should be accessed from `GithubAPI::load_milestone`.
849 # See <https://developer.github.com/v3/issues/milestones/>.
854 # The milestone id on Github.
855 var number
: nullable Int = null is writable
858 var title
: String is writable
860 # Milestone long description.
861 var description
: nullable String is writable
863 # Count of opened issues linked to this milestone.
864 var open_issues
: nullable Int = null is writable
866 # Count of closed issues linked to this milestone.
867 var closed_issues
: nullable Int = null is writable
870 var state
: nullable String is writable
872 # Creation time as String.
873 var created_at
: nullable String is writable
875 # Creation time as ISODate.
876 fun iso_created_at
: nullable ISODate do
877 var created_at
= self.created_at
878 if created_at
== null then return null
879 return new ISODate.from_string
(created_at
)
882 # User that created this milestone.
883 var creator
: nullable User is writable
885 # Due time as String (if any).
886 var due_on
: nullable String is writable
888 # Due time in ISODate format (if any).
889 fun iso_due_on
: nullable ISODate do
890 var due_on
= self.due_on
891 if due_on
== null then return null
892 return new ISODate.from_string
(due_on
)
895 # Last update time as String (if any).
896 var updated_at
: nullable String is writable
898 # Last update date as ISODate.
899 fun iso_updated_at
: nullable ISODate do
900 var updated_at
= self.updated_at
901 if updated_at
== null then return null
902 return new ISODate.from_string
(updated_at
)
905 # Close time as String (if any).
906 var closed_at
: nullable String is writable
908 # Close time as ISODate.
909 fun iso_closed_at
: nullable ISODate do
910 var closed_at
= self.closed_at
911 if closed_at
== null then return null
912 return new ISODate.from_string
(closed_at
)
918 # There is two kinds of comments:
920 # * `CommitComment` are made on a commit page.
921 # * `IssueComment` are made on an issue or pull request page.
922 # * `ReviewComment` are made on the diff associated to a pull request.
923 abstract class Comment
927 # Identifier of this comment.
928 var id
: Int is writable
930 # User that made this comment.
931 var user
: User is writable
933 # Creation time as String.
934 var created_at
: String is writable
936 # Creation time as ISODate.
937 fun iso_created_at
: nullable ISODate do
938 return new ISODate.from_string
(created_at
)
941 # Last update time as String (if any).
942 var updated_at
: nullable String is writable
944 # Last update date as ISODate.
945 fun iso_updated_at
: nullable ISODate do
946 var updated_at
= self.updated_at
947 if updated_at
== null then return null
948 return new ISODate.from_string
(updated_at
)
952 var body
: String is writable
954 # Does the comment contain an acknowledgement (+1)
956 return body
.has
("\\+1\\b".to_re
) or body
.has
(":+1:") or body
.has
(":shipit:")
960 # A comment made on a commit.
966 var commit_id
: String is writable
968 # Position of the comment on the line.
969 var position
: nullable Int is writable
971 # Line of the comment.
972 var line
: nullable Int is writable
974 # Path of the commented file.
975 var path
: nullable String is writable
978 # Comments made on Github issue and pull request pages.
980 # Should be accessed from `GithubAPI::load_issue_comment`.
982 # See <https://developer.github.com/v3/issues/comments/>.
987 # Issue that contains `self`.
988 fun issue_number
: Int do return issue_url
.split
("/").last
.to_i
990 # Link to the issue document on API.
991 var issue_url
: String is writable
994 # Comments made on Github pull request diffs.
996 # Should be accessed from `GithubAPI::load_diff_comment`.
998 # See <https://developer.github.com/v3/pulls/comments/>.
1003 # Pull request that contains `self`.
1004 fun pull_number
: Int do return pull_request_url
.split
("/").last
.to_i
1006 # Link to the pull request on API.
1007 var pull_request_url
: String is writable
1010 var diff_hunk
: String is writable
1012 # Path of commented file.
1013 var path
: String is writable
1015 # Position of the comment on the file.
1016 var position
: nullable Int is writable
1018 # Original position in the diff.
1019 var original_position
: Int is writable
1021 # Commit referenced by this comment.
1022 var commit_id
: String is writable
1024 # Original commit id.
1025 var original_commit_id
: String is writable
1028 # An event that occurs on a Github `Issue`.
1030 # Should be accessed from `GithubAPI::load_issue_event`.
1032 # See <https://developer.github.com/v3/issues/events/>.
1037 # Event id on Github.
1038 var id
: Int is writable
1040 # User that initiated the event.
1041 var actor
: User is writable
1043 # Creation time as String.
1044 var created_at
: String is writable
1046 # Creation time as ISODate.
1047 fun iso_created_at
: nullable ISODate do
1048 return new ISODate.from_string
(created_at
)
1052 var event
: String is writable
1054 # Commit linked to this event (if any).
1055 var commit_id
: nullable String is writable
1057 # Label linked to this event (if any).
1058 var labl
: nullable Label is writable, serialize_as
("label")
1060 # User linked to this event (if any).
1061 var assignee
: nullable User is writable
1063 # Milestone linked to this event (if any).
1064 var milestone
: nullable Milestone is writable
1066 # Rename linked to this event (if any).
1067 var rename
: nullable RenameAction is writable
1070 # A rename action maintains the name before and after a renaming action.
1074 # Name before renaming.
1075 var from
: String is writable
1077 # Name after renaming.
1078 var to
: String is writable
1082 # Should be accessed from `Repo::contrib_stats`.
1084 # See <https://developer.github.com/v3/repos/statistics/>.
1085 class ContributorStats
1089 redef type OTHER: ContributorStats
1091 # Github API client.
1092 var api
: GithubAPI is writable
1094 # User these statistics are about.
1095 var author
: User is writable
1097 # Total number of commit.
1098 var total
: Int is writable
1100 # Are of weeks of activity with detailed statistics.
1101 var weeks
: JsonArray is writable
1103 # ContributorStats can be compared on the total amount of commits.
1104 redef fun <(o
) do return total
< o
.total
1107 # A Github file representation.
1109 # Mostly a wrapper around a json object.
1114 var filename
: String is writable
1117 # Make ISO Datew serilizable
1123 # JsonDeserializer specific for Github objects.
1124 class GithubDeserializer
1125 super JsonDeserializer
1127 redef fun class_name_heuristic
(json_object
) do
1128 if json_object
.has_key
("login") then
1130 else if json_object
.has_key
("full_name") then
1132 else if json_object
.has_key
("name") and json_object
.has_key
("commit") then
1134 else if json_object
.has_key
("sha") and json_object
.has_key
("ref") then
1136 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
1138 else if json_object
.has_key
("sha") and json_object
.has_key
("tree") then
1140 else if json_object
.has_key
("name") and json_object
.has_key
("date") then
1142 else if json_object
.has_key
("number") and json_object
.has_key
("patch_url") then
1143 return "PullRequest"
1144 else if json_object
.has_key
("open_issues") and json_object
.has_key
("closed_issues") then
1146 else if json_object
.has_key
("number") and json_object
.has_key
("title") then
1148 else if json_object
.has_key
("color") then
1150 else if json_object
.has_key
("event") then
1152 else if json_object
.has_key
("original_commit_id") then
1153 return "ReviewComment"
1154 else if json_object
.has_key
("commit_id") then
1155 return "CommitComment"
1156 else if json_object
.has_key
("issue_url") then
1157 return "IssueComment"
1162 redef fun deserialize_class
(name
) do
1163 if name
== "Issue" then
1164 var issue
= super.as(Issue)
1165 if path
.last
.has_key
("pull_request") then
1166 issue
.is_pull_request
= true
1169 else if name
== "Commit" then
1170 var commit
= super.as(Commit)
1171 var git_commit
= commit
.commit
1172 if git_commit
!= null then commit
.message
= git_commit
.message