Fix github dependent pipeline with merge
When enabling merge in a github gate pipeline merge message formatting
fails with an exception [1]. The reason for this is a missing
initialization of the GithubUser data structure which is using lazy
initialization (presumibly due to api rate limiting). This is fixed by
adding the initialization.
This was uncovered in the tests because the FakeGithubConnection
directly returns a data structure instead of a GithubUser object like
the real GithubConnection. This is fixed by returning a real
GithubUser object linked to a FakeGithub object.
[1] 2017-08-02 07:13:21,323 ERROR zuul.DependentPipelineManager: Exception while reporting:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/zuul/manager/__init__.py", line 786, in _reportItem
ret = self.sendReport(actions, item)
File "/usr/lib/python3.6/site-packages/zuul/manager/__init__.py", line 168, in sendReport
ret = reporter.report(item)
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubreporter.py", line 73, in report
self.mergePull(item)
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubreporter.py", line 129, in mergePull
message = self._formatMergeMessage(item.change)
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubreporter.py", line 168, in _formatMergeMessage
if not account:
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubconnection.py", line 340, in __len__
return len(self._data)
TypeError: object of type 'NoneType' has no len()
Change-Id: Ieb9694ff0c98c8cc4011cd4e36627e8ed647d078
diff --git a/tests/base.py b/tests/base.py
index 35c8324..7093e13 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -551,6 +551,18 @@
_points_to_commits_only = True
+class FakeGithub(object):
+
+ class FakeUser(object):
+ def __init__(self, login):
+ self.login = login
+ self.name = "Github User"
+ self.email = "github.user@example.com"
+
+ def user(self, login):
+ return self.FakeUser(login)
+
+
class FakeGithubPullRequest(object):
def __init__(self, github, number, project, branch,
@@ -879,6 +891,13 @@
self.merge_failure = False
self.merge_not_allowed_count = 0
self.reports = []
+ self.github_client = FakeGithub()
+
+ def getGithubClient(self,
+ project=None,
+ user_id=None,
+ use_app=True):
+ return self.github_client
def openFakePullRequest(self, project, branch, subject, files=[],
body=None):
@@ -965,14 +984,6 @@
pr = self.pull_requests[number - 1]
return pr.reviews
- def getUser(self, login):
- data = {
- 'username': login,
- 'name': 'Github User',
- 'email': 'github.user@example.com'
- }
- return data
-
def getRepoPermission(self, project, login):
owner, proj = project.split('/')
for pr in self.pull_requests:
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 48603a0..80ac573 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -326,25 +326,26 @@
self._data = None
def __getitem__(self, key):
- if self._data is None:
- self._data = self._init_data()
+ self._init_data()
return self._data[key]
def __iter__(self):
+ self._init_data()
return iter(self._data)
def __len__(self):
+ self._init_data()
return len(self._data)
def _init_data(self):
- user = self._github.user(self._username)
- log_rate_limit(self.log, self._github)
- data = {
- 'username': user.login,
- 'name': user.name,
- 'email': user.email
- }
- return data
+ if self._data is None:
+ user = self._github.user(self._username)
+ log_rate_limit(self.log, self._github)
+ self._data = {
+ 'username': user.login,
+ 'name': user.name,
+ 'email': user.email
+ }
class GithubConnection(BaseConnection):