def get_all_build_failed_targets(self) -> Optional[Set[str]]: # TODO: get rid of project.repo which is mandatory in `CoprBuildModel.get_all_by` # in this case relevant for us is only commit_sha if self.commit_sha is None or self.project.repo is None: return None return self._filter_failed_models_targets( models=CoprBuildModel.get_all_by(project_name=self.project.repo, commit_sha=self.commit_sha))
def test_copr_get_all_by_owner_project_commit_target(clean_before_and_after, multiple_copr_builds): builds_list = list( CoprBuildModel.get_all_by( owner=SampleValues.owner, project_name=SampleValues.project, target=SampleValues.target, commit_sha=SampleValues.ref, )) assert len(builds_list) == 2 # both should have the same project_name assert (builds_list[1].project_name == builds_list[0].project_name == SampleValues.project) # test without target and owner builds_list_without_target = list( CoprBuildModel.get_all_by( project_name=SampleValues.project, commit_sha=SampleValues.ref, )) assert len(builds_list_without_target) == 3 assert (builds_list_without_target[0].commit_sha == builds_list_without_target[1].commit_sha == builds_list_without_target[2].commit_sha == SampleValues.ref)
def get_latest_copr_build(self, target: str, commit_sha: str) -> Optional[CoprBuildModel]: """ Search a last build for the given target and commit SHA using Copr owner and project. """ copr_builds = CoprBuildModel.get_all_by( project_name=self.job_project, commit_sha=commit_sha, owner=self.job_owner, target=target, ) if not copr_builds: return None return list(copr_builds)[0]
def test_filter_failed_models_targets_copr(clean_before_and_after, multiple_copr_builds): builds_list = list( CoprBuildModel.get_all_by( project_name=SampleValues.project, commit_sha=SampleValues.ref, )) assert len(builds_list) == 3 # these targets should be different assert builds_list[0].target != builds_list[2].target # 2 builds with failed status and one with success builds_list[0].set_status(SampleValues.status_failed) builds_list[2].set_status(SampleValues.status_error) assert (len( AbstractForgeIndependentEvent._filter_failed_models_targets( models=builds_list)) == 2)