Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
GitHub hook: use sender login when username is not available (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored and roll committed Apr 22, 2019
1 parent 36782b8 commit 612a2e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion goodtablesio/integrations/github/utils/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def get_details_from_hook_payload(payload):
details['owner'] = payload['repository']['owner']['name']
details['sha'] = payload['head_commit']['id']
details['commit_message'] = payload['head_commit']['message']
details['author_name'] = payload['head_commit']['author']['username']
try:
details['author_name'] = payload['head_commit']['author']['username']
except KeyError:
details['author_name'] = payload['sender']['login']
details['branch_name'] = payload['ref'].replace('refs/heads/', '')

except KeyError:
Expand Down
21 changes: 21 additions & 0 deletions goodtablesio/tests/integrations/github/utils/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ def test_get_details_from_hook_payload_PUSH():
'branch_name': 'some-branch',
}

payload = {
'ref': 'refs/heads/some-branch',
'repository': {'name': 'test-repo', 'owner': {'name': 'test-owner'}},
'head_commit': {
'id': 'test-sha',
'message': 'Test message',
'author': {
'name': 'no-username',
}},
'sender': {'login': 'test-user'},
}
assert get_details_from_hook_payload(payload) == {
'owner': 'test-owner',
'repo': 'test-repo',
'sha': 'test-sha',
'is_pr': False,
'commit_message': 'Test message',
'author_name': 'test-user',
'branch_name': 'some-branch',
}


def test_get_details_from_hook_payload_PR():
payload = {
Expand Down

0 comments on commit 612a2e1

Please sign in to comment.