Skip to content

Commit

Permalink
Control who gets notified by GerritStatusPush
Browse files Browse the repository at this point in the history
Allow the GerritStatusPush object to accept who to notify
as an argument. The notify argument is a string
which accepts values found in the gerrit documentation
for the --notify flag. The argument is set to None by
default to maintain current functionality.

Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
  • Loading branch information
dinatale2 committed Oct 12, 2016
1 parent f7be7bc commit 3945799
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
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.
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

0 comments on commit 3945799

Please sign in to comment.