From c23a3335a63f3ecfede06b11afea7bdb144be672 Mon Sep 17 00:00:00 2001 From: Dan Ports Date: Sun, 19 Apr 2020 14:37:58 -0700 Subject: [PATCH] #30: Support for GitHub commits. --- apis/github | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/apis/github b/apis/github index aa01e91..b340ea5 100644 --- a/apis/github +++ b/apis/github @@ -63,6 +63,25 @@ Auth.delete = function(user) writeAuth(authTable) end +-- A class for a commit +local Commit = {} +Commit.__index = Commit +Commit.new = function(repo, sha) + -- Documented here: https://developer.github.com/v3/git/trees/ + local url = ('repos/%s/%s/git/commits/%s'):format(repo.user, repo.name, sha) + local status, data = getAPI(url, repo.auth) + if not status then + error('Could not get commit github API from ' ..url) + end + return setmetatable({ + repo = repo, + sha = sha, + author = data.author, + committer = data.committer, + message = data.message + }, Commit) +end + -- A class for a blob (aka a file) local Blob = {} Blob.__index = Blob @@ -121,6 +140,9 @@ local function walkTree(t, level) end end end +Tree.getCommit = function(self) + return Commit.new(self.repo, self.sha) +end Tree.iter = function(self) return coroutine.wrap(function() walkTree(self, 0) @@ -176,6 +198,7 @@ Repository.__tostring = function(self) return ("Repo@%s/%s"):format(self.user, s -- Export members local github = {} github.Repository = Repository +github.Commit = Commit github.Blob = Blob github.Tree = Tree github.Auth = Auth