From 152a402493b9723b107bbd2da8e88becf3ea3c49 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Fri, 7 Jul 2017 08:39:52 -0700 Subject: [PATCH] Ensure github change body is not a NoneType The test framework was already operating in this way, but this changes it to reflect that we might get pull requests without a body (description). Without this, we'd attempt to run a regex on a None type which causes a traceback. Change-Id: Ibabf6452bd7d0c6df071227d8a3dc2e32f36158e --- tests/base.py | 10 +++++++--- zuul/driver/github/githubconnection.py | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/base.py b/tests/base.py index 617169a614..45af51d080 100755 --- a/tests/base.py +++ b/tests/base.py @@ -554,7 +554,7 @@ class FakeGithubPullRequest(object): def __init__(self, github, number, project, branch, subject, upstream_root, files=[], number_of_commits=1, - writers=[], body=''): + writers=[], body=None): """Creates a new PR with several commits. Sends an event about opened PR.""" self.github = github @@ -880,7 +880,7 @@ class FakeGithubConnection(githubconnection.GithubConnection): self.reports = [] def openFakePullRequest(self, project, branch, subject, files=[], - body=''): + body=None): self.pr_number += 1 pull_request = FakeGithubPullRequest( self, self.pr_number, project, branch, subject, self.upstream_root, @@ -1051,7 +1051,11 @@ class FakeGithubConnection(githubconnection.GithubConnection): (self.git_host, change.project.name, change.number)) for pr in self.pull_requests: - if pattern.search(pr.body): + if not pr.body: + body = '' + else: + body = pr.body + if pattern.search(body): # Get our version of a pull so that it's a dict pull = self.getPull(pr.project, pr.number) prs.append(pull) diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py index 6e0ccde816..7d27c865fc 100644 --- a/zuul/driver/github/githubconnection.py +++ b/zuul/driver/github/githubconnection.py @@ -595,6 +595,9 @@ class GithubConnection(BaseConnection): change.number) change.labels = change.pr.get('labels') change.body = change.pr.get('body') + # ensure body is at least an empty string + if not change.body: + change.body = '' if history is None: history = []