Gitea.Helpers (gitea v1.1.11)

Helper functions that can be unit tested independently of the main functions. If you spot any way to make these better, please share: https://github.com/dwyl/gitea/issues

Link to this section Summary

Functions

api_base_url/0 returns the Gitea Server REST API url for API requests.

Returns the full system path

get_org_name_from_url/1 extracts the organisation name from a .git url. ssh://git@gitea-server.fly.dev:10022/theorg/myrepo.git

returns {org, repo} from git url

get_repo_name_from_url/1 extracts the repository name from a .git url. Feel free to refactor/simplify this function if you want.

local_git_repo/2 returns the %Git.Repository{} (struct) for an org and repo on the localhost. This is used by the Git module to perform operations.

local_repo_path/2 returns the full system path for the cloned repo on the localhost i.e. the Elixir/Phoenix server that cloned it.

make_url/1 constructs the URL based on the supplied git url.

remote_url/3 returns the git remote url.

remote_url_ssh/2 returns the remote ssh url for cloning.

temp_dir/1 returns the Current Working Directory (CWD). Made this a function in case we want to change the location of the directory later e.g. to a temporary directory.

Link to this section Functions

@spec api_base_url() :: String.t()

api_base_url/0 returns the Gitea Server REST API url for API requests.

examples

Examples

iex> Gitea.Helpers.api_base_url() "https://gitea-server.fly.dev/api/v1/"

Link to this function

create_local_path(path)

@spec create_local_path([String.t()]) :: binary()

Returns the full system path

Link to this function

get_org_name_from_url(url)

@spec get_org_name_from_url(String.t()) :: String.t()

get_org_name_from_url/1 extracts the organisation name from a .git url. ssh://git@gitea-server.fly.dev:10022/theorg/myrepo.git

Link to this function

get_org_repo_names(url)

@spec get_org_repo_names(String.t()) :: {String.t(), String.t()}

returns {org, repo} from git url

examples

Examples

iex> Gitea.Helpers.get_org_repo_names("git@gitea-server.fly.dev:myorg/myrepo.git") {"myorg", "myrepo"}

iex> Gitea.Helpers.get_org_repo_names("ssh://git@gitea-server.fly.dev:10022/theorg/myrepo.git") {"theorg", "myrepo"}

iex> Gitea.Helpers.get_org_repo_names("https://gitea-server.fly.dev/myorg/public-repo.git") {"myorg", "public-repo"}

Link to this function

get_repo_name_from_url(url)

@spec get_repo_name_from_url(String.t()) :: String.t()

get_repo_name_from_url/1 extracts the repository name from a .git url. Feel free to refactor/simplify this function if you want.

Link to this function

local_git_repo(org, repo)

@spec local_git_repo(String.t(), String.t()) :: Git.Repository.t()

local_git_repo/2 returns the %Git.Repository{} (struct) for an org and repo on the localhost. This is used by the Git module to perform operations.

Link to this function

local_repo_path(org, repo)

@spec local_repo_path(String.t(), String.t()) :: binary()

local_repo_path/2 returns the full system path for the cloned repo on the localhost i.e. the Elixir/Phoenix server that cloned it.

Link to this function

make_url(git_url)

@spec make_url(String.t()) :: String.t()

make_url/1 constructs the URL based on the supplied git url.

examples

Examples

iex> Gitea.Helpers.make_url("gitea-server.fly.dev") "git@gitea-server.fly.dev:"

iex> Gitea.Helpers.make_url("github.com") "git@github.com:"

Link to this function

remote_url(base_url, org, repo)

@spec remote_url(String.t(), String.t(), String.t()) :: String.t()

remote_url/3 returns the git remote url.

Link to this function

remote_url_ssh(org, repo)

@spec remote_url_ssh(String.t(), String.t()) :: String.t()

remote_url_ssh/2 returns the remote ssh url for cloning.

@spec temp_dir(any()) :: binary()

temp_dir/1 returns the Current Working Directory (CWD). Made this a function in case we want to change the location of the directory later e.g. to a temporary directory.