-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathansible-roles
executable file
·60 lines (44 loc) · 1.57 KB
/
ansible-roles
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
#!/usr/bin/env python
"""Helper tool to create a requirements.yml file with all ansible-roles.
Usage:
ansible-roles (-h | --help)
ansible-roles [--org=<name>]
Options:
-h --help Show this message.
-o --org=<name> Organization to search [default: cisagov].
"""
import sys
import docopt
from github import Github
VERSION = "0.0.1"
def eprint(*args, **kwargs):
"""Print to stderr."""
print(*args, file=sys.stderr, **kwargs)
def print_reqs(org):
"""Output a list of all ansible-roles in requirements.yml format."""
# There is a bug in the pager (API or library) that spuriously returns
# duplicate results. So set per_page high enough to get one page.
g = Github(per_page=512)
repos = g.search_repositories(
query=f"org:{org} topic:ansible-role NOT skeleton archived:false"
)
sorted_repos = sorted(repos, key=lambda r: r.html_url)
eprint(f"Adding {len(sorted_repos)} ansible-roles.")
prev_repo = None
for repo in sorted_repos:
if prev_repo and repo.id == prev_repo.id:
eprint(">>> DUP >>>")
# github api bug? Same repo can be returned more than once.
continue
short_name = repo.name.replace("ansible-role-", "").replace("-", "_")
print(f"- src: {repo.html_url}")
print(f" name: {short_name}")
prev_repo = repo
def main():
"""Parse arguments and perform requested actions."""
args = docopt.docopt(__doc__, version=VERSION)
org = args["--org"]
print_reqs(org)
return 0
if __name__ == "__main__":
sys.exit(main())