From 47f0dffd57887fbaf2702def7e23b95281b3495c Mon Sep 17 00:00:00 2001 From: knucklessg1 Date: Tue, 7 May 2024 10:25:16 -0500 Subject: [PATCH] Fixed protected branch bool fields. --- gitlab_api/gitlab_models.py | 20 +++++++++++++++++++- test/test_gitlab_models.py | 5 ++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gitlab_api/gitlab_models.py b/gitlab_api/gitlab_models.py index 56f5051..24380da 100644 --- a/gitlab_api/gitlab_models.py +++ b/gitlab_api/gitlab_models.py @@ -1904,7 +1904,7 @@ class ProtectedBranchModel(BaseModel): push_access_level: Optional[int] = None merge_access_level: Optional[int] = None unprotect_access_level: Optional[int] = None - allow_force_push: Optional[List[str]] = None + allow_force_push: Optional[bool] = None allowed_to_push: Optional[List[Dict]] = None allowed_to_merge: Optional[List[Dict]] = None allowed_to_unprotect: Optional[List[Dict]] = None @@ -1960,6 +1960,24 @@ def build_api_parameters(cls, values): values['data'] = data return values + @field_validator('allow_force_push', 'code_owner_approval_required') + def validate_bool_fields(cls, v): + """ + Validate boolean fields to ensure they are valid boolean values. + + Args: + - v: The value of the field. + + Returns: + - bool: The validated field value. + + Raises: + - ValueError: If the field is provided and not a boolean. + """ + if v is not None and not isinstance(v, bool): + raise ValueError("Invalid states") + return v + @field_validator('project_id') def validate_project_id(cls, value): """ diff --git a/test/test_gitlab_models.py b/test/test_gitlab_models.py index 0de22a7..0e2f057 100644 --- a/test/test_gitlab_models.py +++ b/test/test_gitlab_models.py @@ -116,7 +116,10 @@ def test_project_model(): def test_protected_branches_model(): project_id = 5679 branch="test" - protected_branch = ProtectedBranchModel(project_id=project_id, branch=branch, + protected_branch = ProtectedBranchModel(project_id=project_id, + branch=branch, + allow_force_push=False, + code_owner_approval_required=False, allowed_to_push=[{"access_level": 40}], allowed_to_merge=[{"access_level": 20}], all_runners=True)