-
Notifications
You must be signed in to change notification settings - Fork 0
/
force_push_denied.py
32 lines (21 loc) · 1.08 KB
/
force_push_denied.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from src.common.logger import info
from src.controls.control import Control, ControlResult
class ForcePushDeniedControl(Control):
def __init__(self, config: dict):
control_dict = config.get('gitlab').get('code_changes').get('force_push_denied')
enabled = control_dict.get('enabled')
super().__init__(enabled)
def get_name(self):
return "1.1.16 Ensure force push code to branches is denied (Manual)"
def validate_specific(self, gl_group_project, gl_project) -> ControlResult:
protected_branches = gl_project.protectedbranches.list(all=True)
if len(protected_branches) == 0:
return ControlResult(self.get_name(), False, f"Repository does not have protected branches!")
passed = True
more_info = ""
for branch in protected_branches:
allow_force_push = branch.allow_force_push
if allow_force_push:
passed = False
more_info += f"For branch: {branch.name} force pushed allowed\n"
return ControlResult(self.get_name(), passed, more_info)