From 72b0bd92cfba4ee3b2f697ae440fb46c24c2e16b Mon Sep 17 00:00:00 2001 From: Ian Moody Date: Wed, 29 Mar 2017 17:47:52 +0100 Subject: [PATCH 1/4] Add branch name to the changeset data for non-default branches --- pulsebot/pulse_hgpushes.py | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/pulsebot/pulse_hgpushes.py b/pulsebot/pulse_hgpushes.py index 5af8561..1980b8b 100644 --- a/pulsebot/pulse_hgpushes.py +++ b/pulsebot/pulse_hgpushes.py @@ -90,6 +90,8 @@ def get_push_info_from(push_url): } if len(cs['parents']) > 1: data['is_merge'] = True + if cs['branch'] != "default": + data['branch'] = cs['branch'] for l in desc: if l.startswith('Source-Repo:'): data['source-repo'] = l.split(' ', 1)[1] @@ -242,3 +244,88 @@ def test_pushes_info(self): 'user': u'gszorc@mozilla.com' }] self.assertEquals(pushes, servo_results) + + message = {'payload': { + 'repo_url': + 'https://hg.mozilla.org/integration/mozilla-inbound/', + 'pushlog_pushes': [ + {'push_full_json_url': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'json-pushes?version=2&full=1&startID=30963&endID=30964'} + ], + }} + + pushes = list(PulseHgPushes.get_pushes_info(message)) + + self.maxDiff = None + branch_results = [{ + 'pushlog': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'pushloghtml?startID=30963&endID=30964', + 'user': 'mozilla@noorenberghe.ca', + 'changesets': [{ + 'author': 'Matthew Noorenberghe', + 'revlink': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'rev/25093037bf15', + 'desc': + 'Bug 845692 - Close version 2.0 release branches. ' + 'a=bhearsum', + 'branch': 'COMM2000_20110114_RELBRANCH', + }, { + 'author': 'Matthew Noorenberghe', + 'revlink': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'rev/ab389a306b4c', + 'desc': + 'Bug 845692 - Close version 2.0 release branches. ' + 'a=bhearsum', + 'branch': 'GECKO20b10_2011012115_RELBRANCH', + }, { + 'author': 'Matthew Noorenberghe', + 'revlink': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'rev/987ccd4b66b0', + 'desc': + 'Bug 845692 - Close version 2.0 release branches. ' + 'a=bhearsum', + 'branch': 'GECKO20b11pre_20110126_RELBRANCH', + }, { + 'author': 'Matthew Noorenberghe', + 'revlink': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'rev/c16fafdf2f99', + 'desc': + 'Bug 845692 - Close version 2.0 release branches. ' + 'a=bhearsum', + 'branch': 'GECKO20b11_2011020209_RELBRANCH', + }, { + 'author': 'Matthew Noorenberghe', + 'revlink': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'rev/a2e691986b0c', + 'desc': + 'Bug 845692 - Close version 2.0 release branches. ' + 'a=bhearsum', + 'branch': 'GECKO20b12pre_20110216_RELBRANCH', + }, { + 'author': 'Matthew Noorenberghe', + 'revlink': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'rev/6bcf231bd430', + 'desc': + 'Bug 845692 - Close version 2.0 release branches. ' + 'a=bhearsum', + 'branch': 'GECKO20b12_2011022218_RELBRANCH', + }, { + 'author': 'Matthew Noorenberghe', + 'revlink': + 'https://hg.mozilla.org/integration/mozilla-inbound/' + 'rev/fb4cf6555081', + 'desc': + 'Bug 845692 - Close version 2.0 release branches. ' + 'a=bhearsum', + 'branch': 'COMM2000_20110314_RELBRANCH', + }], + }] + self.assertEquals(pushes, branch_results) From ad344bafc09c15e5186753affe4a21d600d73211 Mon Sep 17 00:00:00 2001 From: Ian Moody Date: Tue, 19 Sep 2017 17:03:21 +0100 Subject: [PATCH 2/4] Add branch to the irc message --- pulsebot/pulse_dispatch.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pulsebot/pulse_dispatch.py b/pulsebot/pulse_dispatch.py index 9c81fb1..955fd48 100644 --- a/pulsebot/pulse_dispatch.py +++ b/pulsebot/pulse_dispatch.py @@ -136,6 +136,8 @@ def create_messages(push, max_checkins=sys.maxsize, max_bugs=5): for cs in changesets: revlink = cs['revlink'] desc = cs['desc'] + if cs.get('branch'): + revlink += " [%s]" % (cs['branch']) if group_changesets: bugs = parse_bugs(desc) @@ -146,7 +148,9 @@ def create_messages(push, max_checkins=sys.maxsize, max_bugs=5): yield "%s - %s - %s" % (revlink, author, desc) if group_changesets: - group = '%s - %d changesets' % (push['pushlog'], len(changesets)) + pushlog = "%s [%s]" % (push['pushlog'], changesets[-1]['branch'])\ + if changesets[-1].get('branch') else push['pushlog'] + group = '%s - %d changesets' % (pushlog, len(changesets)) if merge: group += ' - %s' % last_desc @@ -332,6 +336,11 @@ class TestPulseDispatcher(unittest.TestCase): 'revlink': 'https://server/repo/rev/890abcdef012', 'desc': 'Merge branch into repo', 'is_merge': True, + }, { + 'author': 'Com Munity', + 'revlink': 'https://server/repo/rev/6e4e7985aba3', + 'desc': 'Bug 46 - Add tags', + 'branch': 'subproject', }] def test_create_messages(self): @@ -405,6 +414,15 @@ def test_create_messages(self): '- Merge branch into repo' ]) + branchpush = { + 'pushlog': 'https://server/repo/pushloghtml?startID=2&endID=3', + 'changesets': self.CHANGESETS[8:9], + } + self.assertEquals(list(PulseDispatcher.create_messages(branchpush)), [ + 'https://server/repo/rev/6e4e7985aba3 [subproject] - ' + 'Com Munity - Bug 46 - Add tags' + ]) + def test_munge_for_bugzilla(self): def munge(push): return { From b5d5084facd95a87f92aed8decaa6266b65d2460 Mon Sep 17 00:00:00 2001 From: Ian Moody Date: Tue, 19 Sep 2017 17:03:52 +0100 Subject: [PATCH 3/4] Add branch to bugzilla comments --- pulsebot/pulse_dispatch.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pulsebot/pulse_dispatch.py b/pulsebot/pulse_dispatch.py index 955fd48..7594ecd 100644 --- a/pulsebot/pulse_dispatch.py +++ b/pulsebot/pulse_dispatch.py @@ -63,6 +63,8 @@ def add_changeset(self, cs): 'desc': cs['desc'], 'is_backout': bool(BACKOUT_RE.match(cs['desc'])), }) + if cs.get('branch'): + self.changesets[-1]['branch'] = cs['branch'] def __iter__(self): return iter(self.changesets) @@ -185,7 +187,8 @@ def munge_for_bugzilla(push): @staticmethod def bugzilla_summary(cs): - yield cs['revlink'] + yield '%s [%s]' % (cs['revlink'], cs['branch']) if cs.get('branch') \ + else cs['revlink'] desc = cs['desc'] matches = [m for m in BUG_RE.finditer(desc) @@ -616,6 +619,16 @@ def do_push(push, leave_open=False): do_push(push) self.assertEquals(bz.data, {}) + bz.clear() + push['changesets'] = self.CHANGESETS[8:9] + comments = {46: [ + 'Pushed by foo@bar.com:\n' + 'https://server/repo/rev/6e4e7985aba3 [subproject]\n' + 'Add tags' + ]} + do_push(push) + self.assertEquals(bz.comments, comments) + def test_bugzilla_summary(self): def summary_equals(desc, summary): self.assertEquals(list(PulseDispatcher.bugzilla_summary({ From d762c36ca3d1b005968a92ce2abbdc68974865ce Mon Sep 17 00:00:00 2001 From: Ian Moody Date: Wed, 20 Sep 2017 14:42:16 +0100 Subject: [PATCH 4/4] Group changesets by branch in bugzilla comments --- pulsebot/pulse_dispatch.py | 106 ++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 13 deletions(-) diff --git a/pulsebot/pulse_dispatch.py b/pulsebot/pulse_dispatch.py index 7594ecd..853b01c 100644 --- a/pulsebot/pulse_dispatch.py +++ b/pulsebot/pulse_dispatch.py @@ -12,6 +12,7 @@ import unittest from collections import ( defaultdict, + OrderedDict, ) from Queue import Queue, Empty from pulsebot.bugzilla import ( @@ -187,8 +188,7 @@ def munge_for_bugzilla(push): @staticmethod def bugzilla_summary(cs): - yield '%s [%s]' % (cs['revlink'], cs['branch']) if cs.get('branch') \ - else cs['revlink'] + yield cs['revlink'] desc = cs['desc'] matches = [m for m in BUG_RE.finditer(desc) @@ -249,18 +249,39 @@ def get_one(): if cs_to_write: is_backout = all(cs['is_backout'] for cs in cs_to_write) + has_branches = any('branch' in cs for cs in cs_to_write) + branches = OrderedDict() + + for cs in cs_to_write: + key = cs.get('branch', 'default') + if key in branches: + branches[key].append(cs) + else: + branches[key] = [cs] def comment(): - if is_backout: - if info.pusher: - yield 'Backout by %s:' % info.pusher + start = True + for branch in branches: + if start: + start = False else: - yield 'Backout:' - elif info.pusher: - yield 'Pushed by %s:' % info.pusher - for cs in cs_to_write: - for line in self.bugzilla_summary(cs): - yield line + yield '' + branch_info = ( + ' on the default branch' if branch == 'default' + else ' on the branch %s' % branch) if \ + has_branches else '' + if is_backout: + if info.pusher: + yield 'Backout by %s%s:' \ + % (info.pusher, branch_info) + else: + yield 'Backout%s:' % branch_info + elif info.pusher: + yield 'Pushed by %s%s:' \ + % (info.pusher, branch_info) + for cs in branches[branch]: + for line in self.bugzilla_summary(cs): + yield line try: fields = ('whiteboard', 'keywords') @@ -622,13 +643,72 @@ def do_push(push, leave_open=False): bz.clear() push['changesets'] = self.CHANGESETS[8:9] comments = {46: [ - 'Pushed by foo@bar.com:\n' - 'https://server/repo/rev/6e4e7985aba3 [subproject]\n' + 'Pushed by foo@bar.com on the branch subproject:\n' + 'https://server/repo/rev/6e4e7985aba3\n' 'Add tags' ]} do_push(push) self.assertEquals(bz.comments, comments) + bz.clear() + push['changesets'] = [{ + 'author': 'foo', + 'revlink': 'https://server/repo/rev/6e4e7985aba3', + 'desc': 'Bug 47 - Foo', + 'branch': 'foo', + }, { + 'author': 'foo', + 'revlink': 'https://server/repoa/rev/1234567890ab', + 'desc': 'Bug 47 - Bar', + 'branch': 'foo', + }, { + 'author': 'qux', + 'revlink': 'https://server/repoa/rev/234567890abc', + 'desc': 'Bug 47 - Qux', + 'branch': 'qux', + }] + comments = {47: [ + 'Pushed by foo@bar.com on the branch foo:\n' + 'https://server/repo/rev/6e4e7985aba3\n' + 'Foo\n' + 'https://server/repoa/rev/1234567890ab\n' + 'Bar\n' + '\n' + 'Pushed by foo@bar.com on the branch qux:\n' + 'https://server/repoa/rev/234567890abc\n' + 'Qux' + ]} + do_push(push) + self.assertEquals(bz.comments, comments) + + bz.clear() + push['changesets'][1].pop('branch') + comments2 = {47: [ + 'Pushed by foo@bar.com on the branch foo:\n' + 'https://server/repo/rev/6e4e7985aba3\n' + 'Foo\n' + '\n' + 'Pushed by foo@bar.com on the default branch:\n' + 'https://server/repoa/rev/1234567890ab\n' + 'Bar\n' + '\n' + 'Pushed by foo@bar.com on the branch qux:\n' + 'https://server/repoa/rev/234567890abc\n' + 'Qux' + ]} + do_push(push) + self.assertEquals(bz.comments, comments2) + + bz.clear() + push['changesets'][1]['branch'] = 'foo' + push['changesets'] = [ + push['changesets'][0], + push['changesets'][2], + push['changesets'][1], + ] + do_push(push) + self.assertEquals(bz.comments, comments) + def test_bugzilla_summary(self): def summary_equals(desc, summary): self.assertEquals(list(PulseDispatcher.bugzilla_summary({