[pypy-svn] buildbot default: truncate long messages

antocuni commits-noreply at bitbucket.org
Fri Jan 7 18:00:37 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r398:69e9eac01cf6
Date: 2011-01-07 17:39 +0100
http://bitbucket.org/pypy/buildbot/changeset/69e9eac01cf6/

Log:	truncate long messages

diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -86,7 +86,12 @@
                          key=operator.itemgetter('revision'))
         for commit in commits:
             message = commit['message']
-            irc_msg = '%s %s: %s' % (commit['author'], commit['node'], message)
+            part1 = '%s %s: ' % (commit['author'], commit['node'])
+            if len(message) + len(part1) <= 160:
+                irc_msg = part1 + message
+            else:
+                maxlen = 160 - (len(part1) + 3)
+                irc_msg = part1 + message[:maxlen] + '...'
             self.send_irc_message(irc_msg)
 
     def handle_diff_email(self):

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
@@ -46,7 +46,8 @@
     handler.handle_diff_email()
     assert handler.sent_commits == ['first', 'second']
 
-class test_irc_message():
+def test_irc_message():
+    LONG_MESSAGE = u'This is a test with a long message: ' + 'x'*1000
     class MyHandler(BaseHandler):
         def __init__(self):
             self.messages = []
@@ -58,7 +59,16 @@
                      'author': u'antocuni',
                      'message': u'this is a test',
                      'node': 'abcdef'
-                     }]
+                     },
+                    {'revision': 43,
+                     'author': u'antocuni',
+                     'message': LONG_MESSAGE,
+                     'node': 'xxxyyy'
+                     }
+                    ]
         }
     handler.handle_irc_message()
-    assert handler.messages == ['antocuni abcdef: this is a test']
+    msg1, msg2 = handler.messages
+    assert msg1 == 'antocuni abcdef: this is a test'
+    x = 'antocuni xxxyyy: %s...' % LONG_MESSAGE[:160-20]
+    assert msg2 == x


More information about the Pypy-commit mailing list