Update gitget.lua

This commit is contained in:
LDDestroier 2020-06-01 16:46:42 -04:00 committed by GitHub
parent 2d63440f5c
commit 637f9f4250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -245,8 +245,9 @@ local sPrint = function(str)
end end
local getFromGitHub local getFromGitHub
getFromGitHub = function(reponame, repopath, filepath, verbose) getFromGitHub = function(reponame, repopath, filepath, branch, verbose)
local jason = http.get("https://api.github.com/repos/" .. reponame .. "/contents/" .. (repopath or ""), { branch = branch or "master"
local jason = http.get("https://api.github.com/repos/" .. reponame .. "/contents/" .. (repopath or "") .. "?ref=" .. branch, {
["Authorization"] = token ["Authorization"] = token
}) })
if not jason then return false end if not jason then return false end
@ -260,12 +261,13 @@ getFromGitHub = function(reponame, repopath, filepath, verbose)
sPrint("'" .. fs.combine(filepath, v.name) .. "'") sPrint("'" .. fs.combine(filepath, v.name) .. "'")
end end
writeToFile(fs.combine(filepath, v.name), http.get(v.download_url).readAll()) writeToFile(fs.combine(filepath, v.name), http.get(v.download_url).readAll())
os.queueEvent("gitget_got", v.name, filepath, v.download_url)
elseif v.type == "dir" then elseif v.type == "dir" then
if verbose then if verbose then
sPrint("'" .. fs.combine(filepath,v.name) .. "'") sPrint("'" .. fs.combine(filepath,v.name) .. "'")
end end
fs.makeDir(fs.combine(filepath, v.name)) fs.makeDir(fs.combine(filepath, v.name))
getFromGitHub(reponame, fs.combine(repopath, v.name), fs.combine(filepath, v.name), verbose) getFromGitHub(reponame, fs.combine(repopath, v.name), fs.combine(filepath, v.name), branch, verbose)
end end
end end
end end
@ -309,7 +311,7 @@ else
local oldtxt = (term.getTextColor and term.getTextColor()) or colors.white local oldtxt = (term.getTextColor and term.getTextColor()) or colors.white
sPrint("Downloading...") sPrint("Downloading...")
term.setTextColor(term.isColor() and colors.green or colors.lightGray) term.setTextColor(term.isColor() and colors.green or colors.lightGray)
getFromGitHub(reponame, repopath, outpath, verbose) getFromGitHub(reponame, repopath, outpath, branch, verbose)
term.setTextColor(oldtxt) term.setTextColor(oldtxt)
sPrint("Downloaded to /" .. fs.combine("", outpath)) sPrint("Downloaded to /" .. fs.combine("", outpath))
end end