Add 'push' and 'tag' github webhook events.

Change-Id: Ie7ea0f4e264beac530d8eeda13919342a9c9eb58
Co-Authored-By: Jan Hruban <jan.hruban@gooddata.com>
diff --git a/tests/base.py b/tests/base.py
index d6304d7..cfc8fd8 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -672,6 +672,22 @@
         self.pull_requests.append(pull_request)
         return pull_request
 
+    def getPushEvent(self, project, ref, old_rev=None, new_rev=None):
+        if not old_rev:
+            old_rev = '00000000000000000000000000000000'
+        if not new_rev:
+            new_rev = random_sha1()
+        name = 'push'
+        data = {
+            'ref': ref,
+            'before': old_rev,
+            'after': new_rev,
+            'repository': {
+                'full_name': project
+            }
+        }
+        return (name, data)
+
     def emitEvent(self, event):
         """Emulates sending the GitHub webhook event to the connection."""
         port = self.webapp.server.socket.getsockname()[1]
diff --git a/tests/fixtures/layouts/push-tag-github.yaml b/tests/fixtures/layouts/push-tag-github.yaml
new file mode 100644
index 0000000..814068f
--- /dev/null
+++ b/tests/fixtures/layouts/push-tag-github.yaml
@@ -0,0 +1,29 @@
+- pipeline:
+    name: post
+    manager: independent
+    trigger:
+      github:
+        - event: push
+          ref: ^refs/heads/.*$
+
+- pipeline:
+    name: tag
+    manager: independent
+    trigger:
+      github:
+        - event: push
+          ref: ^refs/tags/.*$
+
+- job:
+    name: project-post
+- job:
+    name: project-tag
+
+- project:
+    name: org/project
+    post:
+      jobs:
+        - project-post
+    tag:
+      jobs:
+        - project-tag
diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py
index 430cab3..d386ae4 100644
--- a/tests/unit/test_github_driver.py
+++ b/tests/unit/test_github_driver.py
@@ -14,7 +14,7 @@
 
 import logging
 
-from tests.base import ZuulTestCase, simple_layout
+from tests.base import ZuulTestCase, simple_layout, random_sha1
 
 logging.basicConfig(level=logging.DEBUG,
                     format='%(asctime)s %(name)-32s '
@@ -51,3 +51,49 @@
         self.assertEqual(pr.number, zuulvars['change'])
         self.assertEqual(pr.head_sha, zuulvars['patchset'])
         self.assertEqual(1, len(pr.comments))
+
+    @simple_layout('layouts/push-tag-github.yaml', driver='github')
+    def test_tag_event(self):
+        self.executor_server.hold_jobs_in_build = True
+
+        sha = random_sha1()
+        self.fake_github.emitEvent(
+            self.fake_github.getPushEvent('org/project', 'refs/tags/newtag',
+                                          new_rev=sha))
+        self.waitUntilSettled()
+
+        build_params = self.builds[0].parameters
+        self.assertEqual('refs/tags/newtag', build_params['ZUUL_REF'])
+        self.assertEqual('00000000000000000000000000000000',
+                         build_params['ZUUL_OLDREV'])
+        self.assertEqual(sha, build_params['ZUUL_NEWREV'])
+
+        self.executor_server.hold_jobs_in_build = False
+        self.executor_server.release()
+        self.waitUntilSettled()
+
+        self.assertEqual('SUCCESS',
+                         self.getJobFromHistory('project-tag').result)
+
+    @simple_layout('layouts/push-tag-github.yaml', driver='github')
+    def test_push_event(self):
+        self.executor_server.hold_jobs_in_build = True
+
+        old_sha = random_sha1()
+        new_sha = random_sha1()
+        self.fake_github.emitEvent(
+            self.fake_github.getPushEvent('org/project', 'refs/heads/master',
+                                          old_sha, new_sha))
+        self.waitUntilSettled()
+
+        build_params = self.builds[0].parameters
+        self.assertEqual('refs/heads/master', build_params['ZUUL_REF'])
+        self.assertEqual(old_sha, build_params['ZUUL_OLDREV'])
+        self.assertEqual(new_sha, build_params['ZUUL_NEWREV'])
+
+        self.executor_server.hold_jobs_in_build = False
+        self.executor_server.release()
+        self.waitUntilSettled()
+
+        self.assertEqual('SUCCESS',
+                         self.getJobFromHistory('project-post').result)