Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apis/github
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down