From 54e2f218d68bc048c9c8d0b59add937534399ced Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 2 Dec 2020 12:23:14 +0000 Subject: [PATCH] Skip notifications about WIP changes WIP changes are likely to spam irc channels as they are not even visible by default in dashboards. If we detect the WIP flag as present and set to true, we just skip doing anything about that message. Change-Id: Id4ee6c825e6d508c0c722d01ac8b1147b4025dbe --- gerritbot/bot.py | 8 +++++++- gerritbot/tests/unit/test_bot.py | 8 ++++++++ tox.ini | 10 ++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gerritbot/bot.py b/gerritbot/bot.py index 774c3c1..aec86c2 100755 --- a/gerritbot/bot.py +++ b/gerritbot/bot.py @@ -301,9 +301,15 @@ class Gerrit(threading.Thread): return ret def _read(self, data): + # We skip notifications abour WIP changes + if 'change' in data and data['change'].get('wip', False): + self.log.debug('Skipped processing event on WIP change: %s', data) + return try: # We only consider event (not project/branch) filters for these. - event_only_types = ('ref-updated',) + # 'wip-state-changed' is included in order to notify when a change + # moves from wip to non-wip. + event_only_types = ('ref-updated', 'wip-state-changed') if data['type'] in event_only_types: channel_set = self._channels_for('events', data['type']) else: diff --git a/gerritbot/tests/unit/test_bot.py b/gerritbot/tests/unit/test_bot.py index c57fd20..42850ed 100644 --- a/gerritbot/tests/unit/test_bot.py +++ b/gerritbot/tests/unit/test_bot.py @@ -12,6 +12,7 @@ # under the License. import collections +import copy import testtools import yaml @@ -139,6 +140,9 @@ class GerritTestCase(testtools.TestCase): } + self.sample_data_wip = copy.deepcopy(self.sample_data) + self.sample_data_wip['change']['wip'] = True + def _validate_patchset_created(self): self.assertEqual(1, len(self.ircbot.messages)) message = self.ircbot.messages[0] @@ -171,6 +175,10 @@ class GerritTestCase(testtools.TestCase): self.gerrit._read(dict(self.sample_data, type='ref-updated')) self._validate_ref_updated() + def test__read_ref_updated_wip(self): + self.gerrit._read(dict(self.sample_data_wip, type='ref-updated')) + self.assertEqual(0, len(self.ircbot.messages)) + def _validate_change_merged(self): self.assertEqual(1, len(self.ircbot.messages)) message = self.ircbot.messages[0] diff --git a/tox.ini b/tox.ini index 818e9db..8f9c187 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,8 @@ [tox] -envlist = py37,pep8 +envlist = + pep8 + py3 + py3-{devel} [testenv] usedevelop = True @@ -11,7 +14,10 @@ setenv = VIRTUAL_ENV={envdir} LC_ALL=en_US.UTF-8 PYTHONWARNINGS=default::DeprecationWarning TESTS_DIR=./gerritbot/tests/unit/ -deps = -r{toxinidir}/test-requirements.txt +deps = + -r{toxinidir}/test-requirements.txt + devel: git+https://opendev.org/opendev/gerritlib.git@master#egg=gerritlib + whitelist_externals = rm commands = rm -f .testrepository/times.dbm