From 186f14a3e149bbfb915aaee96c86b2c3f14ac669 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Fri, 12 May 2017 11:29:16 -0700 Subject: [PATCH] Remove pipeline argument from various report fncts The pipeline can be obtained by way of the item which was also being passed in. Change-Id: Ibcafa7daef3567c840a23defcab6fd40a9c6b206 Signed-off-by: Jesse Keating --- zuul/driver/gerrit/gerritreporter.py | 4 +-- zuul/driver/github/githubreporter.py | 23 +++++++------- zuul/driver/smtp/smtpreporter.py | 4 +-- zuul/driver/sql/sqlreporter.py | 4 +-- zuul/manager/__init__.py | 2 +- zuul/reporter/__init__.py | 46 +++++++++++++--------------- 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/zuul/driver/gerrit/gerritreporter.py b/zuul/driver/gerrit/gerritreporter.py index f8e8b03afd..90c95e344a 100644 --- a/zuul/driver/gerrit/gerritreporter.py +++ b/zuul/driver/gerrit/gerritreporter.py @@ -25,7 +25,7 @@ class GerritReporter(BaseReporter): name = 'gerrit' log = logging.getLogger("zuul.GerritReporter") - def report(self, pipeline, item): + def report(self, item): """Send a message to gerrit.""" # If the source is no GerritSource we cannot report anything here. @@ -38,7 +38,7 @@ class GerritReporter(BaseReporter): self.connection.canonical_hostname: return - message = self._formatItemReport(pipeline, item) + message = self._formatItemReport(item) self.log.debug("Report change %s, params %s, message: %s" % (item.change, self.config, message)) diff --git a/zuul/driver/github/githubreporter.py b/zuul/driver/github/githubreporter.py index 68c6af0702..45b7d4bb70 100644 --- a/zuul/driver/github/githubreporter.py +++ b/zuul/driver/github/githubreporter.py @@ -39,25 +39,25 @@ class GithubReporter(BaseReporter): if not isinstance(self._unlabels, list): self._unlabels = [self._unlabels] - def report(self, pipeline, item): + def report(self, item): """Comment on PR and set commit status.""" if self._create_comment: - self.addPullComment(pipeline, item) + self.addPullComment(item) if (self._commit_status is not None and hasattr(item.change, 'patchset') and item.change.patchset is not None): - self.setPullStatus(pipeline, item) + self.setPullStatus(item) if (self._merge and hasattr(item.change, 'number')): self.mergePull(item) if not item.change.is_merged: - msg = self._formatItemReportMergeFailure(pipeline, item) - self.addPullComment(pipeline, item, msg) + msg = self._formatItemReportMergeFailure(item) + self.addPullComment(item, msg) if self._labels or self._unlabels: self.setLabels(item) - def addPullComment(self, pipeline, item, comment=None): - message = comment or self._formatItemReport(pipeline, item) + def addPullComment(self, item, comment=None): + message = comment or self._formatItemReport(item) project = item.change.project.name pr_number = item.change.number self.log.debug( @@ -65,10 +65,11 @@ class GithubReporter(BaseReporter): (item.change, self.config, message)) self.connection.commentPull(project, pr_number, message) - def setPullStatus(self, pipeline, item): + def setPullStatus(self, item): project = item.change.project.name sha = item.change.patchset - context = '%s/%s' % (pipeline.layout.tenant.name, pipeline.name) + context = '%s/%s' % (item.pipeline.layout.tenant.name, + item.pipeline.name) state = self._commit_status url = '' if self.connection.sched.config.has_option('zuul', 'status_url'): @@ -77,8 +78,8 @@ class GithubReporter(BaseReporter): item.change.number, item.change.patchset) description = '' - if pipeline.description: - description = pipeline.description + if item.pipeline.description: + description = item.pipeline.description self.log.debug( 'Reporting change %s, params %s, status:\n' diff --git a/zuul/driver/smtp/smtpreporter.py b/zuul/driver/smtp/smtpreporter.py index 35eb69fe87..1f232e9e5a 100644 --- a/zuul/driver/smtp/smtpreporter.py +++ b/zuul/driver/smtp/smtpreporter.py @@ -24,9 +24,9 @@ class SMTPReporter(BaseReporter): name = 'smtp' log = logging.getLogger("zuul.SMTPReporter") - def report(self, pipeline, item): + def report(self, item): """Send the compiled report message via smtp.""" - message = self._formatItemReport(pipeline, item) + message = self._formatItemReport(item) self.log.debug("Report change %s, params %s, message: %s" % (item.change, self.config, message)) diff --git a/zuul/driver/sql/sqlreporter.py b/zuul/driver/sql/sqlreporter.py index 46d538a587..13f62f4a96 100644 --- a/zuul/driver/sql/sqlreporter.py +++ b/zuul/driver/sql/sqlreporter.py @@ -31,7 +31,7 @@ class SQLReporter(BaseReporter): # TODO(jeblair): document this is stored as NULL if unspecified self.result_score = config.get('score', None) - def report(self, pipeline, item): + def report(self, item): """Create an entry into a database.""" if not self.connection.tables_established: @@ -48,7 +48,7 @@ class SQLReporter(BaseReporter): ref=item.change.refspec, score=self.result_score, message=self._formatItemReport( - pipeline, item, with_jobs=False), + item, with_jobs=False), ) buildset_ins_result = conn.execute(buildset_ins) build_inserts = [] diff --git a/zuul/manager/__init__.py b/zuul/manager/__init__.py index 76499448d1..6ea182bbc4 100644 --- a/zuul/manager/__init__.py +++ b/zuul/manager/__init__.py @@ -165,7 +165,7 @@ class PipelineManager(object): report_errors = [] if len(action_reporters) > 0: for reporter in action_reporters: - ret = reporter.report(self.pipeline, item) + ret = reporter.report(item) if ret: report_errors.append(ret) if len(report_errors) == 0: diff --git a/zuul/reporter/__init__.py b/zuul/reporter/__init__.py index 9c8e95381a..dc99c8bd25 100644 --- a/zuul/reporter/__init__.py +++ b/zuul/reporter/__init__.py @@ -37,7 +37,7 @@ class BaseReporter(object): self._action = action @abc.abstractmethod - def report(self, pipeline, item): + def report(self, item): """Send the compiled report message.""" def getSubmitAllowNeeds(self): @@ -61,57 +61,55 @@ class BaseReporter(object): } return format_methods[self._action] - # TODOv3(jeblair): Consider removing pipeline argument in favor of - # item.pipeline - def _formatItemReport(self, pipeline, item, with_jobs=True): + def _formatItemReport(self, item, with_jobs=True): """Format a report from the given items. Usually to provide results to a reporter taking free-form text.""" - ret = self._getFormatter()(pipeline, item, with_jobs) + ret = self._getFormatter()(item, with_jobs) - if pipeline.footer_message: - ret += '\n' + pipeline.footer_message + if item.pipeline.footer_message: + ret += '\n' + item.pipeline.footer_message return ret - def _formatItemReportStart(self, pipeline, item, with_jobs=True): + def _formatItemReportStart(self, item, with_jobs=True): status_url = '' if self.connection.sched.config.has_option('zuul', 'status_url'): status_url = self.connection.sched.config.get('zuul', 'status_url') - return pipeline.start_message.format(pipeline=pipeline, - status_url=status_url) + return item.pipeline.start_message.format(pipeline=item.pipeline, + status_url=status_url) - def _formatItemReportSuccess(self, pipeline, item, with_jobs=True): - msg = pipeline.success_message + def _formatItemReportSuccess(self, item, with_jobs=True): + msg = item.pipeline.success_message if with_jobs: - msg += '\n\n' + self._formatItemReportJobs(pipeline, item) + msg += '\n\n' + self._formatItemReportJobs(item) return msg - def _formatItemReportFailure(self, pipeline, item, with_jobs=True): + def _formatItemReportFailure(self, item, with_jobs=True): if item.dequeued_needing_change: msg = 'This change depends on a change that failed to merge.\n' elif item.didMergerFail(): - msg = pipeline.merge_failure_message + msg = item.pipeline.merge_failure_message elif item.getConfigError(): msg = item.getConfigError() else: - msg = pipeline.failure_message + msg = item.pipeline.failure_message if with_jobs: - msg += '\n\n' + self._formatItemReportJobs(pipeline, item) + msg += '\n\n' + self._formatItemReportJobs(item) return msg - def _formatItemReportMergeFailure(self, pipeline, item, with_jobs=True): - return pipeline.merge_failure_message + def _formatItemReportMergeFailure(self, item, with_jobs=True): + return item.pipeline.merge_failure_message - def _formatItemReportDisabled(self, pipeline, item, with_jobs=True): + def _formatItemReportDisabled(self, item, with_jobs=True): if item.current_build_set.result == 'SUCCESS': - return self._formatItemReportSuccess(pipeline, item) + return self._formatItemReportSuccess(item) elif item.current_build_set.result == 'FAILURE': - return self._formatItemReportFailure(pipeline, item) + return self._formatItemReportFailure(item) else: - return self._formatItemReport(pipeline, item) + return self._formatItemReport(item) - def _formatItemReportJobs(self, pipeline, item): + def _formatItemReportJobs(self, item): # Return the list of jobs portion of the report ret = ''