-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.lua
More file actions
45 lines (42 loc) · 1.38 KB
/
github.lua
File metadata and controls
45 lines (42 loc) · 1.38 KB
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
-- Define the function to download a file
function download(url, path)
local response = http.get(url)
if response then
local content = response.readAll()
response.close()
local file = fs.open(path, "w")
file.write(content)
file.close()
else
print("Failed to download " .. url)
end
end
-- Define the function to clone a repository
function clone(repo, dest)
-- If no destination is provided, use the repository name
if not dest then
dest = fs.getName(repo)
end
local repo_api_url = "https://api.github.com/repos/" .. repo .. "/git/trees/master?recursive=1"
local response = http.get(repo_api_url)
if response then
local data = textutils.unserializeJSON(response.readAll())
response.close()
for _, file in ipairs(data.tree) do
if file.type == "blob" then
local file_url = "https://raw.githubusercontent.com/" .. repo .. "/master/" .. file.path
local dest_path = fs.combine(dest, file.path)
download(file_url, dest_path)
end
end
else
print("Failed to clone " .. repo)
end
end
-- Check if a repository was provided
if arg[1] then
-- Use the clone function with the provided repository and optional destination
clone(arg[1], arg[2])
else
print("Please provide a repository to clone.")
end