-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_all_repos_env_data.py
62 lines (49 loc) · 1.44 KB
/
get_all_repos_env_data.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
52
53
54
55
56
57
58
59
60
61
62
"""
TODO
"""
import json
from pprint import pprint
from github import Github
from github import Auth
# WARNING: do not commit personal tokens!
MY_TOKEN = "<ADD TOKEN HERE>"
ORG_NAME = "ES-DOC"
auth = Auth.Token(MY_TOKEN)
# Public Web Github
g = Github(auth=auth)
# Get the ES-DOC org
o = g.get_organization(ORG_NAME)
# Get all repositories
repos = o.get_repos()
# Create a mapping to store per-repo content
repo_env_content = {}
for repo in repos:
# Get env-related content:
# TODO: how to handle lack of files
# 'github.GithubException.UnknownObjectException' raising? (see try/except)
filenames = {
"REQS": "requirements.txt",
"SETUP": "setup.py",
"PIPFILE": "Pipfile",
"PIPFILE LOCK": "Pipfile.lock",
}
repo_env_content[repo.full_name] = {}
for f_key, f_name in filenames.items():
try:
f_exists = repo.get_contents(f_name)
except:
f_exists = False
if f_exists:
f_url = f_exists.html_url
# Add to registry of env content, else don't add is doesn't exist
repo_env_content[repo.full_name][f_name] = f_url
# Report
print("Repo names are:")
pprint([r.full_name for r in repos])
print("Repo env-related content found at:")
pprint(repo_env_content)
# Must close connections after use
g.close()
# Save details to a file for reference, as JSON
with open("repo-report.json", "w") as f:
json.dump(repo_env_content, f)