Skip to content

Commit

Permalink
Merge pull request #5 from klarna-incubator/master
Browse files Browse the repository at this point in the history
sync with upstream
  • Loading branch information
Wingless-Archangel authored Oct 27, 2021
2 parents 9e1d2db + d6bf577 commit a3915ac
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions sample_repo_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ wz-pr-restrictions:
- branch-id: develop
approval-quota: 0 # The percentage of individuals reviewing a PR who must approve it before it can be merged
group-quota: 1 # Minimum number of approvals required per group
ignore-self-approve: true # Pull request code contributor approvals are not counted towards quotas

# Workzone Branch Reviewers
wz-branch-reviewers:
Expand Down
8 changes: 4 additions & 4 deletions src/bec_wz_branch_reviewer_t.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ from_map(#{ <<"refName">> := RefName

-spec to_map(reviewer()) -> map().
to_map(#{ 'branch-id' := BranchId
, users := Users
, groups := Groups
, paths := Paths
} = Map) ->
MUsers = maps:get('mandatory-users', Map, []),
MGroups = maps:get('mandatory-groups', Map, []),

Users = maps:get('users', Map, []),
Groups = maps:get('groups', Map, []),
Paths = maps:get('paths', Map, []),

#{ <<"refName">> => bec_wz_utils:add_prefix(BranchId)
, <<"users">> => [bec_wz_user_t:to_map(U) || U <- Users]
, <<"groups">> => Groups
Expand Down
46 changes: 26 additions & 20 deletions src/bec_wz_pr_restriction_t.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
%%==============================================================================
%% Types
%%==============================================================================
-type restriction() :: #{ 'branch-id' := bec_branch_t:id()
, 'approval-quota' := integer()
, 'group-quota' := integer()
-type restriction() :: #{ 'branch-id' := bec_branch_t:id()
, 'approval-quota' := integer()
, 'group-quota' := integer()
, 'ignore-self-approve' := boolean()
}.

%%==============================================================================
Expand All @@ -28,28 +29,33 @@
%% API
%%==============================================================================
-spec from_map(map()) -> restriction().
from_map(#{ <<"refName">> := RefName
, <<"approvalQuota">> := ApprovalQuota
, <<"groupQuota">> := GroupQuota
from_map(#{ <<"refName">> := RefName
, <<"approvalQuota">> := ApprovalQuota
, <<"groupQuota">> := GroupQuota
, <<"ignoreContributingReviewersApproval">> := IgnoreSelfApprove
}) ->
#{ 'branch-id' => bec_wz_utils:strip_prefix(RefName)
, 'approval-quota' => binary_to_integer(ApprovalQuota)
, 'group-quota' => GroupQuota
#{ 'branch-id' => bec_wz_utils:strip_prefix(RefName)
, 'approval-quota' => binary_to_integer(ApprovalQuota)
, 'group-quota' => GroupQuota
, 'ignore-self-approve' => IgnoreSelfApprove
}.

-spec to_map(restriction()) -> map().
to_map(#{ 'branch-id' := BranchId
, 'approval-quota' := ApprovalQuota
, 'group-quota' := GroupQuota
}) ->
#{ <<"approvalQuota">> => ApprovalQuota
, <<"approvalQuotaEnabled">> => true
, <<"automergeUsers">> => []
, <<"deleteSourceBranch">> => false
, <<"groupQuota">> => GroupQuota
, <<"refName">> => bec_wz_utils:add_prefix(BranchId)
, <<"requiredBuildsCount">> => <<>>
, <<"requiredSignaturesCount">> => <<>>
, <<"srcRefName">> => <<>>
, <<"watchBuildResult">> => false
} = Map) ->
IgnoreSelfApprove = maps:get('ignore-self-approve', Map, false),

#{ <<"approvalQuota">> => ApprovalQuota
, <<"approvalQuotaEnabled">> => true
, <<"automergeUsers">> => []
, <<"deleteSourceBranch">> => false
, <<"groupQuota">> => GroupQuota
, <<"refName">> => bec_wz_utils:add_prefix(BranchId)
, <<"requiredBuildsCount">> => <<>>
, <<"requiredSignaturesCount">> => <<>>
, <<"srcRefName">> => <<>>
, <<"watchBuildResult">> => false
, <<"ignoreContributingReviewersApproval">> => IgnoreSelfApprove
}.
11 changes: 6 additions & 5 deletions test/bec_proper_gen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ wz_pr_restrictions() ->
unique_list(wz_pr_restriction(), {map, 'branch-id'}).

wz_pr_restriction() ->
?LET( {BranchId, ApprovalQuota, GroupQuota}
, {branch_id(), non_zero_nat(), non_zero_nat()}
, #{ 'branch-id' => BranchId
, 'approval-quota' => ApprovalQuota
, 'group-quota' => GroupQuota
?LET( {BranchId, ApprovalQuota, GroupQuota, IgnoreSelfApprove}
, {branch_id(), non_zero_nat(), non_zero_nat(), bool()}
, #{ 'branch-id' => BranchId
, 'approval-quota' => ApprovalQuota
, 'group-quota' => GroupQuota
, 'ignore-self-approve' => IgnoreSelfApprove
}).

%%==============================================================================
Expand Down

0 comments on commit a3915ac

Please sign in to comment.