Skip to content

Commit

Permalink
Merge pull request #7606 from mokibit/remove-BaseScheduler-compatibil…
Browse files Browse the repository at this point in the history
…ity-code

Remove compatibility code for BaseScheduler change_filter
  • Loading branch information
p12tic committed May 14, 2024
2 parents f9a2008 + 54e0906 commit 73d3ac6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 59 deletions.
43 changes: 2 additions & 41 deletions master/buildbot/schedulers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#
# Copyright Buildbot Team Members

import copy

from twisted.internet import defer
from twisted.python import failure
from twisted.python import log
Expand All @@ -26,7 +24,6 @@
from buildbot.process.properties import Properties
from buildbot.util.service import ClusteredBuildbotService
from buildbot.util.state import StateMixin
from buildbot.warnings import warn_deprecated


@implementer(interfaces.IScheduler)
Expand Down Expand Up @@ -209,44 +206,8 @@ def _changeCallback(self, key, msg, fileIsImportant, change_filter, onlyImportan
change = yield changes.Change.fromChdict(self.master, chdict)

# filter it
if change_filter:
# There has been a change in how Gerrit handles branches in Buildbot 3.5 - ref-updated
# events will now emit proper branch instead of refs/heads/<branch>. Below we detect
# whether this breaks change filters.
change_filter_may_be_broken = (
change.category == 'ref-updated' and not change.branch.startswith('refs/')
)

if change_filter_may_be_broken:
old_change = copy.deepcopy(change)
old_change.branch = f'refs/heads/{old_change.branch}'

old_filter_result = change_filter.filter_change(old_change)
new_filter_result = change_filter.filter_change(change)

def has_deprecated_ref_branch_filter():
for filter in change_filter.filters:
if filter.prop == 'branch':
if 'refs/heads/' in filter.describe():
return True

return False

if old_filter_result != new_filter_result and has_deprecated_ref_branch_filter():
warn_deprecated(
'3.5.0',
'Change filters must not expect ref-updated events from '
'Gerrit to include refs/heads prefix for the branch attr.',
)

if not old_filter_result:
return
else:
if not new_filter_result:
return
else:
if not change_filter.filter_change(change):
return
if change_filter and not change_filter.filter_change(change):
return

if change.codebase not in self.codebases:
log.msg(
Expand Down
18 changes: 0 additions & 18 deletions master/buildbot/test/unit/schedulers/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from unittest import mock

from parameterized import parameterized
from twisted.internet import defer
from twisted.internet import task
from twisted.trial import unittest
Expand All @@ -29,8 +28,6 @@
from buildbot.test import fakedb
from buildbot.test.reactor import TestReactorMixin
from buildbot.test.util import scheduler
from buildbot.test.util.warnings import assertProducesWarning
from buildbot.warnings import DeprecatedApiWarning


class BaseScheduler(scheduler.SchedulerMixin, TestReactorMixin, unittest.TestCase):
Expand Down Expand Up @@ -244,21 +241,6 @@ def test_change_consumption_change_filter_gerrit_ref_updates_with_refs(self):
change_kwargs={'category': 'ref-updated', 'branch': 'refs/changes/123'},
)

@parameterized.expand([
("branch", filter.ChangeFilter(branch='refs/heads/master'), True),
("branch_re", filter.ChangeFilter(branch_re='refs/heads/master'), True),
("branch_re_no_match", filter.ChangeFilter(branch_re='(refs/heads/other|master)'), None),
])
def test_change_consumption_refs_heads_branch_deprecated(self, name, cf, expected_result):
with assertProducesWarning(
DeprecatedApiWarning, "Change filters must not expect ref-updated events"
):
return self.do_test_change_consumption(
{'change_filter': cf},
expected_result,
change_kwargs={'category': 'ref-updated', 'branch': 'master'},
)

def test_change_consumption_change_filter_gerrit_filters_branch_new(self):
cf = filter.ChangeFilter(branch='master')
return self.do_test_change_consumption(
Expand Down

0 comments on commit 73d3ac6

Please sign in to comment.