Verified Commit d912e44e authored by Adrian DC's avatar Adrian DC
Browse files

feat(entrypoint): implement subgroups and projects progress indexes

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 618e131a
Loading
Loading
Loading
Loading
Loading
+46 −8
Changes for src/cli/entrypoint.py: 46 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ class Entrypoint:

        # Variables
        group: Optional[GitLabGroup] = None
        progress_count: int
        progress_index: int
        project: Optional[GitLabProject] = None
        result: Entrypoint.Result
        user: Optional[GitLabUser] = None
@@ -164,7 +166,7 @@ class Entrypoint:

            # Iterate through subgroups
            if not options.exclude_subgroups:
                for group_subgroup in sorted(
                group_subgroups = sorted(
                    group.descendant_groups.list(
                        get_all=True,
                        include_subgroups=True,
@@ -172,12 +174,18 @@ class Entrypoint:
                        sort='asc',
                    ),
                    key=lambda item: item.full_path,
                ):
                )
                progress_count = len(group_subgroups)
                progress_index = 0
                for group_subgroup in group_subgroups:
                    progress_index += 1
                    result = Entrypoint.group(
                        options,
                        gitlab,
                        group_subgroup.full_path,
                        True,
                        progress_index=progress_index,
                        progress_count=progress_count,
                    )
                    if result in [
                            Entrypoint.Result.FINALIZE,
@@ -187,7 +195,7 @@ class Entrypoint:

            # Iterate through projects
            if not options.exclude_projects:
                for group_project in sorted(
                projects = sorted(
                    group.projects.list(
                        get_all=True,
                        with_shared=False,
@@ -196,11 +204,17 @@ class Entrypoint:
                        sort='asc',
                    ),
                    key=lambda item: item.path_with_namespace,
                ):
                )
                progress_count = len(projects)
                progress_index = 0
                for group_project in projects:
                    progress_index += 1
                    result = Entrypoint.project(
                        options,
                        gitlab,
                        group_project.path_with_namespace,
                        progress_index=progress_index,
                        progress_count=progress_count,
                    )
                    if result in [
                            Entrypoint.Result.FINALIZE,
@@ -213,18 +227,24 @@ class Entrypoint:

            # Iterate through projects
            if not options.exclude_projects:
                for user_project in sorted(
                user_projects = sorted(
                    user.projects.list(
                        get_all=True,
                        order_by='path',
                        sort='asc',
                    ),
                    key=lambda item: item.path_with_namespace,
                ):
                )
                progress_count = len(user_projects)
                progress_index = 0
                for user_project in user_projects:
                    progress_index += 1
                    result = Entrypoint.project(
                        options,
                        gitlab,
                        user_project.path_with_namespace,
                        progress_index=progress_index,
                        progress_count=progress_count,
                    )
                    if result in [
                            Entrypoint.Result.FINALIZE,
@@ -272,13 +292,15 @@ class Entrypoint:
        # Result
        return answer

    # Group, pylint: disable=too-many-locals
    # Group, pylint: disable=too-many-arguments,too-many-locals,too-many-positional-arguments
    @staticmethod
    def group(
        options: Namespace,
        gitlab: GitLabFeature,
        criteria: str,
        subgroup: bool = False,
        progress_index: int = 1,
        progress_count: int = 1,
    ) -> Result:

        # Variables
@@ -301,6 +323,16 @@ class Entrypoint:

        # Show group details
        group_type = 'subgroup' if subgroup else 'group'
        if subgroup:
            print(f'{Colors.BOLD} - GitLab {group_type} ('
                  f'{Colors.GREEN}{progress_index}'
                  f'{Colors.RESET}/'
                  f'{Colors.CYAN}{progress_count}'
                  f'{Colors.BOLD}) : '
                  f'{Colors.YELLOW_LIGHT}{group.full_path}'
                  f'{Colors.CYAN} # {group.description if group.description else "/"}'
                  f'{Colors.RESET}')
        else:
            print(f'{Colors.BOLD} - GitLab {group_type}: '
                  f'{Colors.YELLOW_LIGHT}{group.full_path}'
                  f'{Colors.CYAN} # {group.description if group.description else "/"}'
@@ -464,6 +496,8 @@ class Entrypoint:
        options: Namespace,
        gitlab: GitLabFeature,
        criteria: str,
        progress_index: int = 1,
        progress_count: int = 1,
    ) -> Result:

        # Variables
@@ -473,7 +507,11 @@ class Entrypoint:
        project = gitlab.project(criteria)

        # Show project details
        print(f'{Colors.BOLD} - GitLab project: '
        print(f'{Colors.BOLD} - GitLab project ('
              f'{Colors.GREEN}{progress_index}'
              f'{Colors.RESET}/'
              f'{Colors.CYAN}{progress_count}'
              f'{Colors.BOLD}) : '
              f'{Colors.YELLOW_LIGHT}{project.path_with_namespace}'
              f'{Colors.CYAN} # {project.description if project.description else "/"}'
              f'{Colors.RESET}')