Commit 24b82bcd authored by Adrian DC's avatar Adrian DC
Browse files

feat(cli, gitlab): implement '--erase-jobs-contents' to erase jobs contents

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 75109f38
Loading
Loading
Loading
Loading
Loading
+3 −1
Changes for README.md: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -57,7 +57,8 @@ usage: gitlab-projects-settings [-h] [--version] [--update-check] [--settings] [
                                [--set-avatar FILE] [--set-description TEXT] [--update-description]
                                [--run-housekeeping] [--prune-unreachable-objects]
                                [--archive-project | --unarchive-project] [--delete-group] [--delete-project]
                                [--protect-branches] [--protect-tags [LEVEL]] [--erase-jobs-artifacts] [--]
                                [--protect-branches] [--protect-tags [LEVEL]]
                                [--erase-jobs-artifacts | --erase-jobs-contents] [--]
                                [url_path]

gitlab-projects-settings: Configure GitLab groups and projects settings automatically
@@ -106,6 +107,7 @@ repository settings arguments:

ci/cd settings arguments:
  --erase-jobs-artifacts            # Erase all CI/CD jobs artifacts
  --erase-jobs-contents             # Erase all CI/CD jobs artifacts and traces

positional arguments:
  --                                # Positional arguments separator (recommended)
+9 −1
Changes for src/cli/entrypoint.py: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -537,8 +537,16 @@ class Entrypoint:
                      f'{Colors.RESET}')
                Platform.flush()

        # Erase project jobs artifacts and traces
        if options.erase_jobs_contents:
            gitlab.project_erase_jobs_contents(criteria)
            print(f'{Colors.BOLD}   - Erased CI/CD jobs artifacts and traces: '
                  f'{Colors.GREEN}Success'
                  f'{Colors.RESET}')
            Platform.flush()

        # Erase project jobs artifacts
        if options.erase_jobs_artifacts:
        elif options.erase_jobs_artifacts:
            gitlab.project_erase_jobs_artifacts(criteria)
            print(f'{Colors.BOLD}   - Erased CI/CD jobs artifacts: '
                  f'{Colors.GREEN}Success'
+8 −1
Changes for src/cli/main.py: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -243,12 +243,19 @@ def main() -> None:

    # Arguments CI/CD settings definitions
    group = parser.add_argument_group('ci/cd settings arguments')
    group.add_argument(
    subgroup = group.add_mutually_exclusive_group()
    subgroup.add_argument(
        '--erase-jobs-artifacts',
        dest='erase_jobs_artifacts',
        action='store_true',
        help='Erase all CI/CD jobs artifacts',
    )
    subgroup.add_argument(
        '--erase-jobs-contents',
        dest='erase_jobs_contents',
        action='store_true',
        help='Erase all CI/CD jobs artifacts and traces',
    )

    # Arguments positional definitions
    group = parser.add_argument_group('positional arguments')
+19 −1
Changes for src/features/gitlab.py: 19 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -6,7 +6,12 @@ from typing import cast, List

# Modules libraries
from gitlab import Gitlab
from gitlab.exceptions import GitlabDeleteError, GitlabGetError, GitlabListError
from gitlab.exceptions import (
    GitlabDeleteError,
    GitlabGetError,
    GitlabJobEraseError,
    GitlabListError,
)
from gitlab.v4.objects import Group, Namespace, Project, User

# Components
@@ -124,6 +129,19 @@ class GitLabFeature:
                if job.artifacts_expire_at is not None:
                    job.delete_artifacts()

    # Project erase jobs artifacts and traces
    def project_erase_jobs_contents(self, criteria: str) -> None:

        # Erase project jobs artifacts and traces
        project = self.project(criteria)
        if not self.__dry_run:
            for job in project.jobs.list():
                if job.artifacts_expire_at is not None:
                    try:
                        job.erase()
                    except GitlabJobEraseError:
                        pass

    # Project protect branches
    def project_protect_branches(self, criteria: str) -> List[str]: