lib/github: handles github files
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 19 Dec 2014 18:22:11 +0000 (13:22 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 13 Jan 2015 16:39:56 +0000 (17:39 +0100)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/github/api.nit

index def3bcc..b979b5d 100644 (file)
@@ -636,6 +636,17 @@ class Commit
                return new ISODate.from_string(author["date"].to_s)
        end
 
+       # List files staged in this commit.
+       fun files: Array[GithubFile] do
+               var res = new Array[GithubFile]
+               var files = json["files"]
+               if not files isa JsonArray then return res
+               for obj in files do
+                       res.add(new GithubFile(obj.as(JsonObject)))
+               end
+               return res
+       end
+
        # Commit message.
        fun message: String do return json["commit"].as(JsonObject)["message"].to_s
 end
@@ -1200,3 +1211,15 @@ class ContributorStats
        # ContributorStats can be compared on the total amount of commits.
        redef fun <(o) do return total < o.total
 end
+
+# A Github file representation.
+#
+# Mostly a wrapper around a json object.
+class GithubFile
+
+       # Json content.
+       var json: JsonObject
+
+       # File name.
+       fun filename: String do return json["filename"].to_s
+end