def _import_project_repo_collaborators(gitea_api: pygitea.API, collaborators: T.List[gitlab.v4.objects.ProjectMember], project: gitlab.v4.objects.Project): for collaborator in collaborators: if not collaborator_exists(gitea_api, project.namespace['name'], name_clean(project.name), collaborator.username): permission = "read" if collaborator.access_level == 10: # guest access permission = "read" elif collaborator.access_level == 20: # reporter access permission = "read" elif collaborator.access_level == 30: # developer access permission = "write" elif collaborator.access_level == 40: # maintainer access permission = "admin" elif collaborator.access_level == 50: # owner access (only for groups) print_error("Groupmembers are currently not supported!") continue # groups are not supported else: print_warning("Unsupported access level " + str(collaborator.access_level) + ", setting permissions to 'read'!") import_response: requests.Response = gitea_api.put("/repos/" + project.namespace['name'] +"/" + name_clean(project.name) + "/collaborators/" + collaborator.username, json={ "permission": permission }) if import_response.ok: print_info("Collaborator " + collaborator.username + " imported!") else: print_error("Collaborator " + collaborator.username + " import failed: " + import_response.text)
def _import_group_members(gitea_api: pygitea.API, members: T.List[gitlab.v4.objects.GroupMember], group: gitlab.v4.objects.Group): # TODO: create teams based on gitlab permissions (access_level of group member) existing_teams = get_teams(gitea_api, name_clean(group.name)) if existing_teams: first_team = existing_teams[0] print("Organization teams fetched, importing users to first team: " + first_team['name']) # add members to teams for member in members: if not member_exists(gitea_api, member.username, first_team['id']): import_response: requests.Response = gitea_api.put("/teams/" + str(first_team['id']) + "/members/" + member.username) if import_response.ok: print_info("Member " + member.username + " added to group " + name_clean(group.name) + "!") else: print_error("Failed to add member " + member.username + " to group " + name_clean(group.name) + "!") else: print_error("Failed to import members to group " + name_clean(group.name) + ": no teams found!")