Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone an existing repo hosted on Gogs Fly https://gogs-server.fly.dev/ #7

Closed
2 tasks done
nelsonic opened this issue Apr 29, 2022 · 3 comments
Closed
2 tasks done

Comments

@nelsonic
Copy link
Member

nelsonic commented Apr 29, 2022

This works fine on my localhost:

git clone ssh://[email protected]:10022/nelsonic/public-repo.git
  • Wrap the Git.Clone command in some syntactic sugar
@nelsonic
Copy link
Member Author

The reason I'm allocating a generous T1h to this is because I've not done it before. But the actual code is probably going to be like 20 lines.

@nelsonic
Copy link
Member Author

In order to do a branch test of my case for this, I'm going to need to create a Repo with a unique name on Fly.io (e.g via REST API) so that it can be cloned and then deleted. Going to work on that now so that I can get 100% test coverage. 😉

GOTO: #9

@nelsonic
Copy link
Member Author

nelsonic commented May 5, 2022

Clone working:

gogs/lib/gogs.ex

Lines 98 to 112 in ec08eb4

@doc """
`clone/1` clones a remote git repository based on `git_repo_url`
returns the path of the _local_ copy of the repository.
"""
def clone(git_repo_url) do
# IO.inspect("git clone #{git_repo_url}")
case inject_git().clone(git_repo_url) do
{:ok, %Git.Repository{path: path}} ->
# Logger.info("Cloned repo: #{git_repo_url} to: #{path}")
path
{:error, %Git.Error{message: message}} ->
Logger.error("ERROR: Tried to clone #{git_repo_url}, got: #{message}")
get_repo_name_from_url(git_repo_url) |> local_repo_path()
end
end

Mock:

gogs/lib/git_mock.ex

Lines 9 to 22 in ec08eb4

@doc """
`clone/1` clones a _real_ Gogs Repo but renames it to `repo_name`
so that it can be used in other tests. This is ugly, we agree!
But we want something we can use in our end-to-end tests
without having to re-invent all of Git.
If you can think of a cleaner way of doing this, please share!
"""
def clone(url) do
if String.contains?(url, "error") do
{:error, %Git.Error{message: "git clone error (mock)"}}
else
{:ok, %Git.Repository{path: GogsHelpers.local_repo_path("test-repo")}}
end
end

I'm happy with this as a baseline implementation. 👍

@nelsonic nelsonic closed this as completed May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant