From bf9505d190f947737f3996a802214fb5f9902c52 Mon Sep 17 00:00:00 2001 From: Ben Kuhar Date: Wed, 11 Jan 2023 15:54:48 -0500 Subject: [PATCH 1/4] Adding not none check when fetching access level to properly handle 0 --- gitlabform/processors/util/branch_protector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlabform/processors/util/branch_protector.py b/gitlabform/processors/util/branch_protector.py index 507cb46d7..3eaec74b5 100644 --- a/gitlabform/processors/util/branch_protector.py +++ b/gitlabform/processors/util/branch_protector.py @@ -277,7 +277,7 @@ def get_current_permissions(self, protected_branches_response, action): for array_element in protected_branches_response.get( f"{action}_access_levels", [] ): - if array_element.get("access_level"): + if array_element.get("access_level") is not None: levels.add(array_element.get("access_level")) elif array_element.get("user_id"): user_ids.add(array_element.get("user_id")) From 3abfbf09f21e94178afdc5d41a6b518393470918 Mon Sep 17 00:00:00 2001 From: Ben Kuhar Date: Thu, 12 Jan 2023 17:02:20 -0500 Subject: [PATCH 2/4] Adding unit test for get current permissions access level fetching --- .../unit/processors/test_branch_protector.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/unit/processors/test_branch_protector.py diff --git a/tests/unit/processors/test_branch_protector.py b/tests/unit/processors/test_branch_protector.py new file mode 100644 index 000000000..1a3bd0fea --- /dev/null +++ b/tests/unit/processors/test_branch_protector.py @@ -0,0 +1,27 @@ +from gitlabform.processors.util.branch_protector import BranchProtector + + +def test_get_current_permissions_handles_zero_access_level(): + bp = BranchProtector(None, False) + test_protected_branches_response = { + "id": 1, + "name": "master", + "push_access_levels": [ + {"access_level": 0, "access_level_description": "Push Description"} + ], + "merge_access_levels": [ + {"access_level": 40, "access_level_description": "Merge Description"} + ], + "allow_force_push": False, + "code_owner_approval_required": False, + } + + push_levels, _, _ = bp.get_current_permissions( + test_protected_branches_response, "push" + ) + assert push_levels == [0] + + merge_levels, _, _ = bp.get_current_permissions( + test_protected_branches_response, "merge" + ) + assert merge_levels == [40] From 1fca4ec003601a2ecd7cbc6de1b2ca748a448144 Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Fri, 13 Jan 2023 21:00:42 +0000 Subject: [PATCH 3/4] Prepare changelog for 3.3.4 --- docs/changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index aefcccf3a..4aa2dcaa4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 3.3.4 + +* Fix unnecessary reapply of branch protection when `*_access_levels` is set to `0`. PR [#474](https://github.com/gitlabform/gitlabform/pull/474) + +Thanks to [Ben Kuhar](https://github.com/BenKuhar) for his contribution! + ## 3.3.3 * Fix bug on the first run when both adding project members and the same users as merge request approvers. Fixes [#461](https://github.com/gitlabform/gitlabform/issues/461). From 1f0683fec9ed48e025bbe471afddc3397e364b65 Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Fri, 13 Jan 2023 21:08:01 +0000 Subject: [PATCH 4/4] Bump to 3.3.4 --- tbump.toml | 2 +- version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tbump.toml b/tbump.toml index d8e364141..521cd3dc7 100644 --- a/tbump.toml +++ b/tbump.toml @@ -2,7 +2,7 @@ github_url = "https://github.com/gitlabform/gitlabform/" [version] -current = "3.3.3" +current = "3.3.4" # Example of a semver regexp. # Make sure this matches current_version before diff --git a/version b/version index 619b53766..a0891f563 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.3.3 +3.3.4