- # 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"].as(String)
- 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"].as(String)
- var branch = api.load_branch(self, name)
- assert branch isa Branch
- return branch
- end
-
- # Set the default branch
- fun default_branch=(branch: Branch) do json["default_branch"] = branch.json
-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