Skip to content

Commit

Permalink
Add recommendation when retiring and require --message flag (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj authored Nov 8, 2018
1 parent 119f23f commit e889c7a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/mix/tasks/hex.retire.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Mix.Tasks.Hex.Retire do
## Command line options
* `--message "MESSAGE"` - Optional message (up to 140 characters) clarifying
* `--message "MESSAGE"` - Required message (up to 140 characters) clarifying
the retirement reason
* `--organization ORGANIZATION` - The organization the package belongs to
"""
Expand Down Expand Up @@ -61,10 +61,19 @@ defmodule Mix.Tasks.Hex.Retire do

defp retire(organization, package, version, reason, opts) do
auth = Mix.Tasks.Hex.auth_info(:write)
body = %{reason: reason, message: opts[:message]}
body = %{reason: reason, message: message_option(opts[:message])}

case Hex.API.Release.retire(organization, package, version, body, auth) do
{:ok, {code, _body, _headers}} when code in 200..299 ->
Hex.Shell.info("#{package} #{version} has been retired\n")

Hex.Shell.warn(
"Retiring a version does not affect if the version will still be resolved. " <>
"We recommend that you publish a new version of this package, unless there is " <>
"already a more recent patch version of this package, because this version may " <>
"still be picked by dependency resolution."
)

:ok

other ->
Expand All @@ -78,11 +87,20 @@ defmodule Mix.Tasks.Hex.Retire do

case Hex.API.Release.unretire(organization, package, version, auth) do
{:ok, {code, _body, _headers}} when code in 200..299 ->
Hex.Shell.info("#{package} #{version} has been unretired")
:ok

other ->
Hex.Shell.error("Unretiring package failed")
Hex.Utils.print_error_result(other)
end
end

defp message_option(nil) do
Mix.raise("Missing required flag --message")
end

defp message_option(message) do
message
end
end
13 changes: 13 additions & 0 deletions test/mix/tasks/hex.retire_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ defmodule Mix.Tasks.Hex.RetireTest do
assert {:ok, {200, %{"retirement" => nil}, _}} =
Hex.API.Release.get("hexpm", "retire_package", "0.0.1")
end

test "retire --message flag is required" do
auth = Hexpm.new_user("retire_user_message", "[email protected]", "passpass", "key")
Hexpm.new_package("retire_package_message", "0.0.1", [], %{}, auth)

Hex.State.put(:home, tmp_path())
Mix.Tasks.Hex.update_keys(auth[:"$write_key"], auth[:"$read_key"])
send(self(), {:mix_shell_input, :prompt, "passpass"})

assert_raise Mix.Error, "Missing required flag --message", fn ->
Mix.Tasks.Hex.Retire.run(["retire_package", "0.0.1", "renamed"])
end
end
end

0 comments on commit e889c7a

Please sign in to comment.