def run(self) -> HandlerResults: logger.debug(f"Received testing-farm result:\n{self.event.result}") logger.debug( f"Received testing-farm test results:\n{self.event.tests}") if self.event.result == TestingFarmResult.passed: status = CommitStatus.success passed = True else: status = CommitStatus.failure passed = False if (len(self.event.tests) == 1 and self.event.tests[0].name == "/install/copr-build"): logger.debug("No-fmf scenario discovered.") short_msg = "Installation passed" if passed else "Installation failed" else: short_msg = self.event.message status_reporter = StatusReporter(self.project, self.event.commit_sha) status_reporter.report( state=status, description=short_msg, url=self.event.log_url, check_names=TestingFarmJobHelper.get_test_check( self.event.copr_chroot), ) return HandlerResults(success=True, details={})
def test_report_status_by_comment( project, commit_sha, pr_id, state, check_names, url, result, ): reporter = StatusReporter(project, commit_sha, pr_id) comment_body = "\n".join(( "| Job | Result |", "| ------------- | ------------ |", f"| [{check_names}]({url}) | {result} |", )) if pr_id: project.should_receive("get_pr").with_args(pr_id=pr_id).and_return( flexmock().should_receive("comment").with_args( body=comment_body).mock()).once() else: project.should_receive("commit_comment").with_args( commit=commit_sha, body=comment_body, ).once() reporter.report_status_by_comment(state, url, check_names)
def test_set_status( project, commit_sha, pr_id, has_pr_id, pr_object, state, description, check_name, url, needs_pr_flags, uid, ): reporter = StatusReporter(project, commit_sha, pr_id) project.should_receive("set_commit_status").with_args( commit_sha, state, url, description, check_name, trim=True ).once() if has_pr_id: project.should_receive("get_pr").with_args(pr_id).once().and_return(pr_object) if needs_pr_flags: pr_object.should_receive("set_flag").with_args( check_name, description, url, state, uid ) reporter.set_status(state, description, check_name, url)
def test_commit_comment_instead_of_status( project, commit_sha, pr_id, has_pr_id, pr_object, state, description, check_name, url, exception_mock, ): reporter = StatusReporter(project, commit_sha, pr_id) exception, exception_args, exception_kwargs = exception_mock project.should_receive("set_commit_status").with_args( commit_sha, state, url, description, check_name, trim=True).and_raise(exception, *exception_args, **exception_kwargs).once() project.should_receive("commit_comment").with_args( commit=commit_sha, body="\n".join([ f"- name: {check_name}", f"- state: {state.name}", f"- url: {url if url else 'not provided'}", ]) + f"\n\n{description}", ) if has_pr_id: project.should_receive("get_pr").with_args(pr_id).once().and_return( pr_object) reporter.set_status(state, description, check_name, url)
def test_set_status_gitlab( commit_sha, pr_id, pr_object, state, description, check_name, url, ): project = GitlabProject(None, None, None) reporter = StatusReporter(project, commit_sha, pr_id) act_upon = flexmock( pr_object.source_project) if pr_id else flexmock(GitlabProject) act_upon.should_receive("set_commit_status").with_args(commit_sha, state, url, description, check_name, trim=True).once() if pr_id is not None: flexmock(GitlabProject).should_receive("get_pr").with_args( pr_id).and_return(pr_object) reporter.set_status(state, description, check_name, url)
def status_reporter(self) -> StatusReporter: if not self._status_reporter: self._status_reporter = StatusReporter( project=self.project, commit_sha=self.metadata.commit_sha, pr_id=self.metadata.pr_id, ) return self._status_reporter
def status_reporter(self) -> StatusReporter: if not self._status_reporter: self._status_reporter = StatusReporter( project=self.base_project if isinstance(self.project, GitlabProject) and self.is_reporting_allowed else self.project, commit_sha=self.metadata.commit_sha, pr_id=self.metadata.pr_id, ) return self._status_reporter
def run(self) -> TaskResults: logger.debug(f"Testing farm {self.pipeline_id} result:\n{self.result}") logger.debug(f"Testing farm test results:\n{self.tests}") test_run_model = TFTTestRunModel.get_by_pipeline_id( pipeline_id=self.pipeline_id) if not test_run_model: logger.warning( f"Unknown pipeline_id received from the testing-farm: " f"{self.pipeline_id}") if test_run_model: test_run_model.set_status(self.result) if self.result == TestingFarmResult.running: status = CommitStatus.pending if isinstance(self.project.service, GitlabService): # only Gitlab has 'running' state status = CommitStatus.running summary = self.summary or "Tests are running ..." elif self.result == TestingFarmResult.passed: status = CommitStatus.success summary = self.summary or "Tests passed ..." elif self.result == TestingFarmResult.error: status = CommitStatus.error if isinstance(self.project.service, GitlabService): # Gitlab has no 'error' state status = CommitStatus.failure summary = self.summary or "Error ..." else: status = CommitStatus.failure summary = self.summary or "Tests failed ..." if len(self.tests ) > 0 and self.tests[0].name == "/packit/install-and-verify": logger.debug("No-fmf scenario discovered.") summary = ("Installation passed" if status == CommitStatus.success else "Installation failed") if test_run_model: test_run_model.set_web_url(self.log_url) status_reporter = StatusReporter(project=self.project, commit_sha=self.data.commit_sha, pr_id=self.data.pr_id) status_reporter.report( state=status, description=summary, url=self.log_url, check_names=TestingFarmJobHelper.get_test_check(self.copr_chroot), ) return TaskResults(success=True, details={})
def run(self) -> TaskResults: logger.debug(f"Received testing-farm result:\n{self.result}") logger.debug(f"Received testing-farm test results:\n{self.tests}") test_run_model = TFTTestRunModel.get_by_pipeline_id( pipeline_id=self.pipeline_id ) if not test_run_model: logger.warning( f"Unknown pipeline_id received from the testing-farm: " f"{self.pipeline_id}" ) if test_run_model: test_run_model.set_status(self.result) if self.result == TestingFarmResult.passed: status = CommitStatus.success passed = True elif self.result == TestingFarmResult.error: status = CommitStatus.error passed = False else: status = CommitStatus.failure passed = False github_status_url = self.log_url if len(self.tests) == 1 and self.tests[0].name == "/install/copr-build": logger.debug("No-fmf scenario discovered.") short_msg = "Installation passed" if passed else "Installation failed" elif self.message.startswith( "Command '['git', 'clone'" ) and self.message.endswith("failed with exit code 128"): short_msg = "Problem with Testing-Farm cluster" github_status_url = "https://pagure.io/centos-infra/issue/85" else: short_msg = self.message if test_run_model: test_run_model.set_web_url(self.log_url) status_reporter = StatusReporter( project=self.project, commit_sha=self.data.commit_sha, pr_id=self.data.pr_id ) status_reporter.report( state=status, description=short_msg, url=github_status_url, check_names=TestingFarmJobHelper.get_test_check(self.copr_chroot), ) return TaskResults(success=True, details={})
def test_report_status_by_comment( project, commit_sha, pr_id, pr_object, state, description, check_names, url, ): reporter = StatusReporter(project, commit_sha, pr_id) project.should_receive("pr_comment").with_args( pr_id, f"| [{check_names}]({url}) | SUCCESS |" ).once() reporter.report_status_by_comment(state, url, check_names)
def run(self) -> HandlerResults: logger.debug(f"Received testing-farm result:\n{self.event.result}") logger.debug( f"Received testing-farm test results:\n{self.event.tests}") test_run_model = TFTTestRunModel.get_by_pipeline_id( pipeline_id=self.event.pipeline_id) if not test_run_model: logger.warning( f"Unknown pipeline_id received from the testing-farm: " f"{self.event.pipeline_id}") if test_run_model: test_run_model.set_status(self.event.result) if self.event.result == TestingFarmResult.passed: status = CommitStatus.success passed = True else: status = CommitStatus.failure passed = False if (len(self.event.tests) == 1 and self.event.tests[0].name == "/install/copr-build"): logger.debug("No-fmf scenario discovered.") short_msg = "Installation passed" if passed else "Installation failed" else: short_msg = self.event.message if test_run_model: test_run_model.set_web_url(self.event.log_url) status_reporter = StatusReporter(self.event.project, self.event.commit_sha) status_reporter.report( state=status, description=short_msg, url=self.event.log_url, check_names=TestingFarmJobHelper.get_test_check( self.event.copr_chroot), ) return HandlerResults(success=True, details={})
def status_reporter(self) -> StatusReporter: if not self._status_reporter: self._status_reporter = StatusReporter( self.project, self.event.commit_sha, self.event.pr_id ) return self._status_reporter