+
+ # 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
+
+ # 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
+end
+
+# A Github branch.
+#
+# Should be accessed from `GithubAPI::load_branch`.
+#
+# See <https://developer.github.com/v3/repos/#list-branches>.
+class Branch
+ super RepoEntity
+
+ redef var key is lazy do return "{repo.key}/branches/{name}"
+
+ # Branch name.
+ var name: String
+
+ redef init from_json(api, repo, json) do
+ self.name = json["name"].to_s
+ super
+ end