Commit afb274c5 authored by Mathieu Coupé's avatar Mathieu Coupé
Browse files

Merge branch '3-pipeline-lasted-2-years' into 'main'

Resolve "Pipeline lasted 2 years..."

Closes #3

See merge request to-be-continuous/tools/gitlab-butler!26
parents 6499bb87 079f3657
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -9,7 +9,8 @@ import yaml
from gitlab import (
    Gitlab,
    GitlabDeleteError,
    GitlabGetError, GitlabHttpError,
    GitlabGetError,
    GitlabHttpError,
)
from gitlab.v4.objects import Group, Project, ProjectFile, ProjectPipeline

@@ -342,12 +343,12 @@ class Butler:
        kept_pipelines: dict[str, list[ProjectPipeline]] = {}

        # iterate over project pipelines (starting with oldest)
        for pipeline in project.pipelines.list(iterator=True, sort="asc"):
            # if the pipeline has been updated after the cutoff date, it is always kept
        for pipeline in project.pipelines.list(iterator=True, sort="asc", order_by="updated_at"):
            # if the pipeline has been updated after the cutoff date: keep and break loop
            if datetime.strptime(pipeline.updated_at, "%Y-%m-%dT%H:%M:%S.%fZ") >= updated_limit:
                if self.verbose and self.debug:
                    print(
                        f'Pipeline {pipeline.id} age is under limit ({datetime.strptime(pipeline.updated_at, "%Y-%m-%dT%H:%M:%S.%fZ")} >= {updated_limit}), skipping')
                        f'Pipeline {pipeline.id} age is under limit ({datetime.strptime(pipeline.created_at, "%Y-%m-%dT%H:%M:%S.%fZ")} >= {updated_limit}), stopping')
                break

            # check pipeline source status
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ def mock_empty_project(project_id, archived: bool = False):
    responses.add(responses.GET, f'http://gitlab.test/api/v4/projects/{project_id}/repository/files/.butlercfg.yml?ref=main', status=404)
    responses.add(responses.GET, f'http://gitlab.test/api/v4/projects/{project_id}/repository/branches?per_page=100', status=200, json=[])
    responses.add(responses.GET, f'http://gitlab.test/api/v4/projects/{project_id}/repository/tags?per_page=100', status=200, json=[])
    responses.add(responses.GET, f'http://gitlab.test/api/v4/projects/{project_id}/pipelines?sort=asc&per_page=100', status=200, json=[])
    responses.add(responses.GET, f'http://gitlab.test/api/v4/projects/{project_id}/pipelines?sort=asc&order_by=updated_at&per_page=100', status=200, json=[])


class TestGroups: