diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py index dda86c52d3..e275b89446 100644 --- a/zerver/lib/webhooks/git.py +++ b/zerver/lib/webhooks/git.py @@ -190,7 +190,9 @@ def get_all_committers(commits_data): for commit in commits_data: committers[commit['name']] += 1 - committers_items = sorted(list(committers.items()), key=lambda item: item[1], reverse=True) # type: List[Tuple[str, int]] + # Sort by commit count, breaking ties alphabetically. + committers_items = sorted(list(committers.items()), + key=lambda item: (-item[1], item[0])) # type: List[Tuple[str, int]] committers_values = [c_i[1] for c_i in committers_items] # type: List[int] if len(committers) > PUSH_COMMITTERS_LIMIT_INFO: diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py index 9b16fc9b14..70678725e3 100644 --- a/zerver/webhooks/gitlab/tests.py +++ b/zerver/webhooks/gitlab/tests.py @@ -41,7 +41,7 @@ class GitlabHookTests(WebhookTestCase): # type: () -> None expected_subject = u"my-awesome-project / tomek" commit_info = u"* b ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))\n" - expected_message = u"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 7 commits to branch tomek. Commits by Ben(3), baxterthehacker(2), Tomasz Kolek(1) and others(1)\n\n{}* b ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))".format(commit_info * 6) + expected_message = u"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 7 commits to branch tomek. Commits by Ben(3), baxterthehacker(2), James(1) and others(1)\n\n{}* b ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))".format(commit_info * 6) self.send_and_test_stream_message('push_multiple_committers_with_others', expected_subject, expected_message, HTTP_X_GITLAB_EVENT="Push Hook") def test_push_commits_more_than_limit_event_message(self):