Commit 1aa72a4d authored by Adrian DC's avatar Adrian DC
Browse files

feat(cli)!: refactor CLI into simpler GitLab URL bound parameters

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 4a2f9546
Loading
Loading
Loading
Loading
Loading
+5 −6
Changes for README.md: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -31,13 +31,13 @@ The following step is required before using the tool:
gitlab-projects-settings

# Protect all projects' tags under a group
gitlab-projects-settings --protect-tags -- 'https://gitlab.com' 'group'
gitlab-projects-settings --protect-tags -- 'https://gitlab.com/group'

# Update all avatars and descriptions under a group
gitlab-projects-settings --set-avatar ./avatar.png --update-description 'https://gitlab.com' 'group'
gitlab-projects-settings --set-avatar ./avatar.png --update-description 'https://gitlab.com/group'

# Automatically detect and reset features of projects based on usage
gitlab-projects-settings --reset-features 'https://gitlab.com' 'group/project'
gitlab-projects-settings --reset-features 'https://gitlab.com/group/project'
```

<!-- prettier-ignore-end -->
@@ -57,7 +57,7 @@ usage: gitlab-projects-settings [-h] [--version] [--update-check] [--settings] [
                                [--set-avatar FILE] [--set-description TEXT] [--update-description]
                                [--run-housekeeping] [--archive-project | --unarchive-project] [--delete-group]
                                [--delete-project] [--protect-branches] [--protect-tags [LEVEL]] [--]
                                [gitlab] [path]
                                [url_path]

gitlab-projects-settings: Configure GitLab groups and projects settings automatically

@@ -103,8 +103,7 @@ repository settings arguments:

positional arguments:
  --                                # Positional arguments separator (recommended)
  gitlab                            # GitLab URL (default: https://gitlab.com)
  path                              # GitLab group, user namespace or project path
  url_path                          # GitLab group or project path URL
```

<!-- readme-help-stop -->
+13 −7
Changes for src/cli/entrypoint.py: 13 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
from argparse import Namespace
from enum import Enum
from typing import Optional
import urllib.parse

# Modules libraries
from gitlab.exceptions import GitlabGetError
@@ -27,7 +28,7 @@ class Entrypoint:
    # Enumerations
    Result = Enum('Result', ['SUCCESS', 'FINALIZE', 'ERROR', 'CRITICAL'])

    # CLI, pylint: disable=too-many-branches
    # CLI, pylint: disable=too-many-branches,too-many-statements
    @staticmethod
    def cli(options: Namespace) -> Result:

@@ -40,9 +41,14 @@ class Entrypoint:
        # Header
        print(' ')

        # Parse URL variables
        gitlab_splits: urllib.parse.SplitResult = urllib.parse.urlsplit(options.url_path)
        gitlab_url: str = f'{gitlab_splits.scheme}://{gitlab_splits.netloc}'
        gitlab_path: str = gitlab_splits.path.lstrip('/')

        # GitLab client
        gitlab = GitLabFeature(
            options.gitlab,
            gitlab_url,
            options.token,
            options.dry_run,
        )
@@ -53,7 +59,7 @@ class Entrypoint:

        # GitLab path
        try:
            group = gitlab.group(options.path)
            group = gitlab.group(gitlab_path)
            print(f'{Colors.BOLD} - GitLab group: '
                  f'{Colors.GREEN}{group.full_path}'
                  f'{Colors.CYAN} ({group.description})'
@@ -62,10 +68,10 @@ class Entrypoint:
            Platform.flush()
        except GitlabGetError as exception:
            try:
                if '/' in options.path:
                if '/' in gitlab_path:
                    raise TypeError from exception
                user = gitlab.user(options.path)
                namespace = gitlab.namespace(options.path)
                user = gitlab.user(gitlab_path)
                namespace = gitlab.namespace(gitlab_path)
                print(f'{Colors.BOLD} - GitLab user namespace: '
                      f'{Colors.GREEN}{namespace.full_path}'
                      f'{Colors.CYAN} ({namespace.name})'
@@ -73,7 +79,7 @@ class Entrypoint:
                print(' ')
                Platform.flush()
            except (GitlabGetError, TypeError):
                project = gitlab.project(options.path)
                project = gitlab.project(gitlab_path)
                print(f'{Colors.BOLD} - GitLab project: '
                      f'{Colors.GREEN}{project.path_with_namespace}'
                      f'{Colors.CYAN} ({project.description})'
+3 −10
Changes for src/cli/main.py: 3 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -238,17 +238,10 @@ def main() -> None:
        help='Positional arguments separator (recommended)',
    )
    group.add_argument(
        dest='gitlab',
        dest='url_path',
        action='store',
        nargs='?',
        default='https://gitlab.com',
        help='GitLab URL (default: %(default)s)',
    )
    group.add_argument(
        dest='path',
        action='store',
        nargs='?',
        help='GitLab group, user namespace or project path',
        help='GitLab group or project path URL',
    )

    # Arguments parser
@@ -297,7 +290,7 @@ def main() -> None:
        sys_exit(0)

    # Arguments validation
    if not options.token or not options.gitlab or not options.path:
    if not options.token or not options.url_path:
        result = Entrypoint.Result.CRITICAL

    # Header