Skip to content

Commit

Permalink
Merge pull request #25 from pilucca/master
Browse files Browse the repository at this point in the history
Fix branch restriction sorting
  • Loading branch information
robertoaloi authored Feb 24, 2021
2 parents c4d6e0a + 540bf23 commit 96898a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions sample_repo_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pr-restrictions:
required-all-tasks-complete: true
required-approvers: 2
required-successful-builds: 1
unapprove-on-update: true
merge-config:
default-strategy: no-ff
enabled-strategies:
Expand Down
2 changes: 2 additions & 0 deletions src/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
5 changes: 5 additions & 0 deletions src/bec_pr_restriction_t.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
, 'required-all-tasks-complete' := boolean()
, 'required-approvers' := integer()
, 'required-successful-builds' := boolean()
, 'unapprove-on-update' := boolean()
}.

%%==============================================================================
Expand All @@ -35,12 +36,14 @@ from_map(#{ <<"mergeConfig">> := MergeConfig
, <<"requiredAllTasksComplete">> := RequiredAllTasksComplete
, <<"requiredApprovers">> := RequiresApprovers
, <<"requiredSuccessfulBuilds">> := RequiredSuccessfulBuilds
, <<"unapproveOnUpdate">> := UnapproveOnUpdate
}) ->
#{ 'merge-config' => bec_merge_config_t:from_map(MergeConfig)
, 'required-all-approvers' => RequiredAllApprovers
, 'required-all-tasks-complete' => RequiredAllTasksComplete
, 'required-approvers' => RequiresApprovers
, 'required-successful-builds' => RequiredSuccessfulBuilds
, 'unapprove-on-update' => UnapproveOnUpdate
}.

-spec to_map(restriction()) -> map().
Expand All @@ -49,10 +52,12 @@ to_map(#{ 'merge-config' := MergeConfig
, 'required-all-tasks-complete' := RequiredAllTasksComplete
, 'required-approvers' := RequiresApprovers
, 'required-successful-builds' := RequiredSuccessfulBuilds
, 'unapprove-on-update' := UnapproveOnUpdate
}) ->
#{ <<"mergeConfig">> => bec_merge_config_t:to_map(MergeConfig)
, <<"requiredAllApprovers">> => RequiredAllApprovers
, <<"requiredAllTasksComplete">> => RequiredAllTasksComplete
, <<"requiredApprovers">> => RequiresApprovers
, <<"requiredSuccessfulBuilds">> => RequiredSuccessfulBuilds
, <<"unapproveOnUpdate">> => UnapproveOnUpdate
}.
3 changes: 2 additions & 1 deletion src/bitbucket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ get_branch_restrictions(ProjectKey, RepoSlug) ->
case bitbucket_api:get_branch_restrictions(ProjectKey, RepoSlug) of
{ok, Response} ->
Values = maps:get(<<"values">>, Response),
{ok, lists:sort([bec_branch_restriction_t:from_map(V) || V <- Values])};
{ok, lists:sort([maps:remove(id, X) ||
X <- [bec_branch_restriction_t:from_map(V) || V <- Values]])};
{error, Reason} ->
{error, Reason}
end.
Expand Down

0 comments on commit 96898a2

Please sign in to comment.