Coverage for sel_tools/code_evaluation/jobs/gitlab.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-04 21:22 +0000

1"""Gitlab evaluation jobs.""" 

2 

3from pathlib import Path 

4 

5from sel_tools.code_evaluation.jobs.common import EvaluationJob 

6from sel_tools.config import GIT_MAIN_BRANCH 

7from sel_tools.utils.repo import GitlabProject 

8 

9 

10class CIStatusTestJob(EvaluationJob): 

11 """Job for checking the CI status.""" 

12 

13 name = "CI Status Check" 

14 

15 def __init__( 

16 self, 

17 gitlab_projects: list[GitlabProject], 

18 branch: str = GIT_MAIN_BRANCH, 

19 weight: int = 1, 

20 ) -> None: 

21 super().__init__(weight) 

22 self.__gitlab_projects = {project.local_path.stem: project.gitlab_project for project in gitlab_projects} 

23 self.__branch = branch 

24 

25 def _run(self, repo_path: Path) -> int: 

26 project = self.__gitlab_projects[repo_path.stem] 

27 pipelines = project.pipelines.list(ref=self.__branch) 

28 if pipelines: 

29 return int(pipelines[0].status == "success") 

30 

31 self._comment = "No pipelines found" 

32 return 0