Commit be6c2415 authored by Adrian DC's avatar Adrian DC
Browse files

feat(cli, gitlab): implement '--{archive,unarchive}-project'

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent cc44651d
Loading
Loading
Loading
Loading
+6 −2
Changes for README.md: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@ The following step is required before using the tool:
```yaml
usage: gitlab-projects-settings [-h] [--version] [-t TOKEN] [--dry-run] [--exclude-group] [--exclude-subgroups]
                                [--exclude-projects] [--reset-features] [--reset-members] [--set-avatar FILE]
                                [--set-description TEXT] [--update-description] [--protect-branches]
                                [--protect-tags LEVEL]
                                [--set-description TEXT] [--update-description]
                                [--archive-project | --unarchive-project] [--protect-branches] [--protect-tags LEVEL]
                                [gitlab] [path]

gitlab-projects-settings: Configure GitLab groups and projects settings automatically
@@ -56,6 +56,10 @@ general settings arguments:
  --set-description TEXT  # Set description of GitLab projects and groups
  --update-description    # Update description of GitLab projects and groups automatically

advanced settings arguments:
  --archive-project       # Archive project or projects in GitLab groups
  --unarchive-project     # Unarchive project or projects in GitLab groups

repository settings arguments:
  --protect-branches      # Protect branches with default master/main, develop and staging
  --protect-tags LEVEL    # Protect tags at level [no-one,admins,maintainers,developers]
+14 −0
Changes for src/cli/entrypoint.py: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -260,6 +260,20 @@ class Entrypoint:
                  f'{Colors.CYAN}{options.set_avatar}'
                  f'{Colors.RESET}')

        # Archive project
        if options.archive_project:
            gitlab.project_set_archive(criteria, True)
            print(f'{Colors.BOLD}   - Archive project: '
                  f'{Colors.GREEN}Success'
                  f'{Colors.RESET}')

        # Unarchive project
        elif options.unarchive_project:
            gitlab.project_set_archive(criteria, False)
            print(f'{Colors.BOLD}   - Unarchive project: '
                  f'{Colors.GREEN}Success'
                  f'{Colors.RESET}')

        # Protect project branches
        if options.protect_branches:
            branches = ', '.join(gitlab.project_protect_branches(criteria))
+19 −1
Changes for src/cli/main.py: 19 added lines, 1 removed line.
Original line number Diff line number Diff line
#!/usr/bin/env python3

# Standard libraries
from argparse import (_ArgumentGroup, ArgumentParser, Namespace, RawTextHelpFormatter)
from argparse import (_ArgumentGroup, _MutuallyExclusiveGroup, ArgumentParser, Namespace,
                      RawTextHelpFormatter)
from os import environ
from shutil import get_terminal_size
from sys import exit as sys_exit
@@ -19,6 +20,7 @@ def main() -> None:
    # Variables
    group: _ArgumentGroup
    result: bool = False
    subgroup: _MutuallyExclusiveGroup

    # Arguments creation
    parser: ArgumentParser = ArgumentParser(
@@ -122,6 +124,22 @@ def main() -> None:
        help='Update description of GitLab projects and groups automatically',
    )

    # Arguments advanced settings definitions
    group = parser.add_argument_group('advanced settings arguments')
    subgroup = group.add_mutually_exclusive_group()
    subgroup.add_argument(
        '--archive-project',
        dest='archive_project',
        action='store_true',
        help='Archive project or projects in GitLab groups',
    )
    subgroup.add_argument(
        '--unarchive-project',
        dest='unarchive_project',
        action='store_true',
        help='Unarchive project or projects in GitLab groups',
    )

    # Arguments repository settings definitions
    group = parser.add_argument_group('repository settings arguments')
    group.add_argument(
+13 −0
Changes for src/features/gitlab.py: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -290,6 +290,19 @@ class GitLabFeature:
            # Save project
            project.save()

    # Project set archive
    def project_set_archive(self, criteria: str, enabled: bool) -> None:

        # Archive project
        if not self.__dry_run and enabled:
            project = self.project(criteria)
            project.archive()

        # Unarchive project
        elif not self.__dry_run:
            project = self.project(criteria)
            project.unarchive()

    # Project set avatar
    def project_set_avatar(self, criteria: str, file: str) -> None: