Merge "Remove pipeline argument from various report fncts" into feature/zuulv3

This commit is contained in:
Jenkins 2017-06-07 12:37:54 +00:00 committed by Gerrit Code Review
commit 4551cb744d
6 changed files with 41 additions and 42 deletions

View File

@ -25,7 +25,7 @@ class GerritReporter(BaseReporter):
name = 'gerrit' name = 'gerrit'
log = logging.getLogger("zuul.GerritReporter") log = logging.getLogger("zuul.GerritReporter")
def report(self, pipeline, item): def report(self, item):
"""Send a message to gerrit.""" """Send a message to gerrit."""
# If the source is no GerritSource we cannot report anything here. # If the source is no GerritSource we cannot report anything here.
@ -38,7 +38,7 @@ class GerritReporter(BaseReporter):
self.connection.canonical_hostname: self.connection.canonical_hostname:
return return
message = self._formatItemReport(pipeline, item) message = self._formatItemReport(item)
self.log.debug("Report change %s, params %s, message: %s" % self.log.debug("Report change %s, params %s, message: %s" %
(item.change, self.config, message)) (item.change, self.config, message))

View File

@ -39,25 +39,25 @@ class GithubReporter(BaseReporter):
if not isinstance(self._unlabels, list): if not isinstance(self._unlabels, list):
self._unlabels = [self._unlabels] self._unlabels = [self._unlabels]
def report(self, pipeline, item): def report(self, item):
"""Comment on PR and set commit status.""" """Comment on PR and set commit status."""
if self._create_comment: if self._create_comment:
self.addPullComment(pipeline, item) self.addPullComment(item)
if (self._commit_status is not None and if (self._commit_status is not None and
hasattr(item.change, 'patchset') and hasattr(item.change, 'patchset') and
item.change.patchset is not None): item.change.patchset is not None):
self.setPullStatus(pipeline, item) self.setPullStatus(item)
if (self._merge and if (self._merge and
hasattr(item.change, 'number')): hasattr(item.change, 'number')):
self.mergePull(item) self.mergePull(item)
if not item.change.is_merged: if not item.change.is_merged:
msg = self._formatItemReportMergeFailure(pipeline, item) msg = self._formatItemReportMergeFailure(item)
self.addPullComment(pipeline, item, msg) self.addPullComment(item, msg)
if self._labels or self._unlabels: if self._labels or self._unlabels:
self.setLabels(item) self.setLabels(item)
def addPullComment(self, pipeline, item, comment=None): def addPullComment(self, item, comment=None):
message = comment or self._formatItemReport(pipeline, item) message = comment or self._formatItemReport(item)
project = item.change.project.name project = item.change.project.name
pr_number = item.change.number pr_number = item.change.number
self.log.debug( self.log.debug(
@ -65,10 +65,11 @@ class GithubReporter(BaseReporter):
(item.change, self.config, message)) (item.change, self.config, message))
self.connection.commentPull(project, pr_number, message) self.connection.commentPull(project, pr_number, message)
def setPullStatus(self, pipeline, item): def setPullStatus(self, item):
project = item.change.project.name project = item.change.project.name
sha = item.change.patchset 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 state = self._commit_status
url_pattern = self.config.get('status-url') url_pattern = self.config.get('status-url')
@ -79,8 +80,8 @@ class GithubReporter(BaseReporter):
url = item.formatUrlPattern(url_pattern) if url_pattern else '' url = item.formatUrlPattern(url_pattern) if url_pattern else ''
description = '' description = ''
if pipeline.description: if item.pipeline.description:
description = pipeline.description description = item.pipeline.description
self.log.debug( self.log.debug(
'Reporting change %s, params %s, status:\n' 'Reporting change %s, params %s, status:\n'

View File

@ -24,9 +24,9 @@ class SMTPReporter(BaseReporter):
name = 'smtp' name = 'smtp'
log = logging.getLogger("zuul.SMTPReporter") log = logging.getLogger("zuul.SMTPReporter")
def report(self, pipeline, item): def report(self, item):
"""Send the compiled report message via smtp.""" """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" % self.log.debug("Report change %s, params %s, message: %s" %
(item.change, self.config, message)) (item.change, self.config, message))

View File

@ -31,7 +31,7 @@ class SQLReporter(BaseReporter):
# TODO(jeblair): document this is stored as NULL if unspecified # TODO(jeblair): document this is stored as NULL if unspecified
self.result_score = config.get('score', None) self.result_score = config.get('score', None)
def report(self, pipeline, item): def report(self, item):
"""Create an entry into a database.""" """Create an entry into a database."""
if not self.connection.tables_established: if not self.connection.tables_established:
@ -51,7 +51,7 @@ class SQLReporter(BaseReporter):
ref=refspec, ref=refspec,
score=self.result_score, score=self.result_score,
message=self._formatItemReport( message=self._formatItemReport(
pipeline, item, with_jobs=False), item, with_jobs=False),
) )
buildset_ins_result = conn.execute(buildset_ins) buildset_ins_result = conn.execute(buildset_ins)
build_inserts = [] build_inserts = []

View File

@ -165,7 +165,7 @@ class PipelineManager(object):
report_errors = [] report_errors = []
if len(action_reporters) > 0: if len(action_reporters) > 0:
for reporter in action_reporters: for reporter in action_reporters:
ret = reporter.report(self.pipeline, item) ret = reporter.report(item)
if ret: if ret:
report_errors.append(ret) report_errors.append(ret)
if len(report_errors) == 0: if len(report_errors) == 0:

View File

@ -37,7 +37,7 @@ class BaseReporter(object):
self._action = action self._action = action
@abc.abstractmethod @abc.abstractmethod
def report(self, pipeline, item): def report(self, item):
"""Send the compiled report message.""" """Send the compiled report message."""
def getSubmitAllowNeeds(self): def getSubmitAllowNeeds(self):
@ -61,57 +61,55 @@ class BaseReporter(object):
} }
return format_methods[self._action] return format_methods[self._action]
# TODOv3(jeblair): Consider removing pipeline argument in favor of def _formatItemReport(self, item, with_jobs=True):
# item.pipeline
def _formatItemReport(self, pipeline, item, with_jobs=True):
"""Format a report from the given items. Usually to provide results to """Format a report from the given items. Usually to provide results to
a reporter taking free-form text.""" a reporter taking free-form text."""
ret = self._getFormatter()(pipeline, item, with_jobs) ret = self._getFormatter()(item, with_jobs)
if pipeline.footer_message: if item.pipeline.footer_message:
ret += '\n' + pipeline.footer_message ret += '\n' + item.pipeline.footer_message
return ret return ret
def _formatItemReportStart(self, pipeline, item, with_jobs=True): def _formatItemReportStart(self, item, with_jobs=True):
status_url = '' status_url = ''
if self.connection.sched.config.has_option('zuul', 'status_url'): if self.connection.sched.config.has_option('zuul', 'status_url'):
status_url = self.connection.sched.config.get('zuul', status_url = self.connection.sched.config.get('zuul',
'status_url') 'status_url')
return pipeline.start_message.format(pipeline=pipeline, return item.pipeline.start_message.format(pipeline=item.pipeline,
status_url=status_url) status_url=status_url)
def _formatItemReportSuccess(self, pipeline, item, with_jobs=True): def _formatItemReportSuccess(self, item, with_jobs=True):
msg = pipeline.success_message msg = item.pipeline.success_message
if with_jobs: if with_jobs:
msg += '\n\n' + self._formatItemReportJobs(pipeline, item) msg += '\n\n' + self._formatItemReportJobs(item)
return msg return msg
def _formatItemReportFailure(self, pipeline, item, with_jobs=True): def _formatItemReportFailure(self, item, with_jobs=True):
if item.dequeued_needing_change: if item.dequeued_needing_change:
msg = 'This change depends on a change that failed to merge.\n' msg = 'This change depends on a change that failed to merge.\n'
elif item.didMergerFail(): elif item.didMergerFail():
msg = pipeline.merge_failure_message msg = item.pipeline.merge_failure_message
elif item.getConfigError(): elif item.getConfigError():
msg = item.getConfigError() msg = item.getConfigError()
else: else:
msg = pipeline.failure_message msg = item.pipeline.failure_message
if with_jobs: if with_jobs:
msg += '\n\n' + self._formatItemReportJobs(pipeline, item) msg += '\n\n' + self._formatItemReportJobs(item)
return msg return msg
def _formatItemReportMergeFailure(self, pipeline, item, with_jobs=True): def _formatItemReportMergeFailure(self, item, with_jobs=True):
return pipeline.merge_failure_message 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': if item.current_build_set.result == 'SUCCESS':
return self._formatItemReportSuccess(pipeline, item) return self._formatItemReportSuccess(item)
elif item.current_build_set.result == 'FAILURE': elif item.current_build_set.result == 'FAILURE':
return self._formatItemReportFailure(pipeline, item) return self._formatItemReportFailure(item)
else: 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 # Return the list of jobs portion of the report
ret = '' ret = ''