- # 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
-
- # 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
-
- # Repo default branch.
- fun default_branch: Branch do
- var name = json["default_branch"].to_s
- var branch = api.load_branch(self, name)
- assert branch isa Branch
- return branch
- end
-end
-
-# A `RepoEntity` is something contained in a `Repo`.
-abstract class RepoEntity
- super GithubEntity
-
- # Repo that contains `self`.
- var repo: Repo
-
- # Init `self` from a `json` object.
- init from_json(api: GithubAPI, repo: Repo, json: JsonObject) do
- self.api = api
- self.repo = repo
- self.json = json
- end