diff --git a/.gitignore b/.gitignore index 228e8f4..262a891 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ gitea-*.tar # Temporary files, for example, from tests. /tmp/ +tmp/test-repo +tmp/test-repo/README.md # Don't accidentally commit real environment variables .env diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3f35897 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test-repo"] + path = test-repo + url = https://gitea-server.fly.dev/nelsonic/public-repo.git \ No newline at end of file diff --git a/README.md b/README.md index 96189ff..162e546 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Gitea -Interface with a **`Gitea`** instance from **`Elixir`**. +**`Elixir`** interface with a **`Gitea`** instance from . [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/dwyl/gitea/Elixir%20CI?label=build&style=flat-square)](https://github.com/dwyl/gitea/actions/workflows/ci.yml) [![codecov.io](https://img.shields.io/codecov/c/github/dwyl/gitea/main.svg?style=flat-square)](http://codecov.io/github/dwyl/gitea?branch=main) @@ -56,14 +56,16 @@ how we use the package: For the complete list of functions, -please see the docs: https://hexdocs.pm/gitea 📚 +please see the docs: +[hexdocs.pm/**gitea**](https://hexdocs.pm/gitea) +📚 # Who? 👤 This library is used by our (`Phoenix`) GitHub Backup App.
If you find it helpful for your project, please ⭐ on GitHub: -[github.com/dwyl/gitea](https://github.com/dwyl/gitea) +[github.com/dwyl/**gitea**](https://github.com/dwyl/gitea) ## _How_? 💻 @@ -89,7 +91,7 @@ by adding `gitea` to the list of dependencies in your `mix.exs` file: ```elixir def deps do [ - {:gitea, "~> 1.0.1"} + {:gitea, "~> 1.0.3"}, ] end ``` @@ -156,6 +158,8 @@ export GIT_TEMP_DIR_PATH=tmp > **Note**: the directory **must _already_ exist**. > (it won't be created if it's not there ...) +> Create it if you don't already have it: +> `mkdir tmp` followed by `cp -r test-repo tmp`
@@ -220,7 +224,7 @@ you can read any file inside it. org_name = "myorg" repo_name = "public-repo" file_name = "README.md" -{:ok, text} == Gitea.local_file_read(org_name, repo_name, file_name) +{:ok, text} = Gitea.local_file_read(org_name, repo_name, file_name) ``` ### 4. _Write_ to a File diff --git a/lib/helpers.ex b/lib/helpers.ex index f379a3f..8385797 100644 --- a/lib/helpers.ex +++ b/lib/helpers.ex @@ -23,21 +23,18 @@ defmodule Gitea.Helpers do end @doc """ - `make_url/2` constructs the URL based on the supplied git `url` and TCP `port`. - If the `port` is set it will be a custom Gitea instance. + `make_url/1` constructs the URL based on the supplied git `url`. ## Examples - iex> Gitea.Helpers.make_url("gitea-server.fly.dev", "10022") - "ssh://git@gitea-server.fly.dev:10022/" + iex> Gitea.Helpers.make_url("gitea-server.fly.dev") + "git@gitea-server.fly.dev:" iex> Gitea.Helpers.make_url("github.com") "git@github.com:" """ - @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}:" + @spec make_url(String.t()) :: String.t() + def make_url(git_url), do: "git@#{git_url}:" @doc """ `remote_url/3` returns the git remote url. @@ -53,8 +50,7 @@ defmodule Gitea.Helpers do @spec remote_url_ssh(String.t(), String.t()) :: String.t() def remote_url_ssh(org, repo) do url = Envar.get("GITEA_URL") - port = Envar.get("GITEA_SSH_PORT", nil) - git_url = Gitea.Helpers.make_url(url, port) + git_url = make_url(url) remote_url(git_url, org, repo) end diff --git a/mix.exs b/mix.exs index 7f22617..bbb899a 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,7 @@ defmodule Gitea.MixProject do def project do [ app: :gitea, - version: "1.0.1", + version: "1.0.3", elixir: @elixir_requirement, start_permanent: Mix.env() == :prod, deps: deps(), diff --git a/test-repo/README.md b/test-repo/README.md index 569bb55..c2a4508 100644 --- a/test-repo/README.md +++ b/test-repo/README.md @@ -1 +1 @@ -text test-repo50098413206073914 \ No newline at end of file +text test-repo9225876994531516 \ No newline at end of file diff --git a/test/gitea_helpers_test.exs b/test/gitea_helpers_test.exs index bf7799c..e03eaa1 100644 --- a/test/gitea_helpers_test.exs +++ b/test/gitea_helpers_test.exs @@ -18,13 +18,13 @@ defmodule Gitea.HelpersTest do end test "make_url/2 returns a valid gitea (Fly.io) Base URL" do - git_url = Gitea.Helpers.make_url("gitea-server.fly.dev", "10022") - assert git_url == "ssh://git@gitea-server.fly.dev:10022/" + git_url = Gitea.Helpers.make_url("gitea-server.fly.dev") + assert git_url == "git@gitea-server.fly.dev:" end test "remote_url/3 returns a valid gitea (Fly.io) remote URL" do - git_url = Gitea.Helpers.make_url("gitea-server.fly.dev", "10022") + git_url = Gitea.Helpers.make_url("gitea-server.fly.dev") remote_url = Gitea.Helpers.remote_url(git_url, "nelsonic", "public-repo") - assert remote_url == "ssh://git@gitea-server.fly.dev:10022/nelsonic/public-repo.git" + assert remote_url == "git@gitea-server.fly.dev:nelsonic/public-repo.git" end end diff --git a/test/gitea_test.exs b/test/gitea_test.exs index c9ecec0..818ef2e 100644 --- a/test/gitea_test.exs +++ b/test/gitea_test.exs @@ -122,14 +122,17 @@ defmodule GiteaTest do test "local_branch_create/1 creates a new branch on the localhost" do org_name = "myorg" repo_name = create_test_git_repo(org_name) - # # delete draft branch if exists: - Git.branch(Gitea.Helpers.local_git_repo(org_name, repo_name), ["-m", repo_name]) - Git.branch(Gitea.Helpers.local_git_repo(org_name, repo_name), ~w(-d draft)) + # delete draft branch if exists: + {:ok, branch_name} = Git.branch(%Git.Repository{path: @cwd}, ~w(--show-current)) + Git.branch(Gitea.Helpers.local_git_repo(org_name, repo_name), ~w(-D draft)) {:ok, res} = Gitea.local_branch_create(org_name, repo_name, "draft") assert res == "Switched to a new branch 'draft'\n" # Cleanup! + branch_name = String.replace(branch_name, "\n", "") + Git.checkout(%Git.Repository{path: @cwd}, [branch_name]) + Git.branch(Gitea.Helpers.local_git_repo(org_name, repo_name), ~w(-D draft)) teardown_local_and_remote(org_name, repo_name) end diff --git a/tmp/test-repo/README.md b/tmp/test-repo/README.md new file mode 100644 index 0000000..5bf378d --- /dev/null +++ b/tmp/test-repo/README.md @@ -0,0 +1 @@ +text test-repo38958817237599362 \ No newline at end of file