Skip to content

Commit

Permalink
Rework repo provider (#274)
Browse files Browse the repository at this point in the history
* Rework repo provider

- repo becomes organization
- align interfaces with organizations from mix hex
- added rebar3_ex_doc to project_plugins
- add initial docs for rebar3_hex_organization
- add basic supporting tests
  • Loading branch information
starbelly authored Dec 29, 2021
1 parent 4866def commit 4a8cb9a
Show file tree
Hide file tree
Showing 9 changed files with 622 additions and 166 deletions.
13 changes: 10 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
{erl_opts, [
debug_info,
{platform_define, "^2[3-9]", 'POST_OTP_22'},
{platform_define, "^23", 'OTP_23'},
{platform_define, "^20", 'POST_OTP_19'},
{platform_define, "^19", 'POST_OTP_18'},
{platform_define, "^[2-9]", 'POST_OTP_18'}
]}.

{project_plugins, [covertool, {rebar3_hank, "~> 0.3.0"}]}.
{project_plugins, [covertool, rebar3_ex_doc, {rebar3_hank, "~> 0.3.0"}]}.

{deps, [{hex_core, "0.8.4"}, {verl, "1.1.1"}]}.

Expand All @@ -25,8 +26,7 @@

{dialyzer, [
{warnings, [
error_handling,
underspecs
error_handling
]},
{plt_extra_apps, [hex_core, verl]}
]}.
Expand All @@ -39,3 +39,10 @@
deprecated_function_calls,deprecated_functions]}.

{alias, [{test, [{ct, "--cover"}, {cover, "-v"}]}]}.


{ex_doc, [
{source_url, <<"https://github.com/erlef/rebar3_hex">>},
{extras, [<<"README.md">>, <<"LICENSE">>]},
{main, <<"readme">>}
]}.
2 changes: 1 addition & 1 deletion src/rebar3_hex.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ init(State) ->
lists:foldl(fun provider_init/2, {ok, State}, [rebar3_hex_user,
rebar3_hex_cut,
rebar3_hex_owner,
rebar3_hex_repo,
rebar3_hex_organization,
rebar3_hex_search,
rebar3_hex_retire,
rebar3_hex_publish]).
Expand Down
17 changes: 14 additions & 3 deletions src/rebar3_hex_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
, hex_config_write/1
, hex_config_read/1
, repo/1
, repo/2
, update_auth_config/2
]).

Expand Down Expand Up @@ -127,9 +128,11 @@ repo(State, RepoName) ->
MaybeFound2 = get_repo(<<MaybeParentRepo/binary, BinName/binary>>, Repos),
case {MaybeFound1, MaybeFound2} of
{{ok, Repo1}, undefined} ->
{ok, set_http_adapter(merge_with_env(Repo1))};
Repo2 = set_http_adapter(merge_with_env(Repo1)),
{ok, maybe_set_api_organization(Repo2)};
{undefined, {ok, Repo2}} ->
{ok, set_http_adapter(merge_with_env(Repo2))};
Repo3 = set_http_adapter(merge_with_env(Repo2)),
{ok, maybe_set_api_organization(Repo3)};
{undefined, undefined} ->
{error, {not_valid_repo, RepoName}}
end.
Expand Down Expand Up @@ -210,7 +213,7 @@ hex_config_write(#{api_key := Key} = HexConfig) when is_binary(Key) ->
{ok, set_http_adapter(HexConfig)};
hex_config_write(#{write_key := undefined}) ->
{error, no_write_key};
hex_config_write(#{api_key := undefined, write_key := WriteKey, username := Username} = HexConfig) ->
hex_config_write(#{write_key := WriteKey, username := Username} = HexConfig) ->
DecryptedWriteKey = rebar3_hex_user:decrypt_write_key(Username, WriteKey),
{ok, set_http_adapter(HexConfig#{api_key => DecryptedWriteKey})};
hex_config_write(_) ->
Expand All @@ -220,3 +223,11 @@ hex_config_read(#{read_key := ReadKey} = HexConfig) ->
{ok, set_http_adapter(HexConfig#{api_key => ReadKey})};
hex_config_read(_Config) ->
{error, no_read_key}.

maybe_set_api_organization(#{name := Name} = Repo) ->
case binary:split(Name, <<":">>) of
[_] ->
Repo;
[_,Org] ->
Repo#{api_organization => Org}
end.
Loading

0 comments on commit 4a8cb9a

Please sign in to comment.