Loading gitlab_cp/sync.py +13 −13 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ class GlVisibility(str, Enum): internal = "internal" private = "private" def __str__(self): def __str__(self) -> str: return self.name Loading @@ -71,7 +71,7 @@ class Synchronizer: dest_sync_path: str, work_dir: Path, max_visibility=GlVisibility.public, exclude: list[str] = None, exclude: Optional[list[str]] = None, update_release=False, group_description=True, project_description=True, Loading @@ -92,17 +92,17 @@ class Synchronizer: self.dry_run = dry_run self.continue_on_error = continue_on_error self.force_update_avatar = update_avatar self.errors = [] self.warnings = [] self.errors: list[Exception] = [] self.warnings: list[Exception] = [] self.groups_count = 0 self.projects_count = 0 def handle_error(self, err: Exception): def handle_error(self, err: Exception) -> None: self.errors.append(err) if not self.continue_on_error: raise err def handle_warn(self, err: Exception): def handle_warn(self, err: Exception) -> None: self.warnings.append(err) def adjust_visibility(self, visi: GlVisibility) -> str: Loading Loading @@ -171,7 +171,7 @@ class Synchronizer: self, src_project: Project, dest_project: Project, ): ) -> None: src_releases = src_project.releases.list(all=True) print(f" - sync {len(src_releases)} releases...") dest_releases = dest_project.releases.list(all=True) Loading Loading @@ -237,7 +237,7 @@ class Synchronizer: f" - {tag_name}: {AnsiColors.HGRAY}up-to-date{AnsiColors.RESET}" ) def sync_git_repo(self, src_project: Project, dest_project: Project): def sync_git_repo(self, src_project: Project, dest_project: Project) -> None: src_default_branch = src_project.default_branch try: src_latest_commit: ProjectCommit = next( Loading Loading @@ -353,7 +353,7 @@ class Synchronizer: try: dest_project.protectedbranches.create({"name": src_default_branch}) except GitlabCreateError as ge: if ge.response_code != 409 & ge.response_code != 422: if ge.response_code != 409 and ge.response_code != 422: print( f" - protect default branch ({src_default_branch}) in dest project: {AnsiColors.HRED}failed{AnsiColors.RESET}", ge, Loading @@ -367,7 +367,7 @@ class Synchronizer: # Synchronizes a GitLab project # $1: source project JSON # $2: destination parent group ID (number) def sync_project(self, src_project: Project, dest_parent_group: Group): def sync_project(self, src_project: Project, dest_parent_group: Optional[Group]) -> None: dest_project_path = self.to_dest_path(src_project.path_with_namespace) print( f" - 🏠 Project {AnsiColors.BLUE}{src_project.path_with_namespace}{AnsiColors.RESET} ({src_project.get_id()}) => {AnsiColors.BLUE}{dest_project_path}{AnsiColors.RESET}..." Loading Loading @@ -443,7 +443,7 @@ class Synchronizer: "visibility": dest_visibility, "description": src_project.description, # ??? "default_branch": src_default_branch, "namespace_id": dest_parent_group.get_id(), "namespace_id": dest_parent_group.get_id() if dest_parent_group else None, "issues_access_level": "disabled", "merge_requests_access_level": "disabled", } Loading Loading @@ -504,7 +504,7 @@ class Synchronizer: self.sync_releases(src_project, dest_project) # Synchronizes recursively a GitLab group def sync_group(self, src_group: Group, dest_parent_group: Group): def sync_group(self, src_group: Group, dest_parent_group: Group) -> None: dest_group_full_path = self.to_dest_path(src_group.full_path) print( f"🏢 Group {AnsiColors.BLUE}{src_group.full_path}{AnsiColors.RESET} ({src_group.get_id()}) => {AnsiColors.BLUE}{dest_group_full_path}{AnsiColors.RESET}..." Loading Loading @@ -696,7 +696,7 @@ def to_url(api_url: str) -> str: return api_url[0:-7] if api_url.endswith("/api/v4") else api_url def run(): def run() -> None: # define command parser parser = argparse.ArgumentParser( prog="gitlab-cp", Loading Loading
gitlab_cp/sync.py +13 −13 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ class GlVisibility(str, Enum): internal = "internal" private = "private" def __str__(self): def __str__(self) -> str: return self.name Loading @@ -71,7 +71,7 @@ class Synchronizer: dest_sync_path: str, work_dir: Path, max_visibility=GlVisibility.public, exclude: list[str] = None, exclude: Optional[list[str]] = None, update_release=False, group_description=True, project_description=True, Loading @@ -92,17 +92,17 @@ class Synchronizer: self.dry_run = dry_run self.continue_on_error = continue_on_error self.force_update_avatar = update_avatar self.errors = [] self.warnings = [] self.errors: list[Exception] = [] self.warnings: list[Exception] = [] self.groups_count = 0 self.projects_count = 0 def handle_error(self, err: Exception): def handle_error(self, err: Exception) -> None: self.errors.append(err) if not self.continue_on_error: raise err def handle_warn(self, err: Exception): def handle_warn(self, err: Exception) -> None: self.warnings.append(err) def adjust_visibility(self, visi: GlVisibility) -> str: Loading Loading @@ -171,7 +171,7 @@ class Synchronizer: self, src_project: Project, dest_project: Project, ): ) -> None: src_releases = src_project.releases.list(all=True) print(f" - sync {len(src_releases)} releases...") dest_releases = dest_project.releases.list(all=True) Loading Loading @@ -237,7 +237,7 @@ class Synchronizer: f" - {tag_name}: {AnsiColors.HGRAY}up-to-date{AnsiColors.RESET}" ) def sync_git_repo(self, src_project: Project, dest_project: Project): def sync_git_repo(self, src_project: Project, dest_project: Project) -> None: src_default_branch = src_project.default_branch try: src_latest_commit: ProjectCommit = next( Loading Loading @@ -353,7 +353,7 @@ class Synchronizer: try: dest_project.protectedbranches.create({"name": src_default_branch}) except GitlabCreateError as ge: if ge.response_code != 409 & ge.response_code != 422: if ge.response_code != 409 and ge.response_code != 422: print( f" - protect default branch ({src_default_branch}) in dest project: {AnsiColors.HRED}failed{AnsiColors.RESET}", ge, Loading @@ -367,7 +367,7 @@ class Synchronizer: # Synchronizes a GitLab project # $1: source project JSON # $2: destination parent group ID (number) def sync_project(self, src_project: Project, dest_parent_group: Group): def sync_project(self, src_project: Project, dest_parent_group: Optional[Group]) -> None: dest_project_path = self.to_dest_path(src_project.path_with_namespace) print( f" - 🏠 Project {AnsiColors.BLUE}{src_project.path_with_namespace}{AnsiColors.RESET} ({src_project.get_id()}) => {AnsiColors.BLUE}{dest_project_path}{AnsiColors.RESET}..." Loading Loading @@ -443,7 +443,7 @@ class Synchronizer: "visibility": dest_visibility, "description": src_project.description, # ??? "default_branch": src_default_branch, "namespace_id": dest_parent_group.get_id(), "namespace_id": dest_parent_group.get_id() if dest_parent_group else None, "issues_access_level": "disabled", "merge_requests_access_level": "disabled", } Loading Loading @@ -504,7 +504,7 @@ class Synchronizer: self.sync_releases(src_project, dest_project) # Synchronizes recursively a GitLab group def sync_group(self, src_group: Group, dest_parent_group: Group): def sync_group(self, src_group: Group, dest_parent_group: Group) -> None: dest_group_full_path = self.to_dest_path(src_group.full_path) print( f"🏢 Group {AnsiColors.BLUE}{src_group.full_path}{AnsiColors.RESET} ({src_group.get_id()}) => {AnsiColors.BLUE}{dest_group_full_path}{AnsiColors.RESET}..." Loading Loading @@ -696,7 +696,7 @@ def to_url(api_url: str) -> str: return api_url[0:-7] if api_url.endswith("/api/v4") else api_url def run(): def run() -> None: # define command parser parser = argparse.ArgumentParser( prog="gitlab-cp", Loading