Commit 75109f38 authored by Adrian DC's avatar Adrian DC
Browse files

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

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 462041db
Loading
Loading
Loading
Loading
Loading
+4 −1
Changes for README.md: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ 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]] [--]
                                [--protect-branches] [--protect-tags [LEVEL]] [--erase-jobs-artifacts] [--]
                                [url_path]

gitlab-projects-settings: Configure GitLab groups and projects settings automatically
@@ -104,6 +104,9 @@ 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] (default: no-one)

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

positional arguments:
  --                                # Positional arguments separator (recommended)
  url_path                          # GitLab group or project path URL
+8 −0
Changes for src/cli/entrypoint.py: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -537,6 +537,14 @@ class Entrypoint:
                      f'{Colors.RESET}')
                Platform.flush()

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

        # Dump group object
        if options.dump:
            print(' ')
+9 −0
Changes for src/cli/main.py: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -241,6 +241,15 @@ def main() -> None:
        ' (default: %(const)s)',
    )

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

    # Arguments positional definitions
    group = parser.add_argument_group('positional arguments')
    group.add_argument(
+10 −0
Changes for src/features/gitlab.py: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -114,6 +114,16 @@ class GitLabFeature:
        # Delay for deletion
        sleep(3)

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

        # Erase project jobs artifacts
        project = self.project(criteria)
        if not self.__dry_run:
            for job in project.jobs.list():
                if job.artifacts_expire_at is not None:
                    job.delete_artifacts()

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