Skip to content

Commit

Permalink
Fixed protected branch bool fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
Knucklessg1 committed May 7, 2024
1 parent 8a6a00b commit 47f0dff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 19 additions & 1 deletion gitlab_api/gitlab_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
5 changes: 4 additions & 1 deletion test/test_gitlab_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 47f0dff

Please sign in to comment.