From e7974b3b656a11ade5ff3c83f146a98f1d311a2d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 21 Apr 2017 11:44:37 -0700 Subject: [PATCH] git: Fix nondeterministic ordering of commit authors. This should fix the nondeterministic test failures introduced by e7455e276bed114396ac0d40f0f89d4a215cc584. --- zerver/lib/webhooks/git.py | 4 +++- zerver/webhooks/gitlab/tests.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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):