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

Update docs issue #1 #11

Merged
merged 30 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6da55b9
create .gitmodules to avoid commiting test changes on the main branch
nelsonic May 17, 2022
8c070de
test msg
May 17, 2022
626aa87
test msg
May 17, 2022
beb53d8
test msg
May 17, 2022
590706f
test msg
May 17, 2022
0167b72
update code to no longer require SSH Port as we dont need it on gitea…
nelsonic May 17, 2022
4d18a2f
update Gitea.commit function to use -f to avoid git error/warning
nelsonic May 17, 2022
07ad63c
bump version in mix.exs and README.md to release create org closes #7
nelsonic May 17, 2022
f020845
Merge branch 'main' into update-docs-issue-#1
nelsonic May 18, 2022
c2b1f93
add check for git branch -D repo_name in gitea_test.exs:134 https://g…
nelsonic May 18, 2022
5c5931c
delete branch before teardown #11
nelsonic May 18, 2022
ee5238d
remove tmp/test-repo/README.md from .git
nelsonic May 18, 2022
82851e7
avoid renaming current branch in test https://github.com/dwyl/gitea/i…
nelsonic May 18, 2022
4a855c1
git branch -D draft |> IO.inspect() #14
nelsonic May 18, 2022
f3558c9
save current branch before running local_branch_create/1 #14
nelsonic May 18, 2022
fd54651
test msg
May 18, 2022
44fe195
add instructions to create ./tmp directory
nelsonic May 18, 2022
5682af8
test msg
May 18, 2022
e6d9026
git branch |> IO.inspect()
nelsonic May 18, 2022
368e83d
test msg
May 18, 2022
4e26a4f
test msg
May 18, 2022
82de976
branch_name = String.replace(branch_name, "\n") #14
nelsonic May 18, 2022
927b6b1
test msg
May 18, 2022
7bdbebc
test msg
May 18, 2022
72031e9
fix merge conflict!!! #14
nelsonic May 18, 2022
eabd1f6
git rm --cached tmp/test-repo/README.md #14
nelsonic May 18, 2022
fd9c8c1
test msg
May 18, 2022
69729ef
test msg
May 18, 2022
4fd3fc6
bump to version 1.0.2
nelsonic May 18, 2022
2298a13
address @SimonLab PR review comments https://github.com/dwyl/gitea/pu…
nelsonic May 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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