2016-12-26 22:26:43 -05:00
|
|
|
local json = require('json')
|
2016-12-11 16:36:36 -05:00
|
|
|
local Util = require('util')
|
2016-12-11 14:24:52 -05:00
|
|
|
|
|
|
|
local TREE_URL = 'https://api.github.com/repos/%s/%s/git/trees/%s?recursive=1'
|
2017-09-30 20:35:36 -04:00
|
|
|
local FILE_URL = 'https://raw.githubusercontent.com/%s/%s/%s/%s'
|
2016-12-11 14:24:52 -05:00
|
|
|
|
|
|
|
local git = { }
|
|
|
|
|
2017-10-08 17:45:01 -04:00
|
|
|
function git.list(repository)
|
2017-09-15 20:27:56 -04:00
|
|
|
|
2017-10-08 17:45:01 -04:00
|
|
|
local t = Util.split(repository, '(.-)/')
|
2017-09-15 20:27:56 -04:00
|
|
|
|
|
|
|
local user = t[1]
|
|
|
|
local repo = t[2]
|
|
|
|
local branch = t[3] or 'master'
|
2016-12-11 14:24:52 -05:00
|
|
|
|
|
|
|
local dataUrl = string.format(TREE_URL, user, repo, branch)
|
|
|
|
local contents = Util.download(dataUrl)
|
|
|
|
|
|
|
|
if not contents then
|
|
|
|
error('Invalid repository')
|
|
|
|
end
|
|
|
|
|
|
|
|
local data = json.decode(contents)
|
|
|
|
|
|
|
|
if data.message and data.message:find("API rate limit exceeded") then
|
|
|
|
error("Out of API calls, try again later")
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.message and data.message == "Not found" then
|
|
|
|
error("Invalid repository")
|
|
|
|
end
|
|
|
|
|
|
|
|
local list = { }
|
|
|
|
|
2017-10-08 17:45:01 -04:00
|
|
|
for _,v in pairs(data.tree) do
|
2016-12-11 14:24:52 -05:00
|
|
|
if v.type == "blob" then
|
|
|
|
v.path = v.path:gsub("%s","%%20")
|
2017-05-19 20:55:19 -04:00
|
|
|
list[v.path] = {
|
|
|
|
url = string.format(FILE_URL, user, repo, branch, v.path),
|
|
|
|
size = v.size,
|
|
|
|
}
|
2016-12-11 14:24:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return list
|
|
|
|
end
|
|
|
|
|
|
|
|
return git
|