Merge "Limit github reporters to event types" into feature/zuulv3
diff --git a/doc/source/reporters.rst b/doc/source/reporters.rst
index dd053fa..ae6ab1c 100644
--- a/doc/source/reporters.rst
+++ b/doc/source/reporters.rst
@@ -31,10 +31,10 @@
 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 @@
   **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
diff --git a/zuul/driver/github/githubreporter.py b/zuul/driver/github/githubreporter.py
index 29edb8a..37cbe61 100644
--- a/zuul/driver/github/githubreporter.py
+++ b/zuul/driver/github/githubreporter.py
@@ -40,21 +40,25 @@
             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 @@
             (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,