Ver código fonte

append organization name to parent's repo_url when parsing repos

pull/1876/head
Tristan Sloughter 6 anos atrás
pai
commit
09013eb898
3 arquivos alterados com 34 adições e 14 exclusões
  1. +1
    -1
      src/rebar3.erl
  2. +20
    -4
      src/rebar_hex_repos.erl
  3. +13
    -9
      src/rebar_packages.erl

+ 1
- 1
src/rebar3.erl Ver arquivo

@ -194,7 +194,7 @@ init_config() ->
?DEBUG("Load global config file ~ts", [GlobalConfigFile]),
try state_from_global_config(Config1, GlobalConfigFile)
catch
_:_ ->
_:_->
?WARN("Global config ~ts exists but can not be read. Ignoring global config values.", [GlobalConfigFile]),
rebar_state:new(Config1)
end;

+ 20
- 4
src/rebar_hex_repos.erl Ver arquivo

@ -3,7 +3,8 @@
-export([from_state/2,
get_repo_config/2,
auth_config/1,
update_auth_config/2]).
update_auth_config/2,
format_error/1]).
-ifdef(TEST).
%% exported for test purposes
@ -11,6 +12,7 @@
-endif.
-include("rebar.hrl").
-include_lib("providers/include/providers.hrl").
-type repo() :: #{name => unicode:unicode_binary(),
api_url => binary(),
@ -32,7 +34,12 @@ from_state(BaseConfig, State) ->
-spec get_repo_config(unicode:unicode_binary(), rebar_state:t() | [hex_core:config()])
-> {ok, hex_core:config()} | error.
get_repo_config(RepoName, Repos) when is_list(Repos) ->
ec_lists:find(fun(#{name := N}) -> N =:= RepoName end, Repos);
case ec_lists:find(fun(#{name := N}) -> N =:= RepoName end, Repos) of
error ->
throw(?PRV_ERROR({repo_not_found, RepoName}));
{ok, RepoConfig} ->
{ok, RepoConfig}
end;
get_repo_config(RepoName, State) ->
Resources = rebar_state:resources(State),
#{repos := Repos} = rebar_resource:find_resource_state(pkg, Resources),
@ -73,9 +80,15 @@ merge_repos(Repos) ->
end, [], Repos).
update_organizations(Repos) ->
lists:map(fun(Repo=#{parent := ParentName}) ->
lists:map(fun(Repo=#{organization := Organization,
parent := ParentName}) ->
{ok, Parent} = get_repo_config(ParentName, Repos),
maps:merge(Parent, Repo);
ParentRepoUrl = rebar_utils:to_list(maps:get(repo_url, Parent)),
{ok, RepoUrl} =
rebar_utils:url_append_path(ParentRepoUrl,
filename:join("repos", rebar_utils:to_list(Organization))),
%% still let the organization config override this constructed repo url
maps:merge(Parent#{repo_url => rebar_utils:to_binary(RepoUrl)}, Repo);
(Repo) ->
Repo
end, Repos).
@ -98,6 +111,9 @@ repo_list([{repos, Repos} | T]) ->
repo_list([{repos, replace, Repos} | T]) ->
Repos ++ repo_list(T).
format_error({repo_not_found, RepoName}) ->
io_lib:format("The repo ~ts was not found in the configuration.", [RepoName]).
%% auth functions
%% authentication is in a separate config file because the hex plugin updates it

+ 13
- 9
src/rebar_packages.erl Ver arquivo

@ -36,7 +36,7 @@ format_error({missing_package, Pkg}) ->
io_lib:format("Package not found in any repo: ~p.", [Pkg]).
-spec get(hex_core:config(), binary()) -> {ok, map()} | {error, term()}.
get(Config, Name) ->
get(Config, Name) ->
try hex_api_package:get(Config, Name) of
{ok, {200, _Headers, PkgInfo}} ->
{ok, PkgInfo};
@ -266,12 +266,16 @@ parse_checksum(Checksum) ->
update_package(Name, RepoConfig=#{name := Repo}, State) ->
?MODULE:verify_table(State),
try hex_repo:get_package(RepoConfig, Name) of
try hex_repo:get_package(RepoConfig#{repo_key => maps:get(read_key, RepoConfig, <<>>)}, Name) of
{ok, {200, _Headers, #{releases := Releases}}} ->
_ = insert_releases(Name, Releases, Repo, ?PACKAGE_TABLE),
{ok, RegistryDir} = rebar_packages:registry_dir(State),
PackageIndex = filename:join(RegistryDir, ?INDEX_FILE),
ok = ets:tab2file(?PACKAGE_TABLE, PackageIndex);
{ok, {403, _Headers, <<>>}} ->
not_found;
{ok, {404, _Headers, _}} ->
not_found;
Error ->
?DEBUG("Hex get_package request failed: ~p", [Error]),
%% TODO: add better log message. hex_core should export a format_error
@ -308,11 +312,7 @@ resolve_version(Dep, DepVsn, Hash, HexRegistry, State) when is_binary(Hash) ->
%% allow retired packages when we have a checksum
case get_package(Dep, DepVsn, Hash, '_', RepoNames, HexRegistry, State) of
{ok, Package=#package{key={_, _, RepoName}}} ->
{ok, RepoConfig} = ec_lists:find(fun(#{name := N}) when N =:= RepoName ->
true;
(_) ->
false
end, RepoConfigs),
{ok, RepoConfig} = rebar_hex_repos:get_repo_config(RepoName, RepoConfigs),
{ok, Package, RepoConfig};
_ ->
Fun = fun(Repo) ->
@ -365,8 +365,12 @@ handle_missing_no_exception(Fun, Dep, State) ->
case check_all_repos(Fun, RepoConfigs) of
not_found ->
ec_lists:search(fun(Config=#{name := R}) ->
?MODULE:update_package(Dep, Config, State),
Fun(R)
case ?MODULE:update_package(Dep, Config, State) of
ok ->
Fun(R);
_ ->
not_found
end
end, RepoConfigs);
Result ->
Result

Carregando…
Cancelar
Salvar