[pypy-svn] buildbot default: make sure to send the emails sorted by revision number, because the bitbucket payload might be unsorted

antocuni commits-noreply at bitbucket.org
Tue Dec 21 14:01:13 CET 2010


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r396:eafd7a336e51
Date: 2010-12-21 14:01 +0100
http://bitbucket.org/pypy/buildbot/changeset/eafd7a336e51/

Log:	make sure to send the emails sorted by revision number, because the
	bitbucket payload might be unsorted

diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -70,7 +70,10 @@
         self.handle_diff_email()
 
     def handle_diff_email(self):
-        for commit in self.payload['commits']:
+        import operator
+        commits = sorted(self.payload['commits'],
+                         key=operator.itemgetter('revision'))
+        for commit in commits:
             self.send_diff_for_commit(commit)
 
     def send_diff_for_commit(self, commit):

diff --git a/bitbucket_hook/test/test_hook.py b/bitbucket_hook/test/test_hook.py
--- a/bitbucket_hook/test/test_hook.py
+++ b/bitbucket_hook/test/test_hook.py
@@ -30,3 +30,19 @@
     stdout = handler.hg('foobar')
     assert type(stdout) is unicode
     assert stdout == u'\ufffdaa'
+
+def test_sort_commits():
+    class MyHandler(BaseHandler):
+        def __init__(self):
+            self.sent_commits = []
+        def send_diff_for_commit(self, commit):
+            self.sent_commits.append(commit['node'])
+
+    #
+    handler = MyHandler()
+    handler.payload = {
+        'commits': [{'revision': 43, 'node': 'second'},
+                    {'revision': 42, 'node': 'first'}]
+        }
+    handler.handle_diff_email()
+    assert handler.sent_commits == ['first', 'second']


More information about the Pypy-commit mailing list