- fun owner: User do
- return new User.from_json(api, json["owner"].as(JsonObject))
- end
-
- # List of branches associated with their names.
- fun branches: Map[String, Branch] do
- api.message(1, "Get branches for {full_name}")
- var array = api.get("repos/{full_name}/branches")
- var res = new HashMap[String, Branch]
- if not array isa JsonArray then return res
- for obj in array do
- if not obj isa JsonObject then continue
- var name = obj["name"].to_s
- res[name] = new Branch.from_json(api, self, obj)
- end
- return res
- end
-
- # List of issues associated with their ids.
- fun issues: Map[Int, Issue] do
- api.message(1, "Get issues for {full_name}")
- var res = new HashMap[Int, Issue]
- var issue = last_issue
- if issue == null then return res
- res[issue.number] = issue
- while issue.number > 1 do
- issue = api.load_issue(self, issue.number - 1)
- assert issue isa Issue
- res[issue.number] = issue
- end
- return res
- end
-
- # Search issues in this repo form an advanced query.
- #
- # Example:
- #
- # ~~~nitish
- # var issues = repo.search_issues("is:open label:need_review")
- # ~~~
- #
- # See <https://developer.github.com/v3/search/#search-issues>.
- fun search_issues(query: String): nullable Array[Issue] do
- query = "search/issues?q={query} repo:{full_name}"
- var response = api.get(query)
- if api.was_error then return null
- var arr = response.as(JsonObject)["items"].as(JsonArray)
- var res = new Array[Issue]
- for obj in arr do
- res.add new Issue.from_json(api, self, obj.as(JsonObject))
- end
- return res
- end
-
- # Get the last published issue.
- fun last_issue: nullable Issue do
- var array = api.get("repos/{full_name}/issues")
- if not array isa JsonArray then return null
- if array.is_empty then return null
- var obj = array.first
- if not obj isa JsonObject then return null
- return new Issue.from_json(api, self, obj)
- end
-
- # List of labels associated with their names.
- fun labels: Map[String, Label] do
- api.message(1, "Get labels for {full_name}")
- var array = api.get("repos/{full_name}/labels")
- var res = new HashMap[String, Label]
- if not array isa JsonArray then return res
- for obj in array do
- if not obj isa JsonObject then continue
- var name = obj["name"].to_s
- res[name] = new Label.from_json(api, self, obj)
- end
- return res
- end
-
- # List of milestones associated with their ids.
- fun milestones: Map[Int, Milestone] do
- api.message(1, "Get milestones for {full_name}")
- var array = api.get("repos/{full_name}/milestones")
- var res = new HashMap[Int, Milestone]
- if array isa JsonArray then
- for obj in array do
- if not obj isa JsonObject then continue
- var number = obj["number"].as(Int)
- res[number] = new Milestone.from_json(api, self, obj)
- end
- end
- return res
- end
-
- # List of pull-requests associated with their ids.
- #
- # Implementation notes: because PR numbers are not consecutive,
- # PR are loaded from pages.
- # See: https://developer.github.com/v3/pulls/#list-pull-requests
- fun pulls: Map[Int, PullRequest] do
- api.message(1, "Get pulls for {full_name}")
- var res = new HashMap[Int, PullRequest]
- var page = 1
- var array = api.get("{key}/pulls?page={page}").as(JsonArray)
- while not array.is_empty do
- for obj in array do
- if not obj isa JsonObject then continue
- var number = obj["number"].as(Int)
- res[number] = new PullRequest.from_json(api, self, obj)
- end
- page += 1
- array = api.get("{key}/pulls?page={page}").as(JsonArray)
- end
- return res
- end
-
- # List of contributor related statistics.
- fun contrib_stats: Array[ContributorStats] do
- api.message(1, "Get contributor stats for {full_name}")
- var res = new Array[ContributorStats]
- var array = api.get("{key}/stats/contributors")
- if array isa JsonArray then
- for obj in array do
- res.add new ContributorStats.from_json(api, obj.as(JsonObject))
- end
- end
- return res
- end