Skip to content

Commit

Permalink
Merge pull request #32 from dwyl/update-specs
Browse files Browse the repository at this point in the history
Update specs
  • Loading branch information
nelsonic authored May 12, 2022
2 parents 279f7e7 + 0984d4b commit 1cff500
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/git_mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]/myorg/error-test.git", "tmp/test-repo"]
Expand Down
18 changes: 11 additions & 7 deletions lib/gogs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -116,7 +117,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)
Expand All @@ -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
Expand All @@ -144,17 +145,20 @@ 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

@doc """
`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)
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule GogsHelpers do
"[email protected]:"
"""
@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}:"
Expand Down Expand Up @@ -104,6 +104,7 @@ defmodule GogsHelpers do
else
Path.join([temp_dir(@git_dir), org, repo]) |> Path.expand()
end

# coveralls-ignore-stop
end

Expand Down

0 comments on commit 1cff500

Please sign in to comment.