Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Update Gitea.clone to return tuple {:ok, path} or {:error, reason} #17

Open
SimonLab opened this issue May 20, 2022 · 2 comments
Open
Labels
chore a tedious but necessary task often paying technical debt enhancement New feature or request help wanted Extra attention is needed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T1h Time Estimate 1 Hour

Comments

@SimonLab
Copy link
Member

At the moment the clone function returns a string representing the path when the repository is cloned to.
However there isn't a way to know when the clone function has failed:

gitea/lib/gitea.ex

Lines 149 to 164 in 0c2bb0e

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)
local_path = local_repo_path(org_name, repo_name)
Logger.info("git clone #{git_repo_url} #{local_path}")
case inject_git().clone([git_repo_url, local_path]) do
{:ok, %Git.Repository{path: path}} ->
# Logger.info("Cloned repo: #{git_repo_url} to: #{path}")
path
{:error, git_err} ->
Logger.error("Gitea.clone/1 tried to clone #{git_repo_url}, got: #{git_err.message}")
local_path
end
end

We could update it to:

  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)
    local_path = local_repo_path(org_name, repo_name)
    Logger.info("git clone #{git_repo_url} #{local_path}")

    case inject_git().clone([git_repo_url, local_path]) do
      {:ok, %Git.Repository{path: path}} ->
        # Logger.info("Cloned repo: #{git_repo_url} to: #{path}")
        {:ok, path}

      {:error, git_err} ->
        Logger.error("Gitea.clone/1 tried to clone #{git_repo_url}, got: #{git_err.message}")
        {:error, git_err} # I would returns the git_err exception  and the client can either `raise git_err` or execute something else basd on the :error atom
    end
  end
@SimonLab SimonLab added the enhancement New feature or request label May 20, 2022
@nelsonic nelsonic added priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T25m Time Estimate 25 Minutes labels May 20, 2022
@nelsonic
Copy link
Member

@SimonLab do we need this today? 💭

@SimonLab
Copy link
Member Author

I think it can wait, I'll create an issue on the application client to update the code once we have updated Gitea with this type of tuple response

@nelsonic nelsonic changed the title Update Gitea.clone to return tuple {:ok, path} or {:error, reason} Update Gitea.clone to return tuple {:ok, path} or {:error, reason} May 20, 2022
@nelsonic nelsonic added help wanted Extra attention is needed chore a tedious but necessary task often paying technical debt T1h Time Estimate 1 Hour and removed T25m Time Estimate 25 Minutes labels May 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
chore a tedious but necessary task often paying technical debt enhancement New feature or request help wanted Extra attention is needed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T1h Time Estimate 1 Hour
Projects
None yet
Development

No branches or pull requests

2 participants