Skip to content

Commit 43ffabf

Browse files
Kristián LeškoJared Murrell
authored andcommitted
Add support for ignoring GitHub users
In some cases, a user may be added to teams even without directory account. Add support to keep the user in team.
1 parent 3932149 commit 43ffabf

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

app.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def sync_team(client=None, owner=None, team_id=None, slug=None):
6464
try:
6565
org = client.organization(owner)
6666
team = org.team(team_id)
67-
custom_map = load_custom_map()
67+
custom_map, ignore_users = load_custom_map()
6868
try:
6969
directory_group = custom_map[slug] if slug in custom_map else slug
7070
directory_members = directory_group_members(group=directory_group)
@@ -73,7 +73,8 @@ def sync_team(client=None, owner=None, team_id=None, slug=None):
7373
traceback.print_exc(file=sys.stderr)
7474

7575
team_members = github_team_members(
76-
client=client, owner=owner, team_id=team_id, attribute=USER_SYNC_ATTRIBUTE
76+
client=client, owner=owner, team_id=team_id,
77+
attribute=USER_SYNC_ATTRIBUTE, ignore_users=ignore_users
7778
)
7879
compare = compare_members(
7980
group=directory_members, team=team_members, attribute=USER_SYNC_ATTRIBUTE
@@ -124,9 +125,9 @@ def github_team_info(client=None, owner=None, team_id=None):
124125
return org.team(team_id)
125126

126127

127-
def github_team_members(client=None, owner=None, team_id=None, attribute="username"):
128+
def github_team_members(client=None, owner=None, team_id=None, attribute="username", ignore_users=[]):
128129
"""
129-
Look up members of a give team in GitHub
130+
Look up members of a given team in GitHub
130131
:param client:
131132
:param owner:
132133
:param team_id:
@@ -151,7 +152,7 @@ def github_team_members(client=None, owner=None, team_id=None, attribute="userna
151152
else:
152153
for member in team.members():
153154
team_members.append({"username": str(member), "email": ""})
154-
return team_members
155+
return [m for m in team_members if m["username"] not in ignore_users]
155156

156157

157158
def compare_members(group, team, attribute="username"):
@@ -241,6 +242,7 @@ def load_custom_map(file="syncmap.yml"):
241242
:return:
242243
"""
243244
syncmap = {}
245+
ignore_users = []
244246
if os.path.isfile(file):
245247
from yaml import load, Loader
246248

@@ -249,7 +251,9 @@ def load_custom_map(file="syncmap.yml"):
249251
for d in data["mapping"]:
250252
syncmap[d["github"]] = d["directory"]
251253

252-
return syncmap
254+
ignore_users = data.get('ignore_users', [])
255+
256+
return (syncmap, ignore_users)
253257

254258

255259
def get_app_installations():
@@ -279,7 +283,7 @@ def sync_all_teams():
279283
print(f'Syncing all teams: {time.strftime("%A, %d. %B %Y %I:%M:%S %p")}')
280284

281285
installations = get_app_installations()
282-
custom_map = load_custom_map()
286+
custom_map, _ = load_custom_map()
283287
futures = []
284288
install_count = 0
285289
with ThreadPoolExecutor(max_workers=10) as exe:

syncmap.yml.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ mapping:
44
directory: ldap super users
55
- github: demo-team-2
66
directory: another-group
7+
8+
ignore_users:
9+
- userA
10+
- userB
11+
- userC

0 commit comments

Comments
 (0)