Commit 140ff3aa authored by Adrian DC's avatar Adrian DC
Browse files

feat(main, entrypoint): implement '--delete-sources' final actions

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 4af24bae
Loading
Loading
Loading
Loading
Loading
+4 −3
Changes for README.md: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -46,9 +46,9 @@ gitlab-projects-migrate 'https://old.gitlab.com' 'group/subgroup' 'https://new.g
<!-- readme-help-start -->

```yaml
usage: gitlab-projects-migrate [-h] [--version] [-I INPUT_TOKEN] [-O OUTPUT_TOKEN] [--dry-run] [--exclude-group]
                               [--exclude-subgroups] [--exclude-projects] [--keep-members] [--overwrite]
                               [--set-avatar FILE] [--update-description]
usage: gitlab-projects-migrate [-h] [--version] [-I INPUT_TOKEN] [-O OUTPUT_TOKEN] [--delete-sources] [--dry-run]
                               [--exclude-group] [--exclude-subgroups] [--exclude-projects] [--keep-members]
                               [--overwrite] [--set-avatar FILE] [--update-description]
                               [input_gitlab] [input_path] [output_gitlab] [output_group]

gitlab-projects-migrate: Migrate GitLab projects from a GitLab group to another GitLab's group
@@ -62,6 +62,7 @@ credentials arguments:
  -O OUTPUT_TOKEN       # Output GitLab API token (default: GITLAB_OUTPUT_TOKEN, GITLAB_TOKEN environments, or INPUT_TOKEN argument)

migration arguments:
  --delete-sources      # Delete sources after successful migration
  --dry-run             # Enable dry run mode to check without saving
  --exclude-group       # Exclude parent group migration
  --exclude-subgroups   # Exclude children subgroups migration
+31 −1
Changes for src/cli/entrypoint.py: 31 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ from ..prints.colors import Colors
from ..system.platform import Platform
from ..types.namespaces import Namespaces

# Entrypoint class, pylint: disable=too-few-public-methods
# Entrypoint class, pylint: disable=too-few-public-methods,too-many-statements
class Entrypoint:

    # CLI, pylint: disable=too-many-branches
@@ -95,6 +95,8 @@ class Entrypoint:

        # Handle single project
        if input_project:

            # Handle project
            Entrypoint.project(
                options,
                input_gitlab,
@@ -104,6 +106,20 @@ class Entrypoint:
                output_group.id,
            )

            # Delete input project
            if options.delete_sources:
                print(f'{Colors.BOLD} - GitLab input project: '
                      f'{Colors.GREEN}{input_project.path_with_namespace}'
                      f'{Colors.CYAN} ({Namespaces.text(input_project.description)})'
                      f'{Colors.RESET}')
                Platform.flush()
                input_gitlab.project_delete(input_project.id)
                print(f'{Colors.BOLD}   - Delete sources project: '
                      f'{Colors.GREEN}Success'
                      f'{Colors.RESET}')
                print(' ')
                Platform.flush()

        # Handle group recursively
        elif input_group:

@@ -165,6 +181,20 @@ class Entrypoint:
                    ):
                        return False

            # Delete input group
            if options.delete_sources:
                print(f'{Colors.BOLD} - GitLab input group: '
                      f'{Colors.GREEN}{input_group.full_path}'
                      f'{Colors.CYAN} ({Namespaces.text(input_group.description)})'
                      f'{Colors.RESET}')
                Platform.flush()
                input_gitlab.group_delete(input_group.id)
                print(f'{Colors.BOLD}   - Delete sources group: '
                      f'{Colors.GREEN}Success'
                      f'{Colors.RESET}')
                print(' ')
                Platform.flush()

        # Result
        return True

+6
Changes for src/cli/main.py: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -84,6 +84,12 @@ def main() -> None:

    # Arguments migration definitions
    group = parser.add_argument_group('migration arguments')
    group.add_argument(
        '--delete-sources',
        dest='delete_sources',
        action='store_true',
        help='Delete sources after successful migration',
    )
    group.add_argument(
        '--dry-run',
        dest='dry_run',
+9
Changes for src/features/gitlab.py: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -74,6 +74,15 @@ class GitLabFeature:
            })
            sleep(5)

    # Group delete
    def group_delete(self, criteria: str) -> None:

        # Delete group
        if not self.__dry_run:
            group = self.group(criteria)
            group.delete()
            sleep(10)

    # Group export
    def group_export(
        self,