1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-17 06:04:50 +00:00
opus/sys/apis/git.lua

45 lines
992 B
Lua
Raw Normal View History

2016-12-27 03:26:43 +00:00
local json = require('json')
2016-12-11 21:36:36 +00:00
local Util = require('util')
2016-12-11 19:24:52 +00:00
local TREE_URL = 'https://api.github.com/repos/%s/%s/git/trees/%s?recursive=1'
local FILE_URL = 'https://raw.github.com/%s/%s/%s/%s'
local git = { }
function git.list(user, repo, branch)
branch = branch or 'master'
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 = { }
for k,v in pairs(data.tree) do
if v.type == "blob" then
v.path = v.path:gsub("%s","%%20")
2017-05-20 00:55:19 +00:00
list[v.path] = {
url = string.format(FILE_URL, user, repo, branch, v.path),
size = v.size,
}
2016-12-11 19:24:52 +00:00
end
end
return list
end
return git