Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle lowercase project ids #59

Merged
merged 4 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bitbucket_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ do_request(Method, Url, Body) ->
Type = "application/json",
Request = {Url, Headers, Type, Body},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put _Body here so that warning_as_errors won't cause compilation to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but for some weird reason, rebar.config uses fail_on_warning, which I thinks is not a valid option.

{erl_opts             , [fail_on_warning, debug_info]}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But Body is actually a function argument, so this is not a problem.

ok = ?LOG_DEBUG("HTTP Request: (~p) ~p~n~p~n",
[Method, Url, Headers, Body]),
[Method, Url, Headers]),
do_http_request(Method, Request).

-spec do_http_request(method(), request()) ->
Expand Down
12 changes: 10 additions & 2 deletions src/bitbucket_repo_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ read_template(TemplatePath, Variables) ->
render(String, Ctx) ->
mustache:render(String, Ctx).

%% Convert a binary to upper-case.
-spec binary_to_upper(Bin :: binary()) -> binary().
binary_to_upper(Bin) ->
list_to_binary(string:to_upper(binary_to_list(Bin))).

-spec do_verify(opts(), map()) -> boolean().
do_verify(Options, Config) ->
Project = maps:get(<<"project">>, Config),
Expand All @@ -90,7 +95,10 @@ do_verify(Options, Config) ->
{_, undefined} -> {error, missing_repo};
{_, _} ->
NewConfig = remove_global_config(Config),
do_verify(Project, Repo, NewConfig, Enforce, AbortOnError)
%% Project key must be upper-case, or some pluging
%% (e.g. Workzone) may get confused.
do_verify(binary_to_upper(Project), Repo, NewConfig, Enforce,
AbortOnError)
end.

-spec do_verify(binary(), binary(), map(), boolean(), boolean()) -> boolean().
Expand Down Expand Up @@ -182,7 +190,7 @@ do_verify(ProjectKey, RepoSlug, Key, Expected) ->
equals(<<"branch-restrictions">>, Actual, Expected) ->
Expected == [maps:remove(id, X) || X <- Actual];
equals(<<"access-keys">>, Actual, Expected) ->
Expected == [maps:remove(id, X) || X <- Actual];
lists:sort(Expected) == lists:sort([maps:remove(id, X) || X <- Actual]);
equals(<<"hooks">>, Actual, Expected) ->
F = fun(Hook) -> lists:member(Hook, Actual) end,
lists:all(F, Expected);
Expand Down
5 changes: 5 additions & 0 deletions test/bec_test_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

-export([ init_bitbucket/0
, init_logging/0
, flush_logging/0
, is_wz_supported/0

, bitbucket_server_url/0
Expand Down Expand Up @@ -158,6 +159,10 @@ maybe_add_file_handler() ->
level => all})
end.

flush_logging() ->
logger_std_h:filesync(default),
logger_std_h:filesync(file_handler).

is_wz_supported() ->
try
{ok, _} = bitbucket:get_wz_branch_reviewers(<<"TOOLS">>, <<"bec-test">>),
Expand Down
1 change: 1 addition & 0 deletions test/prop_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ setup() ->
%% Teardown
%%==============================================================================
teardown(#{started := Started}) ->
bec_test_utils:flush_logging(),
[application:stop(App) || App <- Started],
ok.

Expand Down
29 changes: 19 additions & 10 deletions test/prop_yml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@
%% The property
%%==============================================================================
prop_yml() ->
setup(),
?FORALL( Config
, bec_proper_gen:config()
, begin
Path = "/tmp/test.yml",
file:write_file(Path, bec_yml:encode(Config)),
bitbucket_repo_config:verify(Path, [{enforce, true}]),
bitbucket_repo_config:verify(Path)
end
).
?SETUP(
fun() ->
setup(),
fun cleanup/0
end,
?WHENFAIL(
fun cleanup/0,
?FORALL( Config
, bec_proper_gen:config()
, begin
Path = "/tmp/test.yml",
file:write_file(Path, bec_yml:encode(Config)),
bitbucket_repo_config:verify(Path, [{enforce, true}]),
bitbucket_repo_config:verify(Path)
end
))).

cleanup() ->
bec_test_utils:flush_logging().

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