- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_api.lua
More file actions
Latest commit
64 lines (56 loc) · 1.92 KB
/
Copy pathgithub_api.lua
File metadata and controls
64 lines (56 loc) · 1.92 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
lunajson=require'lunajson'
os_capture=require'os_capture'
tprint=require'tprint'
localfunctionchar_to_hex(c)
returnstring.format("%%%02X", string.byte(c))
end
localfunctionurlencode(url)
-- from https://gist.github.com/liukun/f9ce7d6d14fa45fe9b924a3eed5c3d99
ifurl==nilthen
return
end
url=url:gsub("\n", "\r\n")
url=url:gsub("([^%w ])", char_to_hex)
url=url:gsub("", "+")
returnurl
end
functionsearch_repositories(count)
-- maximum count of 100, requires `gh` to be available in the cmdline
count=countor30-- I could support higher than 100, but then I'd need to implement pagination
localsearch_urlquery="per_page="..count..
"&s=stars" ..
"&q="..urlencode("language:lua created:<2016 pushed:>=2024 archived:false fork:false")
localcommand='gh api' ..
' -H "Accept: application/vnd.github+json"' ..
' -H "X-GitHub-Api-Version: 2026-03-10"' ..
' "/search/repositories?' ..search_urlquery..'"'
-- print(command)
localoutput=os_capture(command)
localparsed=lunajson.decode(output)
returnparsed
end
functionremove_repository(path)
returnos_capture('rmdir /S /Q "' ..path..'"')
end
functionclone_repository(name, dir)
-- where name is formatted as "user/repo"
-- assumes existence of `cloned-repos` directory
-- REMOVES currently named repository
localrepo=name:gsub(".*/", "")
localgit_clone="git clone -c core.protectNTFS=false https://github.com/" ..name..".git"
-- protectNTFS=false allows us to clone repos with colliding paths due to casing (which is fine on Linux, but not Windows)
localrm, c
ifdirthen
rm=remove_repository(dir.."/" ..repo)
c=os_capture("cd " ..dir.." & " ..git_clone)
else
rm=remove_repository(repo)
c=os_capture(git_clone)
end
return {rm, c}
end
return {
search_repositories=search_repositories,
remove_repository=remove_repository,
clone_repository=clone_repository,
}