mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-03 23:14:02 -07:00
gitlab_protected_branch: refactor, add allow_force_push
, code_owner_approval_required
(#10795)
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.16) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.16) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled
* gitlab_protected_branch: fix typo * gitlab_protected_branch: lump parameters into options dictionary Hardcoding parameter lists gets repetitive. Refactor this module to use an options dictionary like many other gitlab_* modules. This makes it cleaner to add new options. * gitlab_protected_branch: update when possible Until now, the module deletes and re-creates the protected branch if any change is detected. This makes sense for the access level parameters, as these are not easily mutated after creation. However, in order to add further options which _can_ easily be updated, we should support updating by default, unless known-immutable parameters are changing. * gitlab_protected_branch: add `allow_force_push` option * gitlab_protected_branch: add `code_owner_approval_required` option * gitlab_protected_branch: add issues to changelog * Update changelog. --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
efb0c487f6
commit
f772bcda88
3 changed files with 99 additions and 35 deletions
|
@ -47,6 +47,12 @@ except ImportError:
|
|||
with_httmock = _dummy
|
||||
|
||||
|
||||
class MockProtectedBranch():
|
||||
def __init__(self, merge_access_levels, push_access_levels):
|
||||
self.merge_access_levels = merge_access_levels
|
||||
self.push_access_levels = push_access_levels
|
||||
|
||||
|
||||
class TestGitlabProtectedBranch(GitlabModuleTestCase):
|
||||
@with_httmock(resp_get_project_by_name)
|
||||
@with_httmock(resp_get_user)
|
||||
|
@ -66,14 +72,40 @@ class TestGitlabProtectedBranch(GitlabModuleTestCase):
|
|||
rvalue = self.moduleUtil.protected_branch_exist(name="master")
|
||||
self.assertEqual(rvalue, False)
|
||||
|
||||
@with_httmock(resp_get_protected_branch)
|
||||
def test_compare_protected_branch(self):
|
||||
rvalue = self.moduleUtil.compare_protected_branch(name="master", merge_access_levels="maintainer", push_access_level="maintainer")
|
||||
def test_can_update_zero_delta(self):
|
||||
protected_branch = MockProtectedBranch(
|
||||
merge_access_levels=[{"access_level": 40}],
|
||||
push_access_levels=[{"access_level": 40}],
|
||||
)
|
||||
options = {
|
||||
"merge_access_levels": 40,
|
||||
"push_access_level": 40
|
||||
}
|
||||
rvalue = self.moduleUtil.can_update(protected_branch, options)
|
||||
self.assertEqual(rvalue, True)
|
||||
|
||||
@with_httmock(resp_get_protected_branch)
|
||||
def test_compare_protected_branch_different_settings(self):
|
||||
rvalue = self.moduleUtil.compare_protected_branch(name="master", merge_access_levels="developer", push_access_level="maintainer")
|
||||
def test_can_update_no_configured(self):
|
||||
protected_branch = MockProtectedBranch(
|
||||
merge_access_levels=[{"access_level": 40}],
|
||||
push_access_levels=[{"access_level": 40}],
|
||||
)
|
||||
options = {
|
||||
"merge_access_levels": None,
|
||||
"push_access_level": None
|
||||
}
|
||||
rvalue = self.moduleUtil.can_update(protected_branch, options)
|
||||
self.assertEqual(rvalue, True)
|
||||
|
||||
def test_can_update_different_settings(self):
|
||||
protected_branch = MockProtectedBranch(
|
||||
merge_access_levels=[{"access_level": 40}],
|
||||
push_access_levels=[{"access_level": 40}],
|
||||
)
|
||||
options = {
|
||||
"merge_access_levels": 40,
|
||||
"push_access_level": 30
|
||||
}
|
||||
rvalue = self.moduleUtil.can_update(protected_branch, options)
|
||||
self.assertEqual(rvalue, False)
|
||||
|
||||
@with_httmock(resp_get_protected_branch)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue