-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathget_community_team_data.py
96 lines (80 loc) · 2.58 KB
/
get_community_team_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
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
"""
This script pulls the members of the Community Team from the databag in the
OS@CC repository, formats it to match the required structure for setting up
GitHub teams and then syncs the teams to GitHub.
This file intentionally has an external API identical to that of
`push_data_to_ccos/get_community_team_data.py`.
"""
# Standard library
import inspect
import logging
import os.path
import re
# Third-party
import requests
# First-party/Local
from ccos import log
# Constants should match 'push_data_to_ccos/push_data_via_git.py'
GITHUB_ORGANIZATION = "creativecommons"
GITHUB_REPO_NAME = "creativecommons.github.io-source"
# Constants should match 'push_data_to_ccos/sync_data.py'
CT_MEMBERS = "community_team_members.json"
DATABAG_URL = (
f"https://raw.githubusercontent.com/{GITHUB_ORGANIZATION}/"
f"{GITHUB_REPO_NAME}/main/databags/{CT_MEMBERS}"
)
log_name = os.path.basename(os.path.splitext(inspect.stack()[-1].filename)[0])
logger = logging.getLogger(log_name)
log.reset_handler()
def fetch_databag():
"""
This method pulls the team members from CCOS and
and loads them into the databag after a little
formatting. The databag schema is below.
databag schema
{
"projects": [
{
"name": "",
"repos: [
"",
...
],
"members": [
{
"name": "",
"github": ""
},
...
]
},
...
]
}
"""
logging.log(logging.INFO, "Pulling from OS@CC...")
databag = {"projects": []}
request = requests.get(DATABAG_URL)
request.raise_for_status()
projects = request.json()["projects"]
logging.log(logging.INFO, "Team members pulled.")
logging.log(logging.INFO, "Processing team members...")
for project in projects:
formatted_project = {
"name": project["name"],
"repos": re.split(r",\s?", project["repos"]),
"roles": {},
}
members = project["members"]
for member in members:
role = member["role"]
if role not in formatted_project["roles"]:
formatted_project["roles"][role] = []
del member["role"]
formatted_project["roles"][role].append(member)
databag["projects"].append(formatted_project)
logging.log(log.SUCCESS, "Done.")
logging.log(log.SUCCESS, "Pull successful.")
return databag
def get_community_team_data():
return fetch_databag()