8f439f106a3bdee61d64eac9d9f706df367920d0
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
(full_name
: String): nullable Repo do
229 return get
("/repos/{full_name}").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
: Repo, page
, per_page
: nullable Int): Array[Branch] do
238 return new GithubArray[Branch].from
(get
(
239 "/repos/{repo.full_name}/branches?{pagination(page, per_page)}"))
242 # List of issues associated with their ids.
243 fun get_repo_issues
(repo
: Repo, page
, per_page
: nullable Int): Array[Issue] do
244 return new GithubArray[Issue].from
(get
(
245 "/repos/{repo.full_name}/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
: Repo, query
: String, page
, per_page
: nullable Int): nullable SearchResults do
258 return get
("/search/issues?q={query} repo:{repo.full_name}&{pagination(page, per_page)}").as(nullable SearchResults)
261 # List of labels associated with their names.
262 fun get_repo_labels
(repo
: Repo, page
, per_page
: nullable Int): Array[Label] do
263 return new GithubArray[Label].from
(get
(
264 "/repos/{repo.full_name}/labels?{pagination(page, per_page)}"))
267 # List of milestones associated with their ids.
268 fun get_repo_milestones
(repo
: Repo, page
, per_page
: nullable Int): Array[Milestone] do
269 return new GithubArray[Milestone].from
(get
(
270 "/repos/{repo.full_name}/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
: Repo, page
, per_page
: nullable Int): Array[PullRequest] do
279 return new GithubArray[PullRequest].from
(get
(
280 "/repos/{repo.full_name}/pulls?{pagination(page, per_page)}"))
283 # List of contributor related statistics.
284 fun get_repo_contrib_stats
(repo
: Repo): Array[ContributorStats] do
285 message
(1, "Get contributor stats for {repo.full_name}")
286 var res
= new Array[ContributorStats]
287 var array
= get
("/repos/{repo.full_name}/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
: Repo, name
: String): nullable Branch do
305 return get
("/repos/{repo.full_name}/branches/{name}").as(nullable Branch)
308 # List all commits in `self`.
310 # This can be long depending on the branch size.
311 # Commit are returned in an unspecified order.
312 fun get_branch_commits
(branch
: Branch): Array[Commit] do
313 var res
= new Array[Commit]
314 var done
= new HashSet[String]
315 var todos
= new Array[Commit]
316 todos
.add branch
.commit
318 if todos
.is_empty
then break
319 var commit
= todos
.pop
320 if done
.has
(commit
.sha
) then continue
323 var parents
= commit
.parents
324 if parents
== null then continue
325 for parent
in parents
do
332 # Get the Github commit with `sha`.
334 # Returns `null` if the commit cannot be found.
337 # var api = new GithubAPI(get_github_oauth)
338 # var repo = api.get_repo("nitlang/nit")
339 # assert repo != null
340 # var commit = api.get_commit(repo, "64ce1f")
341 # assert commit isa Commit
343 fun get_commit
(repo
: Repo, sha
: String): nullable Commit do
344 return get
("/repos/{repo.full_name}/commits/{sha}").as(nullable Commit)
347 # Get the Github issue #`number`.
349 # Returns `null` if the issue cannot be found.
352 # var api = new GithubAPI(get_github_oauth)
353 # var repo = api.get_repo("nitlang/nit")
354 # assert repo != null
355 # var issue = api.get_issue(repo, 1)
356 # assert issue.title == "Doc"
358 fun get_issue
(repo
: Repo, number
: Int): nullable Issue do
359 return get
("/repos/{repo.full_name}/issues/{number}").as(nullable Issue)
362 # List of event on this issue.
363 fun get_issue_comments
(repo
: Repo, issue
: Issue, page
, per_page
: nullable Int): Array[IssueComment] do
364 return new GithubArray[IssueComment].from
(get
(
365 "/repos/{repo.full_name}/issues/{issue.number}/comments?{pagination(page, per_page)}"))
368 # List of events on this issue.
369 fun get_issue_events
(repo
: Repo, issue
: Issue, page
, per_page
: nullable Int): Array[IssueEvent] do
370 return new GithubArray[IssueEvent].from
(get
(
371 "/repos/{repo.full_name}/issues/{issue.number}/events?{pagination(page, per_page)}"))
374 # Get the Github pull request #`number`.
376 # Returns `null` if the pull request cannot be found.
379 # var api = new GithubAPI(get_github_oauth)
380 # var repo = api.get_repo("nitlang/nit")
381 # assert repo != null
382 # var pull = api.get_pull(repo, 1)
383 # assert pull.title == "Doc"
384 # assert pull.user.login == "Morriar"
386 fun get_pull
(repo
: Repo, number
: Int): nullable PullRequest do
387 return get
("/repos/{repo.full_name}/pulls/{number}").as(nullable PullRequest)
390 # Get the Github label with `name`.
392 # Returns `null` if the label cannot be found.
395 # var api = new GithubAPI(get_github_oauth)
396 # var repo = api.get_repo("nitlang/nit")
397 # assert repo != null
398 # var labl = api.get_label(repo, "ok_will_merge")
399 # assert labl != null
401 fun get_label
(repo
: Repo, name
: String): nullable Label do
402 return get
("/repos/{repo.full_name}/labels/{name}").as(nullable Label)
405 # Get the Github milestone with `id`.
407 # Returns `null` if the milestone cannot be found.
410 # var api = new GithubAPI(get_github_oauth)
411 # var repo = api.get_repo("nitlang/nit")
412 # assert repo != null
413 # var stone = api.get_milestone(repo, 4)
414 # assert stone.title == "v1.0prealpha"
416 fun get_milestone
(repo
: Repo, id
: Int): nullable Milestone do
417 return get
("/repos/{repo.full_name}/milestones/{id}").as(nullable Milestone)
420 # Get the Github issue event with `id`.
422 # Returns `null` if the event cannot be found.
425 # var api = new GithubAPI(get_github_oauth)
426 # var repo = api.get_repo("nitlang/nit")
427 # assert repo isa Repo
428 # var event = api.get_issue_event(repo, 199674194)
429 # assert event isa IssueEvent
430 # assert event.actor.login == "privat"
431 # assert event.event == "labeled"
432 # assert event.labl isa Label
433 # assert event.labl.name == "need_review"
435 fun get_issue_event
(repo
: Repo, id
: Int): nullable IssueEvent do
436 return get
("/repos/{repo.full_name}/issues/events/{id}").as(nullable IssueEvent)
439 # Get the Github commit comment with `id`.
441 # Returns `null` if the comment cannot be found.
444 # var api = new GithubAPI(get_github_oauth)
445 # var repo = api.get_repo("nitlang/nit")
446 # assert repo != null
447 # var comment = api.get_commit_comment(repo, 8982707)
448 # assert comment.user.login == "Morriar"
449 # assert comment.body == "For testing purposes...\n"
450 # assert comment.commit_id == "7eacb86d1e24b7e72bc9ac869bf7182c0300ceca"
452 fun get_commit_comment
(repo
: Repo, id
: Int): nullable CommitComment do
453 return get
("/repos/{repo.full_name}/comments/{id}").as(nullable CommitComment)
456 # Get the Github issue comment with `id`.
458 # Returns `null` if the comment cannot be found.
461 # var api = new GithubAPI(get_github_oauth)
462 # var repo = api.get_repo("nitlang/nit")
463 # assert repo != null
464 # var comment = api.get_issue_comment(repo, 6020149)
465 # assert comment.user.login == "privat"
466 # assert comment.created_at.to_s == "2012-05-30T20:16:54Z"
467 # assert comment.issue_number == 10
469 fun get_issue_comment
(repo
: Repo, id
: Int): nullable IssueComment do
470 return get
("/repos/{repo.full_name}/issues/comments/{id}").as(nullable IssueComment)
473 # Get the Github diff comment with `id`.
475 # Returns `null` if the comment cannot be found.
478 # var api = new GithubAPI(get_github_oauth)
479 # var repo = api.get_repo("nitlang/nit")
480 # assert repo != null
481 # var comment = api.get_review_comment(repo, 21010363)
482 # assert comment.path == "src/modelize/modelize_property.nit"
483 # assert comment.original_position == 26
484 # assert comment.pull_number == 945
486 fun get_review_comment
(repo
: Repo, id
: Int): nullable ReviewComment do
487 return get
("/repos/{repo.full_name}/pulls/comments/{id}").as(nullable ReviewComment)
490 private fun pagination
(page
, per_page
: nullable Int): String do
491 return "page={page or else 1}&per_page={per_page or else 30}"
495 # Return deserialization as an array of E
497 # Non-subtypes will be ignored.
498 private class GithubArray[E
]
501 # Create `self` from an Array of objects
503 # Objects non-subtyping E will be ignored.
504 init from
(res
: nullable Object) do
505 if not res
isa Array[Object] then return
507 if obj
isa E
then add obj
512 # An Error returned by GithubAPI
517 # An Error returned by https://api.github.com
519 # Anything that can occurs when sending request to the API:
520 # * Can't connect to API
521 # * Ressource not found
527 # Status code obtained
530 # URI that returned the error
531 var requested_uri
: String
534 # An Error returned while deserializing GithubEntity objects
535 class GithubDeserializerErrors
538 # Errors returned by the deserizalization process
539 var deserizalization_errors
: Array[Error]
542 # Something returned by the Github API.
544 # Mainly a Nit wrapper around a JSON objet.
545 abstract class GithubEntity
549 var html_url
: nullable String is writable
554 # Provides access to [Github user data](https://developer.github.com/v3/users/).
555 # Should be accessed from `GithubAPI::get_user`.
561 var login
: String is writable
563 # Avatar image url for this user.
564 var avatar_url
: nullable String is writable
566 # User public name if any.
567 var name
: nullable String is writable
569 # User public email if any.
570 var email
: nullable String is writable
572 # User public blog if any.
573 var blog
: nullable String is writable
576 # A Github repository.
578 # Provides access to [Github repo data](https://developer.github.com/v3/repos/).
579 # Should be accessed from `GithubAPI::get_repo`.
584 # Repo full name on Github.
585 var full_name
: String is writable
587 # Repo short name on Github.
588 var name
: String is writable
590 # Get the repo owner.
591 var owner
: User is writable
593 # Repo default branch name.
594 var default_branch
: String is writable
599 # Should be accessed from `GithubAPI::get_branch`.
601 # See <https://developer.github.com/v3/repos/#list-branches>.
607 var name
: String is writable
609 # Get the last commit of `self`.
610 var commit
: Commit is writable
615 # Should be accessed from `GithubAPI::get_commit`.
617 # See <https://developer.github.com/v3/repos/commits/>.
623 var sha
: String is writable
625 # Parent commits of `self`.
626 var parents
: nullable Array[Commit] = null is writable
628 # Author of the commit.
629 var author
: nullable GitUser is writable
631 # Committer of the commit.
632 var committer
: nullable GitUser is writable
634 # Authoring date as String.
635 var author_date
: nullable String is writable
637 # Authoring date as ISODate.
638 fun iso_author_date
: nullable ISODate do
639 var author_date
= self.author_date
640 if author_date
== null then return null
641 return new ISODate.from_string
(author_date
)
644 # Commit date as String.
645 var commit_date
: nullable String is writable
647 # Commit date as ISODate.
648 fun iso_commit_date
: nullable ISODate do
649 var commit_date
= self.commit_date
650 if commit_date
== null then return null
651 return new ISODate.from_string
(commit_date
)
654 # List files staged in this commit.
655 var files
: nullable Array[GithubFile] = null is optional
, writable
658 var message
: nullable String is writable
660 # Git commit representation linked to this commit.
661 var commit
: nullable GitCommit
664 # A Git Commit representation
670 var sha
: nullable String is writable
672 # Parent commits of `self`.
673 var parents
: nullable Array[GitCommit] = null is writable
675 # Author of the commit.
676 var author
: nullable GitUser is writable
678 # Committer of the commit.
679 var committer
: nullable GitUser is writable
682 var message
: nullable String is writable
685 # Git user authoring data
691 var date
: nullable String = null is writable
693 # Authoring date as ISODate.
694 fun iso_date
: nullable ISODate do
696 if date
== null then return null
697 return new ISODate.from_string
(date
)
703 # Should be accessed from `GithubAPI::get_issue`.
705 # See <https://developer.github.com/v3/issues/>.
711 var number
: Int is writable
714 var id
: nullable Int is writable
717 var title
: String is writable
719 # User that created this issue.
720 var user
: nullable User is writable
722 # List of labels on this issue associated to their names.
723 var labels
: nullable Array[Label] is writable
725 # State of the issue on Github.
726 var state
: String is writable
728 # Is the issue locked?
729 var locked
: nullable Bool is writable
731 # Assigned `User` (if any).
732 var assignee
: nullable User is writable
734 # `Milestone` (if any).
735 var milestone
: nullable Milestone is writable
737 # Number of comments on this issue.
738 var comments
: nullable Int is writable
740 # Creation time as String.
741 var created_at
: String is writable
743 # Creation time as ISODate.
744 fun iso_created_at
: ISODate do
745 return new ISODate.from_string
(created_at
)
748 # Last update time as String (if any).
749 var updated_at
: nullable String is writable
751 # Last update date as ISODate.
752 fun iso_updated_at
: nullable ISODate do
753 var updated_at
= self.updated_at
754 if updated_at
== null then return null
755 return new ISODate.from_string
(updated_at
)
758 # Close time as String (if any).
759 var closed_at
: nullable String is writable
761 # Close time as ISODate.
762 fun iso_closed_at
: nullable ISODate do
763 var closed_at
= self.closed_at
764 if closed_at
== null then return null
765 return new ISODate.from_string
(closed_at
)
768 # Full description of the issue.
769 var body
: nullable String is writable
771 # User that closed this issue (if any).
772 var closed_by
: nullable User is writable
774 # Is this issue linked to a pull request?
775 var is_pull_request
: Bool = false is writable
778 # A Github pull request.
780 # Should be accessed from `GithubAPI::get_pull`.
782 # PullRequest are basically Issues with more data.
783 # See <https://developer.github.com/v3/pulls/>.
788 # Merge time as String (if any).
789 var merged_at
: nullable String is writable
791 # Merge time as ISODate.
792 fun iso_merged_at
: nullable ISODate do
793 var merged_at
= self.merged_at
794 if merged_at
== null then return null
795 return new ISODate.from_string
(merged_at
)
799 var merge_commit_sha
: nullable String is writable
801 # Count of comments made on the pull request diff.
802 var review_comments
: nullable Int is writable
804 # Pull request head (can be a commit SHA or a branch name).
805 var head
: PullRef is writable
807 # Pull request base (can be a commit SHA or a branch name).
808 var base
: PullRef is writable
810 # Is this pull request merged?
811 var merged
: nullable Bool is writable
813 # Is this pull request mergeable?
814 var mergeable
: nullable Bool is writable
816 # Mergeable state of this pull request.
818 # See <https://developer.github.com/v3/pulls/#list-pull-requests>.
819 var mergeable_state
: nullable String is writable
821 # User that merged this pull request (if any).
822 var merged_by
: nullable User is writable
824 # Count of commits in this pull request.
825 var commits
: nullable Int is writable
828 var additions
: nullable Int is writable
830 # Deleted line count.
831 var deletions
: nullable Int is writable
833 # Changed files count.
834 var changed_files
: nullable Int is writable
837 var patch_url
: nullable String is writable
840 # A pull request reference (used for head and base).
844 # Label pointed by `self`.
845 var labl
: String is writable, serialize_as
("label")
847 # Reference pointed by `self`.
848 var ref
: String is writable
850 # Commit SHA pointed by `self`.
851 var sha
: String is writable
853 # User pointed by `self`.
854 var user
: User is writable
856 # Repo pointed by `self` (if any).
858 # A `null` value means the `repo` was deleted.
859 var repo
: nullable Repo is writable
864 # Should be accessed from `GithubAPI::get_label`.
866 # See <https://developer.github.com/v3/issues/labels/>.
872 var name
: String is writable
875 var color
: String is writable
878 # A Github milestone.
880 # Should be accessed from `GithubAPI::get_milestone`.
882 # See <https://developer.github.com/v3/issues/milestones/>.
887 # The milestone id on Github.
888 var number
: nullable Int = null is writable
891 var title
: String is writable
893 # Milestone long description.
894 var description
: nullable String is writable
896 # Count of opened issues linked to this milestone.
897 var open_issues
: nullable Int = null is writable
899 # Count of closed issues linked to this milestone.
900 var closed_issues
: nullable Int = null is writable
903 var state
: nullable String is writable
905 # Creation time as String.
906 var created_at
: nullable String is writable
908 # Creation time as ISODate.
909 fun iso_created_at
: nullable ISODate do
910 var created_at
= self.created_at
911 if created_at
== null then return null
912 return new ISODate.from_string
(created_at
)
915 # User that created this milestone.
916 var creator
: nullable User is writable
918 # Due time as String (if any).
919 var due_on
: nullable String is writable
921 # Due time in ISODate format (if any).
922 fun iso_due_on
: nullable ISODate do
923 var due_on
= self.due_on
924 if due_on
== null then return null
925 return new ISODate.from_string
(due_on
)
928 # Last update time as String (if any).
929 var updated_at
: nullable String is writable
931 # Last update date as ISODate.
932 fun iso_updated_at
: nullable ISODate do
933 var updated_at
= self.updated_at
934 if updated_at
== null then return null
935 return new ISODate.from_string
(updated_at
)
938 # Close time as String (if any).
939 var closed_at
: nullable String is writable
941 # Close time as ISODate.
942 fun iso_closed_at
: nullable ISODate do
943 var closed_at
= self.closed_at
944 if closed_at
== null then return null
945 return new ISODate.from_string
(closed_at
)
951 # There is two kinds of comments:
953 # * `CommitComment` are made on a commit page.
954 # * `IssueComment` are made on an issue or pull request page.
955 # * `ReviewComment` are made on the diff associated to a pull request.
956 abstract class Comment
960 # Identifier of this comment.
961 var id
: Int is writable
963 # User that made this comment.
964 var user
: User is writable
966 # Creation time as String.
967 var created_at
: String is writable
969 # Creation time as ISODate.
970 fun iso_created_at
: nullable ISODate do
971 return new ISODate.from_string
(created_at
)
974 # Last update time as String (if any).
975 var updated_at
: nullable String is writable
977 # Last update date as ISODate.
978 fun iso_updated_at
: nullable ISODate do
979 var updated_at
= self.updated_at
980 if updated_at
== null then return null
981 return new ISODate.from_string
(updated_at
)
985 var body
: String is writable
987 # Does the comment contain an acknowledgement (+1)
989 return body
.has
("\\+1\\b".to_re
) or body
.has
(":+1:") or body
.has
(":shipit:")
993 # A comment made on a commit.
999 var commit_id
: String is writable
1001 # Position of the comment on the line.
1002 var position
: nullable Int is writable
1004 # Line of the comment.
1005 var line
: nullable Int is writable
1007 # Path of the commented file.
1008 var path
: nullable String is writable
1011 # Comments made on Github issue and pull request pages.
1013 # Should be accessed from `GithubAPI::get_issue_comment`.
1015 # See <https://developer.github.com/v3/issues/comments/>.
1020 # Issue that contains `self`.
1021 fun issue_number
: Int do return issue_url
.split
("/").last
.to_i
1023 # Link to the issue document on API.
1024 var issue_url
: String is writable
1027 # Comments made on Github pull request diffs.
1029 # Should be accessed from `GithubAPI::get_diff_comment`.
1031 # See <https://developer.github.com/v3/pulls/comments/>.
1036 # Pull request that contains `self`.
1037 fun pull_number
: Int do return pull_request_url
.split
("/").last
.to_i
1039 # Link to the pull request on API.
1040 var pull_request_url
: String is writable
1043 var diff_hunk
: String is writable
1045 # Path of commented file.
1046 var path
: String is writable
1048 # Position of the comment on the file.
1049 var position
: nullable Int is writable
1051 # Original position in the diff.
1052 var original_position
: Int is writable
1054 # Commit referenced by this comment.
1055 var commit_id
: String is writable
1057 # Original commit id.
1058 var original_commit_id
: String is writable
1061 # An event that occurs on a Github `Issue`.
1063 # Should be accessed from `GithubAPI::get_issue_event`.
1065 # See <https://developer.github.com/v3/issues/events/>.
1070 # Event id on Github.
1071 var id
: Int is writable
1073 # User that initiated the event.
1074 var actor
: User is writable
1076 # Creation time as String.
1077 var created_at
: String is writable
1079 # Creation time as ISODate.
1080 fun iso_created_at
: nullable ISODate do
1081 return new ISODate.from_string
(created_at
)
1085 var event
: String is writable
1087 # Commit linked to this event (if any).
1088 var commit_id
: nullable String is writable
1090 # Label linked to this event (if any).
1091 var labl
: nullable Label is writable, serialize_as
("label")
1093 # User linked to this event (if any).
1094 var assignee
: nullable User is writable
1096 # Milestone linked to this event (if any).
1097 var milestone
: nullable Milestone is writable
1099 # Rename linked to this event (if any).
1100 var rename
: nullable RenameAction is writable
1103 # A rename action maintains the name before and after a renaming action.
1107 # Name before renaming.
1108 var from
: String is writable
1110 # Name after renaming.
1111 var to
: String is writable
1115 # Should be accessed from `Repo::contrib_stats`.
1117 # See <https://developer.github.com/v3/repos/statistics/>.
1118 class ContributorStats
1122 redef type OTHER: ContributorStats
1124 # Github API client.
1125 var api
: GithubAPI is writable
1127 # User these statistics are about.
1128 var author
: User is writable
1130 # Total number of commit.
1131 var total
: Int is writable
1133 # Are of weeks of activity with detailed statistics.
1134 var weeks
: JsonArray is writable
1136 # ContributorStats can be compared on the total amount of commits.
1137 redef fun <(o
) do return total
< o
.total
1140 # A Github file representation.
1142 # Mostly a wrapper around a json object.
1147 var filename
: String is writable
1150 # A list of results returned buy `/search`
1154 # Total count with other pages
1155 var total_count
: Int
1157 # Does this page contain all the results?
1158 var incomplete_results
: Bool
1160 # Results in this page
1161 var items
: Array[Object]
1164 # Make ISO Datew serilizable
1169 # JsonDeserializer specific for Github objects.
1170 class GithubDeserializer
1171 super JsonDeserializer
1173 redef fun class_name_heuristic
(json_object
) do
1174 if json_object
.has_key
("login") then
1176 else if json_object
.has_key
("full_name") then
1178 else if json_object
.has_key
("name") and json_object
.has_key
("commit") then
1180 else if json_object
.has_key
("sha") and json_object
.has_key
("ref") then
1182 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
1184 else if json_object
.has_key
("sha") and json_object
.has_key
("tree") then
1186 else if json_object
.has_key
("name") and json_object
.has_key
("date") then
1188 else if json_object
.has_key
("number") and json_object
.has_key
("patch_url") then
1189 return "PullRequest"
1190 else if json_object
.has_key
("open_issues") and json_object
.has_key
("closed_issues") then
1192 else if json_object
.has_key
("number") and json_object
.has_key
("title") then
1194 else if json_object
.has_key
("color") then
1196 else if json_object
.has_key
("event") then
1198 else if json_object
.has_key
("original_commit_id") then
1199 return "ReviewComment"
1200 else if json_object
.has_key
("commit_id") then
1201 return "CommitComment"
1202 else if json_object
.has_key
("issue_url") then
1203 return "IssueComment"
1204 else if json_object
.has_key
("total_count") then
1205 return "SearchResults"
1210 redef fun deserialize_class
(name
) do
1211 if name
== "Issue" then
1212 var issue
= super.as(Issue)
1213 if path
.last
.has_key
("pull_request") then
1214 issue
.is_pull_request
= true
1217 else if name
== "Commit" then
1218 var commit
= super.as(Commit)
1219 var git_commit
= commit
.commit
1220 if git_commit
!= null then commit
.message
= git_commit
.message
1227 # Gets the Github token from `git` configuration
1229 # Return the value of `git config --get github.oauthtoken`
1230 # or `""` if no key exists.
1231 fun get_github_oauth
: String
1233 var p
= new ProcessReader("git", "config", "--get", "github.oauthtoken")
1234 var token
= p
.read_line