Skip to content
Snippets Groups Projects
Commit 3cdab89e authored by Adrien Lescourt's avatar Adrien Lescourt
Browse files

Improve stdout messages for repo creations

parent f0839518
Branches refactor
No related tags found
No related merge requests found
...@@ -112,7 +112,13 @@ class Gitlab: ...@@ -112,7 +112,13 @@ class Gitlab:
print(f"Error searching user {user.user_login_aai}") print(f"Error searching user {user.user_login_aai}")
print(res.text) print(res.text)
else: else:
return str(res.json()[0]["id"]) res_json = res.json()
if len(res_json) == 1:
return str(res.json()[0]["id"])
elif len(res_json) > 1:
print(f"ERROR: More than one users found for {user.user_login_aai}")
else:
print(f"ERROR: No user found for {user.user_login_aai}")
def add_users_to_repository( def add_users_to_repository(
self, self,
...@@ -120,8 +126,8 @@ class Gitlab: ...@@ -120,8 +126,8 @@ class Gitlab:
project_name: str, project_name: str,
users: list[User], users: list[User],
expires_at: str | None, expires_at: str | None,
): ) -> list[User]:
"""Add users to a repo, and set their permissions""" """Add users to a repo, and set their permissions, returns all user added"""
headers = {"PRIVATE-TOKEN": self.token} headers = {"PRIVATE-TOKEN": self.token}
# Allow users with developer access level to push and merge on master # Allow users with developer access level to push and merge on master
access_level = 40 access_level = 40
...@@ -140,12 +146,14 @@ class Gitlab: ...@@ -140,12 +146,14 @@ class Gitlab:
f"Error setting project ({project_name}) premissions", res.text f"Error setting project ({project_name}) premissions", res.text
) )
added_users = []
for user in users: for user in users:
user_id = self.get_user_id(user) user_id = self.get_user_id(user)
if user_id is None: if user_id is None:
print( print(
f"ERROR: User {user.user_login_aai} will not be added to project: {project_name}" f"ERROR: User {user.user_login_aai} will not be added to project: {project_name}"
) )
continue
params = {"user_id": user_id, "access_level": access_level} params = {"user_id": user_id, "access_level": access_level}
if expires_at: if expires_at:
params["expires_at"] = expires_at params["expires_at"] = expires_at
...@@ -159,6 +167,8 @@ class Gitlab: ...@@ -159,6 +167,8 @@ class Gitlab:
f"ERROR: User {user.user_login_aai} will not be added to project: {project_name}" f"ERROR: User {user.user_login_aai} will not be added to project: {project_name}"
) )
print(res.text) print(res.text)
added_users.append(user)
return added_users
def create_repository( def create_repository(
self, self,
...@@ -328,11 +338,11 @@ def command_create_group_repos(args): ...@@ -328,11 +338,11 @@ def command_create_group_repos(args):
group.name, group.name,
args.import_url, args.import_url,
) )
gl.add_users_to_repository( added_users = gl.add_users_to_repository(
project_id, group.name, group.user_ids, args.expires_at project_id, group.name, group.user_ids, args.expires_at
) )
print( print(
f"Created repo: {group.name} with the users: {[u.user_login_aai for u in group.user_ids]}" f"Created repo: {group.name} with the users: {[u.user_login_aai for u in added_users]}"
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment