GitHub Reporter: Fix User Email in Merge Commit Message

Re-introduce change https://review.opendev.org/#/c/738590/

There was a bug in fetching a GitHub user while loading pull requests.
`getUser` was given a project object instead of a project name string,
so no installation id was found for GitHub app authentication. That lead
to unauthenticated requests to the user API which resulted in HTTP 401
errors.

This change fixes this by passing the correct `project.name` to
`getUser` and also refactors the parameter names of the involved
methods from `project` to `project_name` to be more precise there.

This reverts commit 56f355ab72.

Change-Id: Ib25f0ef5d27115626792890d0ec282ed0d562485
This commit is contained in:
Benjamin Schanzel
2020-07-15 12:52:24 +02:00
parent 2d46288a25
commit 1ed3992809
5 changed files with 46 additions and 42 deletions

View File

@@ -2160,7 +2160,7 @@ class FakeGithubPullRequest(object):
'state': state,
'user': {
'login': user,
'email': user + "@derp.com",
'email': user + "@example.com",
},
'submitted_at': submitted_at,
}))
@@ -2279,12 +2279,12 @@ class FakeGithubClientManager(GithubClientManager):
self.github_data = None
def getGithubClient(self,
project=None,
project_name=None,
user_id=None,
zuul_event_id=None):
if self.app_id:
inst_id = self.installation_map.get(project)
inst_id = self.installation_map.get(project_name)
client = tests.fakegithub.FakeGithubClient(
self.github_data, inst_id=inst_id)
else:

View File

@@ -41,8 +41,8 @@ class ErrorResponse:
class FakeUser(object):
def __init__(self, login):
self.login = login
self.name = "Github User"
self.email = "github.user@example.com"
self.name = login
self.email = '%s@example.com' % login
self.html_url = 'https://example.com/%s' % login

View File

@@ -697,7 +697,7 @@ class TestGithubDriver(ZuulTestCase):
# assert that single 'Reviewed-By' is in merge commit message
self.assertThat(B.merge_message,
MatchesRegex(
r'.*Reviewed-by: derp <derp@derp.com>.*',
r'.*Reviewed-by: derp <derp@example.com>.*',
re.DOTALL))
C = self.fake_github.openFakePullRequest('org/project', 'master', 'C')
@@ -710,11 +710,11 @@ class TestGithubDriver(ZuulTestCase):
# assert that multiple 'Reviewed-By's are in merge commit message
self.assertThat(C.merge_message,
MatchesRegex(
r'.*Reviewed-by: derp <derp@derp.com>.*',
r'.*Reviewed-by: derp <derp@example.com>.*',
re.DOTALL))
self.assertThat(C.merge_message,
MatchesRegex(
r'.*Reviewed-by: herp <herp@derp.com>.*',
r'.*Reviewed-by: herp <herp@example.com>.*',
re.DOTALL))
@simple_layout('layouts/dependent-github.yaml', driver='github')