Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add branch names for pushes on non-default branches #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 121 additions & 10 deletions pulsebot/pulse_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import unittest
from collections import (
defaultdict,
OrderedDict,
)
from Queue import Queue, Empty
from pulsebot.bugzilla import (
Expand Down Expand Up @@ -63,6 +64,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']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically speaking, a push could have multiple changesets all on different branches. So the branch should be attached to all changesets. Then when creating the bugzilla message, some kind of per branch aggregation should occur.

So a bugzilla message could look like:

Pushed by [email protected] on the branch foo:
https://server/repo/rev/6e4e7985aba3
Foo
https://server/repoa/rev/1234567890ab
Bar

Pushed by [email protected] on the branch qux:
https://server/repoa/rev/234567890abc
Qux

Or some other variation where branches are not repeated. Typical pushes would only have something like the first half.


def __iter__(self):
return iter(self.changesets)
Expand Down Expand Up @@ -136,6 +139,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)
Expand All @@ -146,7 +151,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
Expand Down Expand Up @@ -242,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')
Expand Down Expand Up @@ -332,6 +360,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):
Expand Down Expand Up @@ -405,6 +438,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 {
Expand Down Expand Up @@ -598,6 +640,75 @@ 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 [email protected] 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 [email protected] on the branch foo:\n'
'https://server/repo/rev/6e4e7985aba3\n'
'Foo\n'
'https://server/repoa/rev/1234567890ab\n'
'Bar\n'
'\n'
'Pushed by [email protected] 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 [email protected] on the branch foo:\n'
'https://server/repo/rev/6e4e7985aba3\n'
'Foo\n'
'\n'
'Pushed by [email protected] on the default branch:\n'
'https://server/repoa/rev/1234567890ab\n'
'Bar\n'
'\n'
'Pushed by [email protected] 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({
Expand Down
87 changes: 87 additions & 0 deletions pulsebot/pulse_hgpushes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -242,3 +244,88 @@ def test_pushes_info(self):
'user': u'[email protected]'
}]
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': '[email protected]',
'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)