Merge "Fix issue in Github connection with large diffs"

This commit is contained in:
Zuul 2018-11-06 11:30:12 +00:00 committed by Gerrit Code Review
commit c96d0b918a
2 changed files with 25 additions and 2 deletions

View File

@ -18,9 +18,10 @@ from testtools.matchers import MatchesRegex, StartsWith
import urllib
import socket
import time
from unittest import skip
from unittest import mock, skip
import git
import github3.exceptions
from tests.base import ZuulTestCase, simple_layout, random_sha1
from tests.base import ZuulWebFixture
@ -114,6 +115,19 @@ class TestGithubDriver(ZuulTestCase):
self.waitUntilSettled()
self.assertEqual(1, len(self.history))
@simple_layout('layouts/basic-github.yaml', driver='github')
def test_pull_github_files_error(self):
A = self.fake_github.openFakePullRequest(
'org/project', 'master', 'A')
with mock.patch("tests.fakegithub.FakePull.files") as files_mock:
files_mock.side_effect = github3.exceptions.ServerError(
mock.MagicMock())
self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
self.waitUntilSettled()
self.assertEqual(1, files_mock.call_count)
self.assertEqual(2, len(self.history))
@simple_layout('layouts/basic-github.yaml', driver='github')
def test_comment_event(self):
A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')

View File

@ -1044,7 +1044,16 @@ class GithubConnection(BaseConnection):
# Get the issue obj so we can get the labels (this is silly)
issueobj = probj.issue()
pr = probj.as_dict()
pr['files'] = [f.filename for f in probj.files()]
try:
pr['files'] = [f.filename for f in probj.files()]
except github3.exceptions.ServerError as exc:
# NOTE: For PRs with a lot of lines changed, Github will return
# an error (HTTP 500) because it can't generate the diff.
self.log.warning("Failed to get list of files from Github. "
"Using empty file list to trigger update "
"via the merger: %s", exc)
pr['files'] = []
pr['labels'] = [l.name for l in issueobj.labels()]
self.log.debug('Got PR %s#%s', project_name, number)
self.log_rate_limit(self.log, github)