forked from gvx/luahub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos.lua
155 lines (134 loc) · 4.1 KB
/
repos.lua
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
local repos = {show = {}, keys = {}, collaborators = {}}
function repos.search(query, language, start_page)
local t = ''
if language or start_page then
t = '?'
if language then
t = t .. 'language=' .. language
if start_page then
t = t .. '&'
end
end
if start_page then
t = t .. 'start_page=' .. start_page
end
end
t = luahub._apiquery('repos/search', query .. t)
t = t.repositories
return t, #t > 0 and (t[1].username .. '/' .. t[1].name)
end
local _mt_show = {}
setmetatable(repos.show, _mt_show)
function _mt_show.__call(self, user, repo, extra) --variants: repos.show(user)
--repos.show(user, repo, {description='Blah', ...}
--repos.show(user, repo, 'collaborators') aka repos.show.collaborators(user, repo)
--repos.show(user, repo, 'contributors') aka repos.show.contributors(user, repo)
--repos.show(user, repo, 'network') aka repos.show.network(user, repo)
--repos.show(user, repo, 'languages') aka repos.show.languages(user, repo)
--etc.
--note show.contributors is different: it takes an extra boolean, whether or not to include anons
if type(extra) == 'table' then
local e = {}
for k,v in pairs(extra) do
e['values['..k..']'] = v
end
extra = e
end
local t = luahub._apiquery('repos/show', user, repo, extra)
if t then
t = t[extra] or t.repository or t.repositories
return t
end
end
function _mt_show.__index(self, name)
return function()
local t = luahub._apiquery('repos/show', user, repo, name)
if t then
return t[name]
end
end
end
function repos.watch(user, repo)
luahub._apiquery('repos/watch', user, repo) --no data returned?
end
function repos.unwatch(user, repo)
luahub._apiquery('repos/unwatch', user, repo) --no data returned?
end
function repos.fork(user, repo)
local t = luahub._apiquery('repos/fork', user, repo)
if t then
t = t.repository
return t
end
end
local _mt_keys = {}
setmetatable(repos.keys,_mt_keys)
function _mt_keys.__call(repo)
local t = luahub._apiquery('repos/keys', repo)
if t then
t = t.public_keys
return t
end
end
function repos.keys.add(repo, title, key)
luahub._apiquery('repos/keys', repo, 'add', {title = title, key = key})
end
function repos.keys.remove(repo, key_id)
luahub._apiquery('repos/keys', repo, 'remove', {id = key_id})
end
--[[
function repos.show.collaborators(user, repo)
local t = luahub._apiquery('repos/show', user, repo, 'collaborators')
if t then
return t.collaborators
end
end
--]]
function repos.pushable()
local t = luahub._apiquery('repos/pushable')
return t
end
function repos.show.contributors(user, repo, show_anon)
local t = luahub._apiquery('repos/show', user, repo, 'contributors', show_anon and 'anon')
if t then
return t.contributors
end
end
--[[function repos.show.network(user, repo)
local t = luahub._apiquery('repos/show', user, repo, 'network')
if t then
return t.network
end
end]]
function repos.create(name, description, homepage, public)
luahub._apiquery('repos/create', {name = name, description = description,
homepage = homepage, public = public})
end
function repos.delete(name, token)
local t = luahub._apiquery('repos/delete', name, token and {delete_token=token})
return t.delete_token
end
function repos.setprivate(name)
luahub._apiquery('repos/set/private', name, {}) -- empty table forces POST
end
function repos.setpublic(name)
luahub._apiquery('repos/set/public', name, {}) -- empty table forces POST
end
function repos.collaborators.add(repo, user)
luahub._apiquery('repos/collaborators', repo, 'add', user, {}) -- empty table forces POST
end
function repos.collaborators.remove(repo, user)
luahub._apiquery('repos/collaborators', repo, 'remove', user, {}) -- empty table forces POST
end
function repos.watched(user)
local t = luahub._apiquery('repos/watched', user, repo)
if t then
t = t.repositories
return t
end
end
function repos.tags( repo, user )
local t = luahub._apiquery( 'repos/show', user, repo, 'tags' )
return t.tags
end
luahub.repos = repos