Skip to content

Commit

Permalink
Fix organization owner prompt during publish (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj authored Nov 22, 2022
1 parent f5239cd commit d78a23f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mix/tasks/hex.publish.ex
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ defmodule Mix.Tasks.Hex.Publish do
end)

Hex.Shell.info("")
owner_prompt_selection(MapSet.new(organizations))
owner_prompt_selection(Map.new(organizations))
end

defp owner_prompt_selection(organizations) do
Expand Down
30 changes: 30 additions & 0 deletions test/mix/tasks/hex.publish_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,36 @@ defmodule Mix.Tasks.Hex.PublishTest do
purge([ReleaseMeta.MixProject])
end

test "create with organization prompt" do
Process.put(:hex_test_app_name, :publish_with_organization_prompt)
Mix.Project.push(ReleaseSimple.MixProject)

in_tmp(fn ->
set_home_tmp()
setup_auth("user", "hunter42")
File.write!("myfile.txt", "hello")

send(self(), {:mix_shell_input, :prompt, "2"})
send(self(), {:mix_shell_input, :yes?, true})
send(self(), {:mix_shell_input, :prompt, "hunter42"})

Mix.Tasks.Hex.Publish.run(["package", "--no-progress", "--replace"])

assert_received {:mix_shell, :info,
["You are a member of one or multiple organizations. " <> _]}

assert_received {:mix_shell, :info, ["Publishing package using http://" <> _]}
assert_received {:mix_shell, :info, ["Transferring ownership to testorg..."]}

assert {:ok, {200, body, _headers}} =
Hex.API.Package.get("hexpm", "publish_with_organization_prompt")

assert "testorg" in Enum.map(body["owners"], & &1["username"])
end)
after
purge([ReleaseSimple.MixProject])
end

test "create package with :organization config" do
Process.put(:hex_test_app_name, :publish_with_org_config)
Mix.Project.push(ReleaseRepo.MixProject)
Expand Down
2 changes: 1 addition & 1 deletion test/support/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ defmodule HexTest.Case do
|> Plug.Conn.resp(201, Hex.Utils.safe_serialize_erlang(body))

%Plug.Conn{method: "GET", request_path: "/api/users/me"} ->
body = %{"organizations" => %{}}
body = %{"organizations" => [%{"name" => repo}]}

conn
|> Plug.Conn.put_resp_header("content-type", "application/vnd.hex+erlang")
Expand Down

0 comments on commit d78a23f

Please sign in to comment.