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

Control who gets notified by GerritStatusPush #2411

Merged
merged 1 commit into from Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion master/buildbot/reporters/gerrit.py
Expand Up @@ -145,11 +145,12 @@ class GerritStatusPush(service.BuildbotService):
startArg = None
summaryCB = None
summaryArg = None
_gerrit_notify = None

def reconfigService(self, server, username, reviewCB=DEFAULT_REVIEW,
startCB=None, port=29418, reviewArg=None,
startArg=None, summaryCB=DEFAULT_SUMMARY, summaryArg=None,
identity_file=None, builders=None):
identity_file=None, builders=None, notify=None):

# If neither reviewCB nor summaryCB were specified, default to sending
# out "summary" reviews. But if we were given a reviewCB and only a
Expand All @@ -176,6 +177,7 @@ def reconfigService(self, server, username, reviewCB=DEFAULT_REVIEW,
self.summaryCB = summaryCB
self.summaryArg = summaryArg
self.builders = builders
self._gerrit_notify = notify

def _gerritCmd(self, *args):
'''Construct a command as a list of strings suitable for
Expand Down Expand Up @@ -398,6 +400,10 @@ def sendCodeReview(self, project, revision, result):
return

command = self._gerritCmd("review", "--project %s" % (project,))

if self._gerrit_notify is not None:
command.append('--notify %s' % str(self._gerrit_notify))

message = result.get('message', None)
if message:
command.append("--message '%s'" % message.replace("'", "\""))
Expand Down
20 changes: 20 additions & 0 deletions master/buildbot/test/unit/test_reporter_gerrit.py
Expand Up @@ -465,3 +465,23 @@ def testBuildGerritCommand(self):
'ssh',
['ssh', 'user@serv', '-p', '29418', 'gerrit', 'review', '--project project',
"--message 'bla'", '--verified 1', 'revision'])

# now test the notify argument, even though _gerrit_notify
# is private, work around that
gsp._gerrit_notify = 'OWNER'
gsp.processVersion('2.6', lambda: None)
spawnSkipFirstArg = Mock()
yield gsp.sendCodeReview('project', 'revision', {'message': 'bla', 'labels': {'Verified': 1}})
spawnSkipFirstArg.assert_called_once_with(
'ssh',
['ssh', 'user@serv', '-p', '29418', 'gerrit', 'review',
'--project project', '--notify OWNER', "--message 'bla'", '--label Verified=1', 'revision'])

# gerrit versions <= 2.5 uses other syntax
gsp.processVersion('2.4', lambda: None)
spawnSkipFirstArg = Mock()
yield gsp.sendCodeReview('project', 'revision', {'message': 'bla', 'labels': {'Verified': 1}})
spawnSkipFirstArg.assert_called_once_with(
'ssh',
['ssh', 'user@serv', '-p', '29418', 'gerrit', 'review', '--project project', '--notify OWNER',
"--message 'bla'", '--verified 1', 'revision'])
5 changes: 4 additions & 1 deletion master/docs/manual/cfg-reporters.rst
Expand Up @@ -665,7 +665,7 @@ GerritStatusPush
:class:`GerritStatusPush` sends review of the :class:`Change` back to the Gerrit server, optionally also sending a message when a build is started.
GerritStatusPush can send a separate review for each build that completes, or a single review summarizing the results for all of the builds.

.. py:class:: GerritStatusPush(server, username, reviewCB, startCB, port, reviewArg, startArg, summaryCB, summaryArg, identity_file, ...)
.. py:class:: GerritStatusPush(server, username, reviewCB, startCB, port, reviewArg, startArg, summaryCB, summaryArg, identity_file, builders, notify...)

:param string server: Gerrit SSH server's address to use for push event notifications.
:param string username: Gerrit SSH server's username.
Expand Down Expand Up @@ -738,6 +738,9 @@ GerritStatusPush can send a separate review for each build that completes, or a
:param builders: (optional) list of builders to send results for.
This method allows to filter results for a specific set of builder.
By default, or if builders is None, then no filtering is performed.
:param notify: (optional) control who gets notified by Gerrit once the status is posted.
Copy link
Member

Choose a reason for hiding this comment

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

I think this would deserve to document which values are possible, probably point on the gerrit documentation, explaining that this correspond to the --notify values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

The possible values for `notify` can be found in your version of the
Gerrit documentation for the `gerrit review` command.

.. note::

Expand Down
2 changes: 2 additions & 0 deletions master/docs/relnotes/index.rst
Expand Up @@ -51,6 +51,8 @@ Features

* Optimization of the data api filtering, sorting and paging, speeding up a lot the UI when the master has lots of builds.

* :bb:reporter:`GerritStatusPush` now accepts a ``notify`` parameter to control who gets emailed by Gerrit.

Fixes
~~~~~

Expand Down