From e2670678fe8db15fcc0e82c1ea378fe92f72a470 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Thu, 12 May 2022 11:18:45 +0100 Subject: [PATCH 1/3] Update specs Update function specs or udpate code if error founds with dialyzer related to: #26 --- lib/gogs.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gogs.ex b/lib/gogs.ex index 176a97d..be2d0d9 100644 --- a/lib/gogs.ex +++ b/lib/gogs.ex @@ -116,7 +116,7 @@ defmodule Gogs do `clone/1` clones a remote git repository based on `git_repo_url` returns the path of the _local_ copy of the repository. """ - @spec clone(String.t()) :: {:ok, any} | {:error, any} + @spec clone(String.t()) :: String.t() def clone(git_repo_url) do org_name = get_org_name_from_url(git_repo_url) repo_name = get_repo_name_from_url(git_repo_url) @@ -154,7 +154,7 @@ defmodule Gogs do `local_file_read/3` reads the raw text from the `file_name`, params: `org_name`, `repo_name` & `file_name` """ - @spec local_file_read(String.t(), String.t(), String.t()) :: String.t() + @spec local_file_read(String.t(), String.t(), String.t()) :: {:ok, String.t()} | {:error, any()} def local_file_read(org_name, repo_name, file_name) do file_path = Path.join([local_repo_path(org_name, repo_name), file_name]) File.read(file_path) From 41b6b8afadc4aafb6d237ed99f9250680df3d482 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Thu, 12 May 2022 15:20:10 +0100 Subject: [PATCH 2/3] update spec --- lib/git_mock.ex | 2 +- lib/gogs.ex | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/git_mock.ex b/lib/git_mock.ex index 764bfb8..da9a629 100644 --- a/lib/git_mock.ex +++ b/lib/git_mock.ex @@ -19,7 +19,7 @@ defmodule Gogs.GitMock do iex> GitMock.clone("any-url-containing-the-word-error-to-trigger-failure") {:error, %Git.Error{message: "git clone error (mock)"}} """ - @spec clone(String.t()) :: {:ok, Git.Repository.t()} | {:error, Git.Error} + @spec clone(String.t() | list(String.t())) :: {:ok, Git.Repository.t()} | {:error, Git.Error} def clone(url) do case Useful.typeof(url) do # e.g: ["ssh://git@gogs.dev/myorg/error-test.git", "tmp/test-repo"] diff --git a/lib/gogs.ex b/lib/gogs.ex index be2d0d9..79e0c8e 100644 --- a/lib/gogs.ex +++ b/lib/gogs.ex @@ -103,6 +103,7 @@ defmodule Gogs do # First retrieve the Raw Markdown Text we want to render: {:ok, %HTTPoison.Response{body: raw_markdown}} = Gogs.remote_read_raw(org_name, repo_name, file_name, branch_name) + url = @api_base_url <> "markdown/raw" Logger.info("remote_render_markdown_html/4 #{url}") # temp_context = "https://github.com/gogs/gogs" @@ -128,8 +129,8 @@ defmodule Gogs do # Logger.info("Cloned repo: #{git_repo_url} to: #{path}") path - {:error, %Git.Error{message: message}} -> - Logger.error("Gogs.clone/1 tried to clone #{git_repo_url}, got: #{message}") + {:error, git_err} -> + Logger.error("Gogs.clone/1 tried to clone #{git_repo_url}, got: #{git_err.message}") local_path end end @@ -144,9 +145,12 @@ defmodule Gogs do {:ok, res} -> {:ok, res} - {:error, %Git.Error{message: message}} -> - Logger.error("Git.checkout error: #{message}, #{repo_name} (should not thow error)") - {:error, message} + {:error, git_err} -> + Logger.error( + "Git.checkout error: #{git_err.message}, #{repo_name} (should not thow error)" + ) + + {:error, git_err.message} end end From 0984d4ba74827f9b4a856bf151a95a66c85d1f0f Mon Sep 17 00:00:00 2001 From: SimonLab Date: Thu, 12 May 2022 15:31:24 +0100 Subject: [PATCH 3/3] Define specs Update specs in helpers --- lib/helpers.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/helpers.ex b/lib/helpers.ex index 761bc6b..11314eb 100644 --- a/lib/helpers.ex +++ b/lib/helpers.ex @@ -33,7 +33,7 @@ defmodule GogsHelpers do "git@github.com:" """ - @spec make_url(String.t(), integer()) :: String.t() + @spec make_url(String.t(), integer() | nil) :: String.t() def make_url(git_url, port \\ 0) def make_url(git_url, port) when port > 0, do: "ssh://git@#{git_url}:#{port}/" def make_url(git_url, _port), do: "git@#{git_url}:" @@ -104,6 +104,7 @@ defmodule GogsHelpers do else Path.join([temp_dir(@git_dir), org, repo]) |> Path.expand() end + # coveralls-ignore-stop end