-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.lua
46 lines (35 loc) · 1.02 KB
/
object.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local table = table
local error = error
local require = require
local assert = assert
local print = print
--- GitHub API
module "ghlua"
require "ghlua.util"
require "ghlua.repository"
local request = require("socket.http").request
local decode = require("json").decode
local repo = _REPO
function repo:getTree(sha)
return action("tree", "show", self.user, self.repo, sha).tree
end
function repo:getBlob(tree, path, excludeData)
checkArg(2, "string", path)
local args
if excludeData then
args = {meta = 1}
end
return get(table.concat({"blob/show", self.user, self.repo, tree, path}, "/"), args).blob
end
-- !!! does not give anything like an error for blobs that weren't found !!!
function repo:getBlobData(blob)
local url = apiUrl(table.concat({"blob/show", self.user, self.repo, blob}, "/"))
print(url)
local body, status, headers, statusline = request(url)
if not body then
error(("blob get failed: %s (%s)"):format(url, statusline), 2)
elseif status ~= 200 then
error(decode(body).error, 2)
end
return body
end