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

Commit

Permalink
Merge pull request #11 from dwyl/update-docs-issue-#1
Browse files Browse the repository at this point in the history
Update docs issue #1
  • Loading branch information
SimonLab authored May 19, 2022
2 parents 25c6e48 + 2298a13 commit 0c2bb0e
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test-repo"]
path = test-repo
url = https://gitea-server.fly.dev/nelsonic/public-repo.git
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img alt="Gitea" src="https://user-images.githubusercontent.com/194400/168781665-a52d2c00-8b69-44ae-a10a-7bd1c3932020.svg" width="240"/>

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)
Expand Down Expand Up @@ -56,14 +56,16 @@ how we use the package:
</div>

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. <br />
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_? 💻
Expand All @@ -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
```
Expand Down Expand Up @@ -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`
<br />

Expand Down Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions lib/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]:10022/"
iex> Gitea.Helpers.make_url("gitea-server.fly.dev")
"[email protected]:"
iex> Gitea.Helpers.make_url("github.com")
"[email protected]:"
"""
@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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion test-repo/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
text test-repo50098413206073914
text test-repo9225876994531516
8 changes: 4 additions & 4 deletions test/gitea_helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]:10022/"
git_url = Gitea.Helpers.make_url("gitea-server.fly.dev")
assert git_url == "[email protected]:"
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://[email protected]:10022/nelsonic/public-repo.git"
assert remote_url == "[email protected]:nelsonic/public-repo.git"
end
end
9 changes: 6 additions & 3 deletions test/gitea_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tmp/test-repo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text test-repo38958817237599362

0 comments on commit 0c2bb0e

Please sign in to comment.