GogsHelpers (gogs v0.6.0)

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/gogs/issues

Link to this section Summary

Functions

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

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/1 returns the %Git.Repository{} (struct) for a repo_name on the localhost. This is used by the Git module to perform operations.

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

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 Gogs instance.

parse_body_response/1 parses the response returned by the Gogs Server so your app can use the resulting JSON.

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

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

examples

Examples

iex> GogsHelpers.api_base_url() "https://gogs-server.fly.dev/api/v1/"

Link to this function

get_repo_name_from_url(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.

Link to this function

local_git_repo(repo_name)

local_git_repo/1 returns the %Git.Repository{} (struct) for a repo_name on the localhost. This is used by the Git module to perform operations.

Link to this function

local_repo_path(repo_name)

local_repo_path/1 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, port \\ 0)

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 Gogs instance.

examples

Examples

iex> GogsHelpers.make_url("gogs-server.fly.dev", "10022") "ssh://git@gogs-server.fly.dev:10022/"

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

Link to this function

parse_body_response(arg)

@spec parse_body_response({atom(), String.t()} | {:error, any()}) ::
  {:ok, map()} | {:error, any()}

parse_body_response/1 parses the response returned by the Gogs Server so your app can use the resulting JSON.

Link to this function

remote_url(base_url, org, repo)

remote_url/3 returns the git remote url.

Link to this function

remote_url_ssh(org, repo)

remote_url_ssh/2 returns the remote ssh url for cloning.

Link to this function

temp_dir(dir \\ nil)

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.