code: explicitly call init in some named constructors
[nit.git] / lib / github / api.nit
index 6b1935e..59917c5 100644 (file)
@@ -557,8 +557,7 @@ abstract class RepoEntity
 
        # Init `self` from a `json` object.
        init from_json(api: GithubAPI, repo: Repo, json: JsonObject) do
-               self.api = api
-               self.repo = repo
+               init(api, repo)
                self.json = json
        end
 end
@@ -732,6 +731,12 @@ class Issue
                super
        end
 
+       # Issue id.
+       fun id: Int do return json["id"].as(Int)
+
+       # Set issue id.
+       fun id=(id: Int) do json["id"] = id
+
        # Issue title.
        fun title: String do return json["title"].as(String)
 
@@ -814,10 +819,16 @@ class Issue
                        for obj in array do
                                if not obj isa JsonObject then continue
                                var id = obj["id"].as(Int)
-                               res.add(api.load_issue_comment(repo, id).as(not null))
+                               var comment = api.load_issue_comment(repo, id)
+                               if comment == null then continue
+                               res.add(comment)
                        end
                        page += 1
-                       array = api.get("{key}/comments?page={page}").as(JsonArray)
+                       var json = api.get("{key}/comments?page={page}")
+                       if not json isa JsonArray then
+                               return res
+                       end
+                       array = json
                end
                return res
        end
@@ -909,6 +920,9 @@ class Issue
                        json["closed_by"] = user.json
                end
        end
+
+       # Is this issue linked to a pull request?
+       fun is_pull_request: Bool do return json.has_key("pull_request")
 end
 
 # A Github pull request.
@@ -1557,8 +1571,7 @@ class ContributorStats
 
        # Init `self` from a `json` object.
        init from_json(api: GithubAPI, json: JsonObject) do
-               self.api = api
-               self.json = json
+               init(api, json)
        end
 
        # User these statistics are about.