Better merge message for GitHub pull reqeusts

* Preserve pull reqeust title in the commit message.
* Add information about the user who triggered the merge.

Change-Id: Ibe0bb5ee273a6ae22fde2e0d71fd10b600dee17f
diff --git a/tests/base.py b/tests/base.py
index 77c0644..c567b03 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -564,6 +564,7 @@
         self.updated_at = None
         self.head_sha = None
         self.is_merged = False
+        self.merge_message = None
         self._createPRRef()
         self._addCommitToRepo()
         self._updateTimeStamp()
@@ -608,6 +609,9 @@
             },
             'repository': {
                 'full_name': self.project
+            },
+            'sender': {
+                'login': 'ghuser'
             }
         }
         return (name, data)
@@ -643,6 +647,9 @@
             },
             'label': {
                 'name': label
+            },
+            'sender': {
+                'login': 'ghuser'
             }
         }
         return (name, data)
@@ -653,6 +660,7 @@
             'action': 'unlabeled',
             'pull_request': {
                 'number': self.number,
+                'title': self.subject,
                 'updated_at': self.updated_at,
                 'base': {
                     'ref': self.branch,
@@ -666,6 +674,9 @@
             },
             'label': {
                 'name': label
+            },
+            'sender': {
+                'login': 'ghuser'
             }
         }
         return (name, data)
@@ -732,6 +743,7 @@
             'number': self.number,
             'pull_request': {
                 'number': self.number,
+                'title': self.subject,
                 'updated_at': self.updated_at,
                 'base': {
                     'ref': self.branch,
@@ -742,6 +754,9 @@
                 'head': {
                     'sha': self.head_sha
                 }
+            },
+            'sender': {
+                'login': 'ghuser'
             }
         }
         return (name, data)
@@ -800,6 +815,7 @@
         pr = self.pull_requests[number - 1]
         data = {
             'number': number,
+            'title': pr.subject,
             'updated_at': pr.updated_at,
             'base': {
                 'repo': {
@@ -814,6 +830,14 @@
         }
         return data
 
+    def getUser(self, login):
+        data = {
+            'username': login,
+            'name': 'Github User',
+            'email': 'github.user@example.com'
+        }
+        return data
+
     def getGitUrl(self, project):
         return os.path.join(self.upstream_root, str(project))
 
@@ -830,7 +854,7 @@
         pull_request = self.pull_requests[pr_number - 1]
         pull_request.addComment(message)
 
-    def mergePull(self, project, pr_number, sha=None):
+    def mergePull(self, project, pr_number, commit_message='', sha=None):
         pull_request = self.pull_requests[pr_number - 1]
         if self.merge_failure:
             raise Exception('Pull request was not merged')
@@ -839,6 +863,7 @@
             raise MergeFailure('Merge was not successful due to mergeability'
                                ' conflict')
         pull_request.is_merged = True
+        pull_request.merge_message = commit_message
 
     def setCommitStatus(self, project, sha, state,
                         url='', description='', context=''):
diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py
index 3f567d2..7267b83 100644
--- a/tests/unit/test_github_driver.py
+++ b/tests/unit/test_github_driver.py
@@ -258,10 +258,13 @@
     @simple_layout('layouts/merging-github.yaml', driver='github')
     def test_report_pull_merge(self):
         # pipeline merges the pull request on success
-        A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
+        A = self.fake_github.openFakePullRequest('org/project', 'master',
+                                                 'PR title')
         self.fake_github.emitEvent(A.getCommentAddedEvent('merge me'))
         self.waitUntilSettled()
         self.assertTrue(A.is_merged)
+        self.assertThat(A.merge_message,
+                        MatchesRegex('.*PR title.*Reviewed-by.*', re.DOTALL))
 
         # pipeline merges the pull request on success after failure
         self.fake_github.merge_failure = True