Current section

Files

Jump to
go_over src go_over@retired.erl
Raw

src/go_over@retired.erl

-module(go_over@retired).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([check_retired/2, print_ret/1]).
-spec path(go_over@packages:package()) -> binary().
path(Pkg) ->
_pipe = go_over@util@constants:go_over_path(),
_pipe@1 = filepath:join(_pipe, <<"deps"/utf8>>),
_pipe@2 = filepath:join(_pipe@1, erlang:element(2, Pkg)),
filepath:join(_pipe@2, erlang:element(4, Pkg)).
-spec filename(go_over@packages:package()) -> binary().
filename(Pkg) ->
_pipe = Pkg,
_pipe@1 = path(_pipe),
filepath:join(_pipe@1, <<"resp.json"/utf8>>).
-spec pull_retired(go_over@packages:package()) -> nil.
pull_retired(Pkg) ->
go_over@util@print:progress(
<<<<"Checking: "/utf8, (erlang:element(2, Pkg))/binary>>/binary,
" From hex.pm"/utf8>>
),
Request = begin
_pipe = gleam@http@request:to(
<<<<<<"https://hex.pm/api/packages/"/utf8,
(erlang:element(2, Pkg))/binary>>/binary,
"/releases/"/utf8>>/binary,
(erlang:element(4, Pkg))/binary>>
),
go_over@util@util:hard_fail(
_pipe,
<<<<"request to hex.pm for package: "/utf8,
(erlang:element(2, Pkg))/binary>>/binary,
" failed"/utf8>>
)
end,
Resp = begin
_pipe@1 = Request,
_pipe@2 = gleam@http@request:prepend_header(
_pipe@1,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@3 = gleam@hackney:send(_pipe@2),
go_over@util@util:hard_fail(
_pipe@3,
<<<<"request to hex.pm for package: "/utf8,
(erlang:element(2, Pkg))/binary>>/binary,
" failed"/utf8>>
)
end,
Pkg_path = path(Pkg),
Pkg_path_fail = <<<<<<"could not store hex.pm pkg info. package: "/utf8,
(erlang:element(2, Pkg))/binary>>/binary,
" at path "/utf8>>/binary,
Pkg_path/binary>>,
_pipe@4 = simplifile:create_directory_all(Pkg_path),
go_over@util@util:hard_fail(_pipe@4, Pkg_path_fail),
_pipe@5 = Pkg,
_pipe@6 = filename(_pipe@5),
_pipe@7 = simplifile:write(_pipe@6, erlang:element(4, Resp)),
go_over@util@util:hard_fail(_pipe@7, Pkg_path_fail),
nil.
-spec check_retired(go_over@packages:package(), boolean()) -> gleam@option:option(gleam@hexpm:release_retirement()).
check_retired(Pkg, Force_pull) ->
_pipe = Pkg,
_pipe@1 = path(_pipe),
go_over@util@cache:pull_if_not_cached(
_pipe@1,
3600,
Force_pull,
fun() ->
_ = simplifile:delete(path(Pkg)),
pull_retired(Pkg)
end,
<<<<(erlang:element(2, Pkg))/binary, ":"/utf8>>/binary,
(erlang:element(4, Pkg))/binary>>
),
Cached_file_name = filename(Pkg),
Resp = begin
_pipe@2 = Cached_file_name,
_pipe@3 = simplifile:read(_pipe@2),
go_over@util@util:hard_fail(
_pipe@3,
<<"failed to read "/utf8, Cached_file_name/binary>>
)
end,
Release = begin
_pipe@4 = gleam@json:decode(Resp, fun gleam@hexpm:decode_release/1),
go_over@util@util:hard_fail(
_pipe@4,
<<"failed to parse "/utf8, Cached_file_name/binary>>
)
end,
erlang:element(8, Release).
-spec print_ret(gleam@hexpm:release_retirement()) -> binary().
print_ret(Ret) ->
Reason = gleam@hexpm:retirement_reason_to_string(erlang:element(2, Ret)),
case erlang:element(3, Ret) of
{some, Msg} ->
<<<<Reason/binary, ": "/utf8>>/binary, Msg/binary>>;
_ ->
Reason
end.