67a9fac5df4303a5404045c4aeceee7ae9f6e4f4
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
30 # Client to Github API
32 # To access the API you need an instance of a `GithubAPI` client.
35 # # Get Github authentification token.
36 # var token = get_github_oauth
37 # assert not token.is_empty
40 # var api = new GithubAPI(token)
43 # The API client allows you to get Github API entities.
46 # var repo = api.get_repo("nitlang/nit")
48 # assert repo.name == "nit"
50 # var user = api.get_user("Morriar")
52 # assert user.login == "Morriar"
56 # Github API OAuth token
58 # To access your private ressources, you must
59 # [authenticate](https://developer.github.com/guides/basics-of-authentication/).
61 # For client applications, Github recommands to use the
62 # [OAuth tokens](https://developer.github.com/v3/oauth/) authentification method.
66 # Be aware that there is [rate limits](https://developer.github.com/v3/rate_limit/)
67 # associated to the key.
68 var auth
: nullable String = null is optional
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
: String = "nit_github_api" is optional
77 # Headers to use on all requests
78 fun new_headers
: HeaderMap do
79 var map
= new HeaderMap
82 map
["Authorization"] = "token {auth}"
84 map
["User-Agent"] = user_agent
85 # FIXME remove when projects and team are no more in beta
86 map
["Accept"] = "application/vnd.github.inertia-preview+json"
87 map
["Accept"] = "application/vnd.github.hellcat-preview+json"
91 # Github API base url.
93 # Default is `https://api.github.com` and should not be changed.
94 var api_url
= "https://api.github.com"
98 # * `0`: only errors (default)
100 var verbose_lvl
= 0 is public
writable
102 # Send a HTTPRequest to the Github API
103 fun send
(method
, path
: String, headers
: nullable HeaderMap, body
: nullable String): nullable String do
105 path
= sanitize_uri
(path
)
106 var uri
= "{api_url}{path}"
107 var request
= new CurlHTTPRequest(uri
)
108 request
.method
= method
109 request
.user_agent
= user_agent
110 request
.headers
= headers
or else self.new_headers
112 return check_response
(uri
, request
.execute
)
115 private fun check_response
(uri
: String, response
: CurlResponse): nullable String do
116 if response
isa CurlResponseSuccess then
118 return response
.body_str
119 else if response
isa CurlResponseFailed then
120 last_error
= new GithubAPIError(
130 # Deserialize an object
131 fun deserialize
(string
: nullable Serializable): nullable Object do
132 if string
== null then return null
133 var deserializer
= new GithubDeserializer(string
.to_s
)
134 var res
= deserializer
.deserialize
135 if deserializer
.errors
.not_empty
then
137 last_error
= new GithubDeserializerErrors("Deserialization failed", deserializer
.errors
)
139 else if res
isa GithubError then
148 # Display a message depending on `verbose_lvl`.
149 fun message
(lvl
: Int, message
: String) do
150 if lvl
<= verbose_lvl
then print message
153 # Escape `uri` in an acceptable format for Github.
154 private fun sanitize_uri
(uri
: String): String do
155 # TODO better URI escape.
156 return uri
.replace
(" ", "%20")
159 # Last error occured during Github API communications.
160 var last_error
: nullable Error = null is public
writable
162 # Does the last request provoqued an error?
163 var was_error
= false is protected writable
165 # Execute a GET request on Github API.
167 # This method returns a deserialized result.
169 # For raw data see `send`.
172 # var api = new GithubAPI(get_github_oauth)
173 # var obj = api.get("/repos/nitlang/nit")
174 # assert obj isa Repo
175 # assert obj.name == "nit"
178 # Returns `null` in case of `error`.
181 # obj = api.get("/foo/bar/baz")
183 # assert api.was_error
184 # assert api.last_error isa GithubError
186 fun get
(path
: String, headers
: nullable HeaderMap, data
: nullable String): nullable Object do
187 return deserialize
(send
("GET", path
, headers
, data
))
190 # Get the Github logged user from `auth` token.
192 # Loads the `User` from the API or returns `null` if the user cannot be found.
195 # var api = new GithubAPI(get_github_oauth)
196 # var user = api.get_auth_user
197 # assert user.login == "Morriar"
199 fun get_auth_user
: nullable User do
200 return get
("/user").as(nullable User)
203 # Get the Github user with `login`
205 # Loads the `User` from the API or returns `null` if the user cannot be found.
208 # var api = new GithubAPI(get_github_oauth)
209 # var user = api.get_user("Morriar")
210 # print user or else "null"
211 # assert user.login == "Morriar"
213 fun get_user
(login
: String): nullable User do
214 return get
("/users/{login}").as(nullable User)
217 # Get the Github repo with `full_name`.
219 # Loads the `Repo` from the API or returns `null` if the repo cannot be found.
222 # var api = new GithubAPI(get_github_oauth)
223 # var repo = api.get_repo("nitlang/nit")
224 # assert repo.name == "nit"
225 # assert repo.owner.login == "nitlang"
226 # assert repo.default_branch == "master"
228 fun get_repo
(repo_slug
: String): nullable Repo do
229 return get
("/repos/{repo_slug}").as(nullable Repo)
232 # List of repo branches.
235 # * `page`: page to fetch (default: 1)
236 # * `per_page`: number of branches by page (default: 30)
237 fun get_repo_branches
(repo_slug
: String, page
, per_page
: nullable Int): Array[Branch] do
238 return new GithubArray[Branch].from
(get
(
239 "/repos/{repo_slug}/branches?{pagination(page, per_page)}"))
242 # List of issues associated with their ids.
243 fun get_repo_issues
(repo_slug
: String, page
, per_page
: nullable Int): Array[Issue] do
244 return new GithubArray[Issue].from
(get
(
245 "/repos/{repo_slug}/issues?{pagination(page, per_page)}"))
248 # Search issues in this repo form an advanced query.
253 # var issues = repo.search_issues("is:open label:need_review")
256 # See <https://developer.github.com/v3/search/#search-issues>.
257 fun search_repo_issues
(repo_slug
: String, query
: String, page
, per_page
: nullable Int): nullable SearchResults do
258 return get
("/search/issues?q={query} repo:{repo_slug}&{pagination(page, per_page)}").as(nullable SearchResults)
261 # List of labels associated with their names.
262 fun get_repo_labels
(repo_slug
: String, page
, per_page
: nullable Int): Array[Label] do
263 return new GithubArray[Label].from
(get
(
264 "/repos/{repo_slug}/labels?{pagination(page, per_page)}"))
267 # List of milestones associated with their ids.
268 fun get_repo_milestones
(repo_slug
: String, page
, per_page
: nullable Int): Array[Milestone] do
269 return new GithubArray[Milestone].from
(get
(
270 "/repos/{repo_slug}/milestones?{pagination(page, per_page)}"))
273 # List of pull-requests associated with their ids.
275 # Implementation notes: because PR numbers are not consecutive,
276 # PR are loaded from pages.
277 # See: https://developer.github.com/v3/pulls/#list-pull-requests
278 fun get_repo_pulls
(repo_slug
: String, page
, per_page
: nullable Int): Array[PullRequest] do
279 return new GithubArray[PullRequest].from
(get
(
280 "/repos/{repo_slug}/pulls?{pagination(page, per_page)}"))
283 # List of contributor related statistics.
284 fun get_repo_contrib_stats
(repo_slug
: String): Array[ContributorStats] do
285 message
(1, "Get contributor stats for {repo_slug}")
286 var res
= new Array[ContributorStats]
287 var array
= get
("/repos/{repo_slug}/stats/contributors")
288 if not array
isa JsonArray then return res
289 return deserialize
(array
.to_json
).as(Array[ContributorStats])
292 # Get the Github branch with `name`.
294 # Returns `null` if the branch cannot be found.
297 # var api = new GithubAPI(get_github_oauth)
298 # var repo = api.get_repo("nitlang/nit")
299 # assert repo != null
300 # var branch = api.get_branch(repo, "master")
301 # assert branch.name == "master"
302 # assert branch.commit isa Commit
304 fun get_branch
(repo_slug
: String, name
: String): nullable Branch do
305 return get
("/repos/{repo_slug}/branches/{name}").as(nullable Branch)
308 # Get the Github commit with `sha`.
310 # Returns `null` if the commit cannot be found.
313 # var api = new GithubAPI(get_github_oauth)
314 # var repo = api.get_repo("nitlang/nit")
315 # assert repo != null
316 # var commit = api.get_commit(repo, "64ce1f")
317 # assert commit isa Commit
319 fun get_commit
(repo_slug
: String, sha
: String): nullable Commit do
320 return get
("/repos/{repo_slug}/commits/{sha}").as(nullable Commit)
323 # Get the Github issue #`number`.
325 # Returns `null` if the issue cannot be found.
328 # var api = new GithubAPI(get_github_oauth)
329 # var repo = api.get_repo("nitlang/nit")
330 # assert repo != null
331 # var issue = api.get_issue(repo, 1)
332 # assert issue.title == "Doc"
334 fun get_issue
(repo_slug
: String, number
: Int): nullable Issue do
335 return get
("/repos/{repo_slug}/issues/{number}").as(nullable Issue)
338 # List of event on this issue.
339 fun get_issue_comments
(repo_slug
: String, issue_number
: Int, page
, per_page
: nullable Int): Array[IssueComment] do
340 return new GithubArray[IssueComment].from
(get
(
341 "/repos/{repo_slug}/issues/{issue_number}/comments?{pagination(page, per_page)}"))
344 # List of events on this issue.
345 fun get_issue_events
(repo_slug
: String, issue_number
: Int, page
, per_page
: nullable Int): Array[IssueEvent] do
346 return new GithubArray[IssueEvent].from
(get
(
347 "/repos/{repo_slug}/issues/{issue_number}/events?{pagination(page, per_page)}"))
350 # Get the Github pull request #`number`.
352 # Returns `null` if the pull request cannot be found.
355 # var api = new GithubAPI(get_github_oauth)
356 # var repo = api.get_repo("nitlang/nit")
357 # assert repo != null
358 # var pull = api.get_pull(repo, 1)
359 # assert pull.title == "Doc"
360 # assert pull.user.login == "Morriar"
362 fun get_pull
(repo_slug
: String, number
: Int): nullable PullRequest do
363 return get
("/repos/{repo_slug}/pulls/{number}").as(nullable PullRequest)
366 # Get the Github label with `name`.
368 # Returns `null` if the label cannot be found.
371 # var api = new GithubAPI(get_github_oauth)
372 # var repo = api.get_repo("nitlang/nit")
373 # assert repo != null
374 # var labl = api.get_label(repo, "ok_will_merge")
375 # assert labl != null
377 fun get_label
(repo_slug
: String, name
: String): nullable Label do
378 return get
("/repos/{repo_slug}/labels/{name}").as(nullable Label)
381 # Get the Github milestone with `id`.
383 # Returns `null` if the milestone cannot be found.
386 # var api = new GithubAPI(get_github_oauth)
387 # var repo = api.get_repo("nitlang/nit")
388 # assert repo != null
389 # var stone = api.get_milestone(repo, 4)
390 # assert stone.title == "v1.0prealpha"
392 fun get_milestone
(repo_slug
: String, id
: Int): nullable Milestone do
393 return get
("/repos/{repo_slug}/milestones/{id}").as(nullable Milestone)
396 # Get the Github issue event with `id`.
398 # Returns `null` if the event cannot be found.
401 # var api = new GithubAPI(get_github_oauth)
402 # var repo = api.get_repo("nitlang/nit")
403 # assert repo isa Repo
404 # var event = api.get_issue_event(repo, 199674194)
405 # assert event isa IssueEvent
406 # assert event.actor.login == "privat"
407 # assert event.event == "labeled"
408 # assert event.labl isa Label
409 # assert event.labl.name == "need_review"
411 fun get_issue_event
(repo_slug
: String, id
: Int): nullable IssueEvent do
412 return get
("/repos/{repo_slug}/issues/events/{id}").as(nullable IssueEvent)
415 # Get the Github commit comment with `id`.
417 # Returns `null` if the comment cannot be found.
420 # var api = new GithubAPI(get_github_oauth)
421 # var repo = api.get_repo("nitlang/nit")
422 # assert repo != null
423 # var comment = api.get_commit_comment(repo, 8982707)
424 # assert comment.user.login == "Morriar"
425 # assert comment.body == "For testing purposes...\n"
426 # assert comment.commit_id == "7eacb86d1e24b7e72bc9ac869bf7182c0300ceca"
428 fun get_commit_comment
(repo_slug
: String, id
: Int): nullable CommitComment do
429 return get
("/repos/{repo_slug}/comments/{id}").as(nullable CommitComment)
432 # Get the Github issue comment with `id`.
434 # Returns `null` if the comment cannot be found.
437 # var api = new GithubAPI(get_github_oauth)
438 # var repo = api.get_repo("nitlang/nit")
439 # assert repo != null
440 # var comment = api.get_issue_comment(repo, 6020149)
441 # assert comment.user.login == "privat"
442 # assert comment.created_at.to_s == "2012-05-30T20:16:54Z"
443 # assert comment.issue_number == 10
445 fun get_issue_comment
(repo_slug
: String, id
: Int): nullable IssueComment do
446 return get
("/repos/{repo_slug}/issues/comments/{id}").as(nullable IssueComment)
449 # Get the Github diff comment with `id`.
451 # Returns `null` if the comment cannot be found.
454 # var api = new GithubAPI(get_github_oauth)
455 # var repo = api.get_repo("nitlang/nit")
456 # assert repo != null
457 # var comment = api.get_review_comment(repo, 21010363)
458 # assert comment.path == "src/modelize/modelize_property.nit"
459 # assert comment.original_position == 26
460 # assert comment.pull_number == 945
462 fun get_review_comment
(repo_slug
: String, id
: Int): nullable ReviewComment do
463 return get
("/repos/{repo_slug}/pulls/comments/{id}").as(nullable ReviewComment)
466 private fun pagination
(page
, per_page
: nullable Int): String do
467 return "page={page or else 1}&per_page={per_page or else 30}"
471 # Return deserialization as an array of E
473 # Non-subtypes will be ignored.
474 private class GithubArray[E
]
477 # Create `self` from an Array of objects
479 # Objects non-subtyping E will be ignored.
480 init from
(res
: nullable Object) do
481 if not res
isa Array[Object] then return
483 if obj
isa E
then add obj
488 # An Error returned by GithubAPI
493 # An Error returned by https://api.github.com
495 # Anything that can occurs when sending request to the API:
496 # * Can't connect to API
497 # * Ressource not found
503 # Status code obtained
506 # URI that returned the error
507 var requested_uri
: String
510 # An Error returned while deserializing GithubEntity objects
511 class GithubDeserializerErrors
514 # Errors returned by the deserizalization process
515 var deserizalization_errors
: Array[Error]
518 # Something returned by the Github API.
520 # Mainly a Nit wrapper around a JSON objet.
521 abstract class GithubEntity
525 var html_url
: nullable String is writable
530 # Provides access to [Github user data](https://developer.github.com/v3/users/).
531 # Should be accessed from `GithubAPI::get_user`.
537 var login
: String is writable
539 # Avatar image url for this user.
540 var avatar_url
: nullable String is writable
542 # User public name if any.
543 var name
: nullable String is writable
545 # User public email if any.
546 var email
: nullable String is writable
548 # User public blog if any.
549 var blog
: nullable String is writable
552 # A Github repository.
554 # Provides access to [Github repo data](https://developer.github.com/v3/repos/).
555 # Should be accessed from `GithubAPI::get_repo`.
560 # Repo full name on Github.
561 var full_name
: String is writable
563 # Repo short name on Github.
564 var name
: String is writable
566 # Get the repo owner.
567 var owner
: User is writable
569 # Repo default branch name.
570 var default_branch
: String is writable
575 # Should be accessed from `GithubAPI::get_branch`.
577 # See <https://developer.github.com/v3/repos/#list-branches>.
583 var name
: String is writable
585 # Get the last commit of `self`.
586 var commit
: Commit is writable
591 # Should be accessed from `GithubAPI::get_commit`.
593 # See <https://developer.github.com/v3/repos/commits/>.
599 var sha
: String is writable
601 # Parent commits of `self`.
602 var parents
: nullable Array[Commit] = null is writable
604 # Author of the commit.
605 var author
: nullable GitUser is writable
607 # Committer of the commit.
608 var committer
: nullable GitUser is writable
610 # Authoring date as String.
611 var author_date
: nullable String is writable
613 # Authoring date as ISODate.
614 fun iso_author_date
: nullable ISODate do
615 var author_date
= self.author_date
616 if author_date
== null then return null
617 return new ISODate.from_string
(author_date
)
620 # Commit date as String.
621 var commit_date
: nullable String is writable
623 # Commit date as ISODate.
624 fun iso_commit_date
: nullable ISODate do
625 var commit_date
= self.commit_date
626 if commit_date
== null then return null
627 return new ISODate.from_string
(commit_date
)
630 # List files staged in this commit.
631 var files
: nullable Array[GithubFile] = null is optional
, writable
634 var message
: nullable String is writable
636 # Git commit representation linked to this commit.
637 var commit
: nullable GitCommit
640 # A Git Commit representation
646 var sha
: nullable String is writable
648 # Parent commits of `self`.
649 var parents
: nullable Array[GitCommit] = null is writable
651 # Author of the commit.
652 var author
: nullable GitUser is writable
654 # Committer of the commit.
655 var committer
: nullable GitUser is writable
658 var message
: nullable String is writable
661 # Git user authoring data
667 var date
: nullable String = null is writable
669 # Authoring date as ISODate.
670 fun iso_date
: nullable ISODate do
672 if date
== null then return null
673 return new ISODate.from_string
(date
)
679 # Should be accessed from `GithubAPI::get_issue`.
681 # See <https://developer.github.com/v3/issues/>.
687 var number
: Int is writable
690 var id
: nullable Int is writable
693 var title
: String is writable
695 # User that created this issue.
696 var user
: nullable User is writable
698 # List of labels on this issue associated to their names.
699 var labels
: nullable Array[Label] is writable
701 # State of the issue on Github.
702 var state
: String is writable
704 # Is the issue locked?
705 var locked
: nullable Bool is writable
707 # Assigned `User` (if any).
708 var assignee
: nullable User is writable
710 # `Milestone` (if any).
711 var milestone
: nullable Milestone is writable
713 # Number of comments on this issue.
714 var comments
: nullable Int is writable
716 # Creation time as String.
717 var created_at
: String is writable
719 # Creation time as ISODate.
720 fun iso_created_at
: ISODate do
721 return new ISODate.from_string
(created_at
)
724 # Last update time as String (if any).
725 var updated_at
: nullable String is writable
727 # Last update date as ISODate.
728 fun iso_updated_at
: nullable ISODate do
729 var updated_at
= self.updated_at
730 if updated_at
== null then return null
731 return new ISODate.from_string
(updated_at
)
734 # Close time as String (if any).
735 var closed_at
: nullable String is writable
737 # Close time as ISODate.
738 fun iso_closed_at
: nullable ISODate do
739 var closed_at
= self.closed_at
740 if closed_at
== null then return null
741 return new ISODate.from_string
(closed_at
)
744 # Full description of the issue.
745 var body
: nullable String is writable
747 # User that closed this issue (if any).
748 var closed_by
: nullable User is writable
750 # Is this issue linked to a pull request?
751 var is_pull_request
: Bool = false is writable
754 # A Github pull request.
756 # Should be accessed from `GithubAPI::get_pull`.
758 # PullRequest are basically Issues with more data.
759 # See <https://developer.github.com/v3/pulls/>.
764 # Merge time as String (if any).
765 var merged_at
: nullable String is writable
767 # Merge time as ISODate.
768 fun iso_merged_at
: nullable ISODate do
769 var merged_at
= self.merged_at
770 if merged_at
== null then return null
771 return new ISODate.from_string
(merged_at
)
775 var merge_commit_sha
: nullable String is writable
777 # Count of comments made on the pull request diff.
778 var review_comments
: nullable Int is writable
780 # Pull request head (can be a commit SHA or a branch name).
781 var head
: PullRef is writable
783 # Pull request base (can be a commit SHA or a branch name).
784 var base
: PullRef is writable
786 # Is this pull request merged?
787 var merged
: nullable Bool is writable
789 # Is this pull request mergeable?
790 var mergeable
: nullable Bool is writable
792 # Mergeable state of this pull request.
794 # See <https://developer.github.com/v3/pulls/#list-pull-requests>.
795 var mergeable_state
: nullable String is writable
797 # User that merged this pull request (if any).
798 var merged_by
: nullable User is writable
800 # Count of commits in this pull request.
801 var commits
: nullable Int is writable
804 var additions
: nullable Int is writable
806 # Deleted line count.
807 var deletions
: nullable Int is writable
809 # Changed files count.
810 var changed_files
: nullable Int is writable
813 var patch_url
: nullable String is writable
816 # A pull request reference (used for head and base).
820 # Label pointed by `self`.
821 var labl
: String is writable, serialize_as
("label")
823 # Reference pointed by `self`.
824 var ref
: String is writable
826 # Commit SHA pointed by `self`.
827 var sha
: String is writable
829 # User pointed by `self`.
830 var user
: User is writable
832 # Repo pointed by `self` (if any).
834 # A `null` value means the `repo` was deleted.
835 var repo
: nullable Repo is writable
840 # Should be accessed from `GithubAPI::get_label`.
842 # See <https://developer.github.com/v3/issues/labels/>.
848 var name
: String is writable
851 var color
: String is writable
854 # A Github milestone.
856 # Should be accessed from `GithubAPI::get_milestone`.
858 # See <https://developer.github.com/v3/issues/milestones/>.
863 # The milestone id on Github.
864 var number
: nullable Int = null is writable
867 var title
: String is writable
869 # Milestone long description.
870 var description
: nullable String is writable
872 # Count of opened issues linked to this milestone.
873 var open_issues
: nullable Int = null is writable
875 # Count of closed issues linked to this milestone.
876 var closed_issues
: nullable Int = null is writable
879 var state
: nullable String is writable
881 # Creation time as String.
882 var created_at
: nullable String is writable
884 # Creation time as ISODate.
885 fun iso_created_at
: nullable ISODate do
886 var created_at
= self.created_at
887 if created_at
== null then return null
888 return new ISODate.from_string
(created_at
)
891 # User that created this milestone.
892 var creator
: nullable User is writable
894 # Due time as String (if any).
895 var due_on
: nullable String is writable
897 # Due time in ISODate format (if any).
898 fun iso_due_on
: nullable ISODate do
899 var due_on
= self.due_on
900 if due_on
== null then return null
901 return new ISODate.from_string
(due_on
)
904 # Last update time as String (if any).
905 var updated_at
: nullable String is writable
907 # Last update date as ISODate.
908 fun iso_updated_at
: nullable ISODate do
909 var updated_at
= self.updated_at
910 if updated_at
== null then return null
911 return new ISODate.from_string
(updated_at
)
914 # Close time as String (if any).
915 var closed_at
: nullable String is writable
917 # Close time as ISODate.
918 fun iso_closed_at
: nullable ISODate do
919 var closed_at
= self.closed_at
920 if closed_at
== null then return null
921 return new ISODate.from_string
(closed_at
)
927 # There is two kinds of comments:
929 # * `CommitComment` are made on a commit page.
930 # * `IssueComment` are made on an issue or pull request page.
931 # * `ReviewComment` are made on the diff associated to a pull request.
932 abstract class Comment
936 # Identifier of this comment.
937 var id
: Int is writable
939 # User that made this comment.
940 var user
: User is writable
942 # Creation time as String.
943 var created_at
: String is writable
945 # Creation time as ISODate.
946 fun iso_created_at
: nullable ISODate do
947 return new ISODate.from_string
(created_at
)
950 # Last update time as String (if any).
951 var updated_at
: nullable String is writable
953 # Last update date as ISODate.
954 fun iso_updated_at
: nullable ISODate do
955 var updated_at
= self.updated_at
956 if updated_at
== null then return null
957 return new ISODate.from_string
(updated_at
)
961 var body
: String is writable
963 # Does the comment contain an acknowledgement (+1)
965 return body
.has
("\\+1\\b".to_re
) or body
.has
(":+1:") or body
.has
(":shipit:")
969 # A comment made on a commit.
975 var commit_id
: String is writable
977 # Position of the comment on the line.
978 var position
: nullable Int is writable
980 # Line of the comment.
981 var line
: nullable Int is writable
983 # Path of the commented file.
984 var path
: nullable String is writable
987 # Comments made on Github issue and pull request pages.
989 # Should be accessed from `GithubAPI::get_issue_comment`.
991 # See <https://developer.github.com/v3/issues/comments/>.
996 # Issue that contains `self`.
997 fun issue_number
: Int do return issue_url
.split
("/").last
.to_i
999 # Link to the issue document on API.
1000 var issue_url
: String is writable
1003 # Comments made on Github pull request diffs.
1005 # Should be accessed from `GithubAPI::get_diff_comment`.
1007 # See <https://developer.github.com/v3/pulls/comments/>.
1012 # Pull request that contains `self`.
1013 fun pull_number
: Int do return pull_request_url
.split
("/").last
.to_i
1015 # Link to the pull request on API.
1016 var pull_request_url
: String is writable
1019 var diff_hunk
: String is writable
1021 # Path of commented file.
1022 var path
: String is writable
1024 # Position of the comment on the file.
1025 var position
: nullable Int is writable
1027 # Original position in the diff.
1028 var original_position
: Int is writable
1030 # Commit referenced by this comment.
1031 var commit_id
: String is writable
1033 # Original commit id.
1034 var original_commit_id
: String is writable
1037 # An event that occurs on a Github `Issue`.
1039 # Should be accessed from `GithubAPI::get_issue_event`.
1041 # See <https://developer.github.com/v3/issues/events/>.
1046 # Event id on Github.
1047 var id
: Int is writable
1049 # User that initiated the event.
1050 var actor
: User is writable
1052 # Creation time as String.
1053 var created_at
: String is writable
1055 # Creation time as ISODate.
1056 fun iso_created_at
: nullable ISODate do
1057 return new ISODate.from_string
(created_at
)
1061 var event
: String is writable
1063 # Commit linked to this event (if any).
1064 var commit_id
: nullable String is writable
1066 # Label linked to this event (if any).
1067 var labl
: nullable Label is writable, serialize_as
("label")
1069 # User linked to this event (if any).
1070 var assignee
: nullable User is writable
1072 # Milestone linked to this event (if any).
1073 var milestone
: nullable Milestone is writable
1075 # Rename linked to this event (if any).
1076 var rename
: nullable RenameAction is writable
1079 # A rename action maintains the name before and after a renaming action.
1083 # Name before renaming.
1084 var from
: String is writable
1086 # Name after renaming.
1087 var to
: String is writable
1091 # Should be accessed from `Repo::contrib_stats`.
1093 # See <https://developer.github.com/v3/repos/statistics/>.
1094 class ContributorStats
1098 redef type OTHER: ContributorStats
1100 # Github API client.
1101 var api
: GithubAPI is writable
1103 # User these statistics are about.
1104 var author
: User is writable
1106 # Total number of commit.
1107 var total
: Int is writable
1109 # Are of weeks of activity with detailed statistics.
1110 var weeks
: JsonArray is writable
1112 # ContributorStats can be compared on the total amount of commits.
1113 redef fun <(o
) do return total
< o
.total
1116 # A Github file representation.
1118 # Mostly a wrapper around a json object.
1123 var filename
: String is writable
1126 # A list of results returned buy `/search`
1130 # Total count with other pages
1131 var total_count
: Int
1133 # Does this page contain all the results?
1134 var incomplete_results
: Bool
1136 # Results in this page
1137 var items
: Array[Object]
1140 # Make ISO Datew serilizable
1145 # JsonDeserializer specific for Github objects.
1146 class GithubDeserializer
1147 super JsonDeserializer
1149 redef fun class_name_heuristic
(json_object
) do
1150 if json_object
.has_key
("login") then
1152 else if json_object
.has_key
("full_name") then
1154 else if json_object
.has_key
("name") and json_object
.has_key
("commit") then
1156 else if json_object
.has_key
("sha") and json_object
.has_key
("ref") then
1158 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
1160 else if json_object
.has_key
("sha") and json_object
.has_key
("tree") then
1162 else if json_object
.has_key
("name") and json_object
.has_key
("date") then
1164 else if json_object
.has_key
("number") and json_object
.has_key
("patch_url") then
1165 return "PullRequest"
1166 else if json_object
.has_key
("open_issues") and json_object
.has_key
("closed_issues") then
1168 else if json_object
.has_key
("number") and json_object
.has_key
("title") then
1170 else if json_object
.has_key
("color") then
1172 else if json_object
.has_key
("event") then
1174 else if json_object
.has_key
("original_commit_id") then
1175 return "ReviewComment"
1176 else if json_object
.has_key
("commit_id") then
1177 return "CommitComment"
1178 else if json_object
.has_key
("issue_url") then
1179 return "IssueComment"
1180 else if json_object
.has_key
("total_count") then
1181 return "SearchResults"
1186 redef fun deserialize_class
(name
) do
1187 if name
== "Issue" then
1188 var issue
= super.as(Issue)
1189 if path
.last
.has_key
("pull_request") then
1190 issue
.is_pull_request
= true
1193 else if name
== "Commit" then
1194 var commit
= super.as(Commit)
1195 var git_commit
= commit
.commit
1196 if git_commit
!= null then commit
.message
= git_commit
.message
1203 # Gets the Github token from `git` configuration
1205 # Return the value of `git config --get github.oauthtoken`
1206 # or `""` if no key exists.
1207 fun get_github_oauth
: String
1209 var p
= new ProcessReader("git", "config", "--get", "github.oauthtoken")
1210 var token
= p
.read_line