-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdl_webhooks.py
51 lines (40 loc) · 1.5 KB
/
dl_webhooks.py
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
from mirror import SSHAgent
from subprocess import check_call
from collections import defaultdict
import json
import gitlab
class DlGitlabProjects(object):
def __init__(self, agent, gl):
self.agent = agent
self.gl = gl
def run(self):
projects = self.get_gitlab_projects()
hooks = defaultdict(list)
for name, project in projects.items():
# import ipdb ; ipdb.set_trace()
for hook in self.gl.project_hooks.list(project_id=project.id):
hooks[name].append(hook.url)
with open("./hooks.json", "w") as f:
json.dump(dict(hooks), f, sort_keys=True, indent=4)
def get_gitlab_projects(self):
page = 0
all_projects = {}
while True:
projects = self.gl.projects.list(per_page=10, page=page, owned=True)
page += 1
if not projects:
break
for item in projects:
# if item.visibility == 'public': # or "githubmirror" not in item.tag_list:
# continue
all_projects[item.name] = item
return all_projects
def main():
with open("creds.json") as f:
creds = json.load(f)
gitlab_api = gitlab.Gitlab(creds["gitlab"]["url"], creds["gitlab"]["token"], api_version=4)
with SSHAgent() as agent:
check_call(["ssh-add", creds["identity"]], env={"SSH_AUTH_SOCK": agent})
DlGitlabProjects(agent, gitlab_api).run()
if __name__ == '__main__':
main()