Skip to content

Commit 621f349

Browse files
committed
add [BERTE-525] Create bypass for specific user and add tests
1 parent 7d867d2 commit 621f349

10 files changed

Lines changed: 569 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [3.5.0] - 2021-04-27
5+
# Added
6+
- Add "pr_author_options" option to config, which add bypass to a specifique user
7+
48
## [3.4.2] - 2020-10-14
59
# Fixed
610
- CommandError "Command git log --no-merges --pretty=..." for delete src branch

bert_e/job.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ def __init__(self, pull_request, **kwargs):
138138
self.git.src_branch = None
139139
self.git.dst_branch = None
140140

141+
@property
142+
def active_options(self):
143+
return (super(PullRequestJob, self).active_options +
144+
[key for key, value in self.author_bypass.items() if value])
145+
146+
@property
147+
def author_bypass(self):
148+
return self.settings.pr_author_options.get(
149+
self.pull_request.author, {}
150+
)
151+
141152
@property
142153
def url(self):
143154
return self.bert_e.settings.pull_request_base_url.format(

bert_e/settings.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,45 @@ def output(self, data):
7979
return UserDict(data)
8080

8181

82+
class PrAuthorsOptions(fields.Dict):
83+
BYPASS_LIST = [
84+
'bypass_author_approval',
85+
'bypass_jira_check',
86+
'bypass_build_status',
87+
'bypass_commit_size',
88+
'bypass_incompatible_branch',
89+
'bypass_peer_approval',
90+
'bypass_leader_approval',
91+
]
92+
93+
def serialize(self, value, attr=None, obj=None):
94+
data = super(PrAuthorsOptions, self).serialize(value, attr, obj)
95+
res = dict()
96+
for user, values in data.items():
97+
res[user] = [key for key, value in data.items() if value]
98+
99+
return res
100+
101+
def deserialize(self, value, attr=None, data=None):
102+
data = super(PrAuthorsOptions, self).deserialize(value, attr, data)
103+
104+
found_elem = []
105+
res = dict()
106+
for user, bypass_list in data.items():
107+
for elem in bypass_list:
108+
if elem in self.BYPASS_LIST:
109+
found_elem.append(elem)
110+
else:
111+
raise IncorrectSettingsFile(
112+
f'This bypass does not exist: {elem}'
113+
)
114+
115+
res[user] = dict([
116+
(key, key in bypass_list) for key in self.BYPASS_LIST
117+
])
118+
return res
119+
120+
82121
class SettingsSchema(Schema):
83122
# Settings defined in config files
84123
always_create_integration_pull_requests = fields.Bool(missing=True)
@@ -100,6 +139,7 @@ class SettingsSchema(Schema):
100139
need_author_approval = fields.Bool(missing=True)
101140
required_leader_approvals = fields.Int(missing=0)
102141
required_peer_approvals = fields.Int(missing=2)
142+
pr_author_options = PrAuthorsOptions(missing={})
103143

104144
jira_account_url = fields.Str(missing='')
105145
jira_email = fields.Str(missing='')

0 commit comments

Comments
 (0)