From b04d99a0be96c0d38946b3a4d259b2a08df9e6ab Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 15 May 2019 14:20:11 +0300 Subject: [PATCH 1/5] Default value for release link --- .../lib/block_scout_web/views/layout_view.ex | 13 ++++++++----- .../test/block_scout_web/views/layout_view_test.exs | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex index 7a454a0e72..8698dc7a7b 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex @@ -144,11 +144,14 @@ defmodule BlockScoutWeb.LayoutView do def release_link(version) do release_link = Application.get_env(:block_scout_web, :release_link) - if release_link == "" || release_link == nil do - version - else - html_escape({:safe, "#{version}"}) - end + release_link = + if release_link == "" || release_link == nil do + "https://github.com/poanetwork/blockscout/releases/tag/" <> version + else + release_link + end + + html_escape({:safe, "#{version}"}) end def ignore_version?("unknown"), do: true diff --git a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs index 5e3302ceec..5a934c20be 100644 --- a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs @@ -65,13 +65,15 @@ defmodule BlockScoutWeb.LayoutViewTest do test "use the version when there is no release_link env configured for it" do Application.put_env(:block_scout_web, :release_link, nil) - assert LayoutView.release_link("1.3.4") == "1.3.4" + assert LayoutView.release_link("1.3.4") == {:safe, + ~s(1.3.4)} end test "use the version when empty release_link env configured for it" do Application.put_env(:block_scout_web, :release_link, "") - assert LayoutView.release_link("1.3.4") == "1.3.4" + assert LayoutView.release_link("1.3.4") == {:safe, + ~s(1.3.4)} end test "use the enviroment release link when it's configured" do From b2a3e7d59d8218209bde75048da12b34c67bb38d Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 15 May 2019 14:33:24 +0300 Subject: [PATCH 2/5] Fix various tests --- .dialyzer-ignore | 2 +- .../lib/block_scout_web/views/layout_view.ex | 6 +++--- .../test/block_scout_web/views/layout_view_test.exs | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.dialyzer-ignore b/.dialyzer-ignore index 11bb3be729..e6b6ee70a7 100644 --- a/.dialyzer-ignore +++ b/.dialyzer-ignore @@ -4,4 +4,4 @@ apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex:400: Function timestamp_to_datetime/1 has no local return apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: Function microseconds_time/1 has no local return apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: The call 'Elixir.System':convert_time_unit(__@1::any(),'native','microseconds') breaks the contract (integer(),time_unit() | 'native',time_unit() | 'native') -> integer() -apps/block_scout_web/lib/block_scout_web/views/layout_view.ex:162: The call 'Elixir.Poison.Parser':'parse!'(any(),#{'keys':='atoms!'}) will never return since the success typing is (binary() | maybe_improper_list(binary() | maybe_improper_list(any(),binary() | []) | byte(),binary() | []),[{atom(),_}]) -> 'false' | 'nil' | 'true' | binary() | ['false' | 'nil' | 'true' | binary() | [any()] | number() | map()] | number() | map() and the contract is (iodata(),'Elixir.Keyword':t()) -> t() \ No newline at end of file +apps/block_scout_web/lib/block_scout_web/views/layout_view.ex:165: The call 'Elixir.Poison.Parser':'parse!'(any(),#{'keys':='atoms!'}) will never return since the success typing is (binary() | maybe_improper_list(binary() | maybe_improper_list(any(),binary() | []) | byte(),binary() | []),[{atom(),_}]) -> 'false' | 'nil' | 'true' | binary() | ['false' | 'nil' | 'true' | binary() | [any()] | number() | map()] | number() | map() and the contract is (iodata(),'Elixir.Keyword':t()) -> t() \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex index 8698dc7a7b..2a216d13fd 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex @@ -142,13 +142,13 @@ defmodule BlockScoutWeb.LayoutView do end def release_link(version) do - release_link = Application.get_env(:block_scout_web, :release_link) + release_link_env_var = Application.get_env(:block_scout_web, :release_link) release_link = - if release_link == "" || release_link == nil do + if release_link_env_var == "" || release_link_env_var == nil do "https://github.com/poanetwork/blockscout/releases/tag/" <> version else - release_link + release_link_env_var end html_escape({:safe, "#{version}"}) diff --git a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs index 5a934c20be..de693dac05 100644 --- a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs @@ -65,14 +65,16 @@ defmodule BlockScoutWeb.LayoutViewTest do test "use the version when there is no release_link env configured for it" do Application.put_env(:block_scout_web, :release_link, nil) - assert LayoutView.release_link("1.3.4") == {:safe, + assert LayoutView.release_link("1.3.4") == + {:safe, ~s(1.3.4)} end test "use the version when empty release_link env configured for it" do Application.put_env(:block_scout_web, :release_link, "") - assert LayoutView.release_link("1.3.4") == {:safe, + assert LayoutView.release_link("1.3.4") == + {:safe, ~s(1.3.4)} end From 9cb94ffa91f254cb416cffe71fd7347f3accb31f Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 15 May 2019 14:34:55 +0300 Subject: [PATCH 3/5] Update CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eed85aec8..676b95a4ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ - [#1837](https://github.com/poanetwork/blockscout/pull/1837) - Add -f flag to clear_build.sh script delete static folder - [#1900](https://github.com/poanetwork/blockscout/pull/1900) - SUPPORTED_CHAINS ENV var - [#1892](https://github.com/poanetwork/blockscout/pull/1892) - Remove temporary worker modules +- [#1958](https://github.com/poanetwork/blockscout/pull/1958) - Default value for release link env var ## 1.3.10-beta From fa9c50853315ccb5d500247cd20ff98a923bf0f1 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 15 May 2019 16:31:52 +0300 Subject: [PATCH 4/5] cond instead fo if --- .dialyzer-ignore | 2 +- .../lib/block_scout_web/views/layout_view.ex | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.dialyzer-ignore b/.dialyzer-ignore index e6b6ee70a7..53e3554c6e 100644 --- a/.dialyzer-ignore +++ b/.dialyzer-ignore @@ -4,4 +4,4 @@ apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex:400: Function timestamp_to_datetime/1 has no local return apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: Function microseconds_time/1 has no local return apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: The call 'Elixir.System':convert_time_unit(__@1::any(),'native','microseconds') breaks the contract (integer(),time_unit() | 'native',time_unit() | 'native') -> integer() -apps/block_scout_web/lib/block_scout_web/views/layout_view.ex:165: The call 'Elixir.Poison.Parser':'parse!'(any(),#{'keys':='atoms!'}) will never return since the success typing is (binary() | maybe_improper_list(binary() | maybe_improper_list(any(),binary() | []) | byte(),binary() | []),[{atom(),_}]) -> 'false' | 'nil' | 'true' | binary() | ['false' | 'nil' | 'true' | binary() | [any()] | number() | map()] | number() | map() and the contract is (iodata(),'Elixir.Keyword':t()) -> t() \ No newline at end of file +apps/block_scout_web/lib/block_scout_web/views/layout_view.ex:174: The call 'Elixir.Poison.Parser':'parse!'(any(),#{'keys':='atoms!'}) will never return since the success typing is (binary() | maybe_improper_list(binary() | maybe_improper_list(any(),binary() | []) | byte(),binary() | []),[{atom(),_}]) -> 'false' | 'nil' | 'true' | binary() | ['false' | 'nil' | 'true' | binary() | [any()] | number() | map()] | number() | map() and the contract is (iodata(),'Elixir.Keyword':t()) -> t() \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex index 2a216d13fd..12df6d3f0a 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex @@ -145,13 +145,22 @@ defmodule BlockScoutWeb.LayoutView do release_link_env_var = Application.get_env(:block_scout_web, :release_link) release_link = - if release_link_env_var == "" || release_link_env_var == nil do - "https://github.com/poanetwork/blockscout/releases/tag/" <> version - else - release_link_env_var + cond do + version == "" || version == nil -> + nil + + release_link_env_var == "" || release_link_env_var == nil -> + "https://github.com/poanetwork/blockscout/releases/tag/" <> version + + true -> + release_link_env_var end - html_escape({:safe, "#{version}"}) + if release_link == nil do + "" + else + html_escape({:safe, "#{version}"}) + end end def ignore_version?("unknown"), do: true From 40dae3a120d99f0651d1a4941850ce1d34b18697 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 15 May 2019 16:56:43 +0300 Subject: [PATCH 5/5] Extend and fix tests --- .../views/layout_view_test.exs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs index de693dac05..5787159b14 100644 --- a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs @@ -62,20 +62,32 @@ defmodule BlockScoutWeb.LayoutViewTest do end describe "release_link/1" do - test "use the version when there is no release_link env configured for it" do + test "set empty string if no blockscout version configured" do + Application.put_env(:block_scout_web, :blockscout_version, nil) + + assert LayoutView.release_link(nil) == "" + end + + test "set empty string if blockscout version is empty string" do + Application.put_env(:block_scout_web, :blockscout_version, "") + + assert LayoutView.release_link("") == "" + end + + test "use the default value when there is no release_link env configured for it" do Application.put_env(:block_scout_web, :release_link, nil) - assert LayoutView.release_link("1.3.4") == + assert LayoutView.release_link("v1.3.4-beta") == {:safe, - ~s(1.3.4)} + ~s(v1.3.4-beta)} end - test "use the version when empty release_link env configured for it" do + test "use the default value when empty release_link env configured for it" do Application.put_env(:block_scout_web, :release_link, "") - assert LayoutView.release_link("1.3.4") == + assert LayoutView.release_link("v1.3.4-beta") == {:safe, - ~s(1.3.4)} + ~s(v1.3.4-beta)} end test "use the enviroment release link when it's configured" do @@ -85,9 +97,9 @@ defmodule BlockScoutWeb.LayoutViewTest do "https://github.com/poanetwork/blockscout/releases/tag/v1.3.4-beta" ) - assert LayoutView.release_link("1.3.4") == + assert LayoutView.release_link("v1.3.4-beta") == {:safe, - ~s(1.3.4)} + ~s(v1.3.4-beta)} end end