-
Notifications
You must be signed in to change notification settings - Fork 10
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
KwanEsq
wants to merge
4
commits into
mozilla-conduit:master
Choose a base branch
from
KwanEsq:branches
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import unittest | ||
from collections import ( | ||
defaultdict, | ||
OrderedDict, | ||
) | ||
from Queue import Queue, Empty | ||
from pulsebot.bugzilla import ( | ||
|
@@ -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'] | ||
|
||
def __iter__(self): | ||
return iter(self.changesets) | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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') | ||
|
@@ -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): | ||
|
@@ -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 { | ||
|
@@ -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({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'[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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
Or some other variation where branches are not repeated. Typical pushes would only have something like the first half.