Merge "Limit github reporters to event types" into feature/zuulv3

This commit is contained in:
Jenkins 2017-06-15 17:18:03 +00:00 committed by Gerrit Code Review
commit 40fe2ea50e
2 changed files with 26 additions and 21 deletions

View File

@ -31,10 +31,10 @@ trigger.
GitHub
------
Zuul reports back to GitHub pull requests via GitHub API.
On success and failure, it creates a comment containing the build results.
It also sets the status on start, success and failure. Status name and
description is taken from the pipeline.
Zuul reports back to GitHub via GitHub API. Available reports include a PR
comment containing the build results, a commit status on start, success and
failure, an issue label addition/removal on the PR, and a merge of the PR
itself. Status name, description, and context is taken from the pipeline.
A :ref:`connection` that uses the github driver must be supplied to the
reporter. It has the following options:
@ -51,22 +51,23 @@ reporter. It has the following options:
**comment**
Boolean value (``true`` or ``false``) that determines if the reporter should
add a comment to the pipeline status to the github pull request. Defaults
to ``true``.
to ``true``. Only used for Pull Request based events.
``comment: false``
**merge**
Boolean value (``true`` or ``false``) that determines if the reporter should
merge the pull reqeust. Defaults to ``false``.
merge the pull reqeust. Defaults to ``false``. Only used for Pull Request based
events.
``merge=true``
**label**
List of strings each representing an exact label name which should be added
to the pull request by reporter.
to the pull request by reporter. Only used for Pull Request based events.
``label: 'test successful'``
**unlabel**
List of strings each representing an exact label name which should be removed
from the pull request by reporter.
from the pull request by reporter. Only used for Pull Request based events.
``unlabel: 'test failed'``
SMTP

View File

@ -40,21 +40,25 @@ class GithubReporter(BaseReporter):
self._unlabels = [self._unlabels]
def report(self, item):
"""Comment on PR and set commit status."""
if self._create_comment:
self.addPullComment(item)
"""Report on an event."""
# order is important for github branch protection.
# A status should be set before a merge attempt
if (self._commit_status is not None and
hasattr(item.change, 'patchset') and
item.change.patchset is not None):
self.setPullStatus(item)
if (self._merge and
hasattr(item.change, 'number')):
self.mergePull(item)
if not item.change.is_merged:
msg = self._formatItemReportMergeFailure(item)
self.addPullComment(item, msg)
if self._labels or self._unlabels:
self.setLabels(item)
self.setCommitStatus(item)
# Comments, labels, and merges can only be performed on pull requests.
# If the change is not a pull request (e.g. a push) skip them.
if hasattr(item.change, 'number'):
if self._create_comment:
self.addPullComment(item)
if self._labels or self._unlabels:
self.setLabels(item)
if (self._merge):
self.mergePull(item)
if not item.change.is_merged:
msg = self._formatItemReportMergeFailure(item)
self.addPullComment(item, msg)
def addPullComment(self, item, comment=None):
message = comment or self._formatItemReport(item)
@ -65,7 +69,7 @@ class GithubReporter(BaseReporter):
(item.change, self.config, message))
self.connection.commentPull(project, pr_number, message)
def setPullStatus(self, item):
def setCommitStatus(self, item):
project = item.change.project.name
sha = item.change.patchset
context = '%s/%s' % (item.pipeline.layout.tenant.name,