Extend in-repo config update support to github

The code that would look for in-repo config changes was gerrit specific.
Turn the gerrit specific bit into a generic that drivers can implement.

Implement the generic in the github driver, which required accounting
for files that are part of a push event (where code is landing in the
repo we care about).

Also remove an unnecessary fake pull request method of getPushEvent, as
there was already one in the fake github class.

Move the real updatesConfig function from the Change object to the Ref
object (since we can get a change from a ref) and move the files
attribute as well.

Introduce a test for github to verify that the tenant is reconfigured.
This required introducing a new Scheduler object attribute to track when
each tenant is reconfigured. The existing reconfiguration time tracker
was generic, and not updated via dyanmic updates.

Change-Id: Ibf59f91fa3701c15d93d859920fe3070478fe457
Story: 2000774
Task: 4664
diff --git a/tests/base.py b/tests/base.py
index 65ded50..b78495d 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -592,21 +592,6 @@
     def getPullRequestClosedEvent(self):
         return self._getPullRequestEvent('closed')
 
-    def getPushEvent(self, old_sha, ref='refs/heads/master'):
-        name = 'push'
-        data = {
-            'ref': ref,
-            'before': old_sha,
-            'after': self.head_sha,
-            'repository': {
-                'full_name': self.project
-            },
-            'sender': {
-                'login': 'ghuser'
-            }
-        }
-        return (name, data)
-
     def addComment(self, message):
         self.comments.append(message)
         self._updateTimeStamp()
@@ -896,7 +881,8 @@
         self.pull_requests.append(pull_request)
         return pull_request
 
-    def getPushEvent(self, project, ref, old_rev=None, new_rev=None):
+    def getPushEvent(self, project, ref, old_rev=None, new_rev=None,
+                     added_files=[], removed_files=[], modified_files=[]):
         if not old_rev:
             old_rev = '00000000000000000000000000000000'
         if not new_rev:
@@ -908,7 +894,14 @@
             'after': new_rev,
             'repository': {
                 'full_name': project
-            }
+            },
+            'commits': [
+                {
+                    'added': added_files,
+                    'removed': removed_files,
+                    'modified': modified_files
+                }
+            ]
         }
         return (name, data)
 
diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py
index 227d659..2474095 100644
--- a/tests/unit/test_github_driver.py
+++ b/tests/unit/test_github_driver.py
@@ -510,3 +510,18 @@
         self.assertNotIn('merge', A.labels)
         self.assertNotIn('merge', B.labels)
         self.assertNotIn('merge', C.labels)
+
+    @simple_layout('layouts/basic-github.yaml', driver='github')
+    def test_push_event_reconfigure(self):
+        pevent = self.fake_github.getPushEvent(project='common-config',
+                                               ref='refs/heads/master',
+                                               modified_files=['zuul.yaml'])
+
+        # record previous tenant reconfiguration time, which may not be set
+        old = self.sched.tenant_last_reconfigured.get('tenant-one', 0)
+        time.sleep(1)
+        self.fake_github.emitEvent(pevent)
+        self.waitUntilSettled()
+        new = self.sched.tenant_last_reconfigured.get('tenant-one', 0)
+        # New timestamp should be greater than the old timestamp
+        self.assertLess(old, new)
diff --git a/tests/unit/test_push_reqs.py b/tests/unit/test_push_reqs.py
index 657d9b8..d3a1feb 100644
--- a/tests/unit/test_push_reqs.py
+++ b/tests/unit/test_push_reqs.py
@@ -28,7 +28,10 @@
         # Create a github change, add a change and emit a push event
         A = self.fake_github.openFakePullRequest('org/project1', 'master', 'A')
         old_sha = A.head_sha
-        self.fake_github.emitEvent(A.getPushEvent(old_sha))
+        pevent = self.fake_github.getPushEvent(project='org/project1',
+                                               ref='refs/heads/master',
+                                               old_rev=old_sha)
+        self.fake_github.emitEvent(pevent)
 
         self.waitUntilSettled()