Merge "Don't update protected flag if unprotected"
This commit is contained in:
@@ -2069,6 +2069,43 @@ class TestGithubUnprotectedBranches(ZuulTestCase):
|
||||
self.waitUntilSettled()
|
||||
cache_mock.assert_not_called()
|
||||
|
||||
def test_push_event_unprotected_branch_cache_update(self):
|
||||
# Test that we do not update the branch cache for events on
|
||||
# unprotected branches when exclude-unprotected-branches is
|
||||
# configured.
|
||||
self.create_branch('org/project2', 'feature')
|
||||
github = self.fake_github.getGithubClient()
|
||||
repo = github.repo_from_project('org/project2')
|
||||
repo._set_branch_protection('master', True)
|
||||
repo._create_branch('feature')
|
||||
|
||||
with (mock.patch(
|
||||
"zuul.zk.branch_cache_new.BranchCacheNew.setProtected")
|
||||
as cache_mock):
|
||||
self.fake_github.emitEvent(
|
||||
self.fake_github.getPushEvent(
|
||||
'org/project2',
|
||||
ref='refs/heads/feature'))
|
||||
self.waitUntilSettled()
|
||||
cache_mock.assert_not_called()
|
||||
|
||||
def test_push_event_protected_branch_cache_update(self):
|
||||
# Test that we do not update the branch cache for events on
|
||||
# protected branches when the protected state did not change.
|
||||
github = self.fake_github.getGithubClient()
|
||||
repo = github.repo_from_project('org/project2')
|
||||
repo._set_branch_protection('master', True)
|
||||
|
||||
with (mock.patch(
|
||||
"zuul.zk.branch_cache_new.BranchCacheNew.setProtected")
|
||||
as cache_mock):
|
||||
self.fake_github.emitEvent(
|
||||
self.fake_github.getPushEvent(
|
||||
'org/project2',
|
||||
ref='refs/heads/master'))
|
||||
self.waitUntilSettled()
|
||||
cache_mock.assert_not_called()
|
||||
|
||||
def _test_push_event_reconfigure(self, project, branch,
|
||||
expect_reconfigure=False,
|
||||
old_sha=None, new_sha=None,
|
||||
|
||||
@@ -526,8 +526,15 @@ class ZKBranchCacheMixin:
|
||||
project_name, required_flags, default=None)
|
||||
|
||||
if branches is not None:
|
||||
if ((branch_info := branches.get(event.branch)) is None or
|
||||
branch_info.protected != protected):
|
||||
if (
|
||||
# We have information about that branch and the
|
||||
# protected state changed ...
|
||||
((branch_info := branches.get(event.branch))
|
||||
and branch_info.protected != protected)
|
||||
# ... OR we don't have any branch info, but the
|
||||
# branch is now protected
|
||||
or (branch_info is None and protected)
|
||||
):
|
||||
log = get_annotated_logger(self.log, event)
|
||||
log.info("Project %s branch %s protected state "
|
||||
"changed to %s",
|
||||
|
||||
Reference in New Issue
Block a user