Skip to content

Commit

Permalink
Always add the person who opened the PR in the authors list
Browse files Browse the repository at this point in the history
Otherwise a PR by someone commits without a login, plus commits from someone else
won't credit the person who opened the PR. Making a PR from someone else's
branch without adding commits to it is rare.
  • Loading branch information
asmeurer committed Mar 1, 2019
1 parent 26c4748 commit 3b9363f
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 4 deletions.
3 changes: 1 addition & 2 deletions fix_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def main():
if commit['author']:
users.add(commit['author']['login'])

if not users:
users = {pull_request.json()['head']['user']['login']}
users.add(pull_request.json()['head']['user']['login'])

pr_users[pr] = users

Expand Down
125 changes: 125 additions & 0 deletions sympy_bot/tests/test_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,3 +1742,128 @@ async def test_bad_version_file(action):
}
assert patch_urls == []
assert patch_data == []


@parametrize('action', ['opened', 'reopened', 'synchronize', 'edited'])
@parametrize('include_extra', [True, False])
async def test_no_user_logins_in_commits(action, include_extra):
event_data = {
'pull_request': {
'number': 1,
'state': 'open',
'merged': False,
'comments_url': comments_url,
'commits_url': commits_url,
'head': {
'user': {
'login': 'asmeurer',
},
},
'base': {
'repo': {
'contents_url': contents_url,
'html_url': html_url,
},
},
'body': valid_PR_description,
'statuses_url': statuses_url,
},
'action': action,
}


commits = [
{
'author': None,
'commit': {
'message': "A good commit",
},
'sha': 'a109f824f4cb2b1dd97cf832f329d59da00d609a',
},
]
if include_extra:
commits += [
{
'author': {
'login': 'certik',
},
'commit': {
'message': "A good commit",
},
'sha': 'a109f824f4cb2b1dd97cf832f329d59da00d609a',
},
]

# No comment from sympy-bot
comments = [
{
'user': {
'login': 'asmeurer',
},
},
{
'user': {
'login': 'certik',
},
},
]

version_file = {
'content': base64.b64encode(b'__version__ = "1.2.1.dev"\n'),
}

getiter = {
commits_url: commits,
comments_url: comments,
}

getitem = {
version_url: version_file,
}
post = {
comments_url: {
'html_url': comment_html_url,
},
statuses_url: {},
}

event = _event(event_data)

gh = FakeGH(getiter=getiter, getitem=getitem, post=post)

await router.dispatch(event, gh)

getitem_urls = gh.getitem_urls
getiter_urls = gh.getiter_urls
post_urls = gh.post_urls
post_data = gh.post_data
patch_urls = gh.patch_urls
patch_data = gh.patch_data

assert getiter_urls == list(getiter)
assert getitem_urls == list(getitem)
assert post_urls == [comments_url, statuses_url]
assert len(post_data) == 2
# Comments data
assert post_data[0].keys() == {"body"}
comment = post_data[0]["body"]
assert ":white_check_mark:" in comment
assert ":x:" not in comment
assert "new trig solvers" in comment
assert "error" not in comment
assert "https://github.com/sympy/sympy-bot" in comment
for line in valid_PR_description:
assert line in comment
assert "good order" in comment
assert "@asmeurer" in comment
if include_extra:
assert "@certik" in comment
# Statuses data
assert post_data[1] == {
"state": "success",
"target_url": comment_html_url,
"description": "The release notes look OK",
"context": "sympy-bot/release-notes",
}
assert patch_urls == []
assert patch_data == []
4 changes: 2 additions & 2 deletions sympy_bot/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async def pull_request_comment(event, gh):
if BEGIN_RELEASE_NOTES in message or END_RELEASE_NOTES in message:
header_in_message = commit['sha']

if not users:
users = {event.data['pull_request']['head']['user']['login']}

users.add(event.data['pull_request']['head']['user']['login'])

users = sorted(users)
contents_url = event.data['pull_request']['base']['repo']['contents_url']
Expand Down

0 comments on commit 3b9363f

Please sign in to comment.