Skip to content

Commit 34254cc

Browse files
authored
Update app.py for ADD_MEMBER attribute
More information in issue: - #214 CHANGES: - ADD: if-statement to check if ADD_MEMBER attribute is `true` and if the user is not a member of the organization - Uses the org.add_or_update_membership function to add the user to the organization - CHANGE: if-statement to add a user to a GitHub team only if they are a member of the organization already
1 parent 743e8a8 commit 34254cc

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

app.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,19 @@ def execute_sync(org, team, slug, state):
211211
raise AssertionError(message)
212212
else:
213213
for user in state["action"]["add"]:
214-
# Validate that user is in org
215-
if org.is_member(user) or ADD_MEMBER:
214+
# Add user to org if they are not already a member and the ADD_MEMBER attribute is "true"
215+
if not org.is_member(user) and ADD_MEMBER:
216+
try:
217+
print(f"User: {user} is not in the {org.login} organization. Attempting to add.")
218+
org.add_or_update_membership(user)
219+
except Exception as e:
220+
print(f"Error adding {user} to {org.login}: {e}")
221+
pass
222+
else:
223+
print(f"User: {user} is already a member of the {org.login} organization or ADD_MEMBER is false")
224+
225+
# Add user to team if they are a member of the org
226+
if org.is_member(user):
216227
try:
217228
print(f"Adding {user} to {slug}")
218229
team.add_or_update_membership(user)

0 commit comments

Comments
 (0)