View Source Gitly.Utils.Git.Provider (gitly v0.1.0)

A module to handle Git provider operations.

This module provides functionality to identify Git providers and build archive URLs for different Git hosting services.

Summary

Functions

Builds the URL for the given provider.

Returns the host type based on the given string.

Types

@type host() :: :github | :gitlab | :bitbucket | :unknown

Functions

Link to this function

build_url(atom, arg2, format)

View Source
@spec build_url(host(), map(), String.t()) :: String.t() | :error

Builds the URL for the given provider.

Parameters

  • provider - The host type (:github, :gitlab, :bitbucket, or :unknown).
  • input - A map containing repository information. It must include:
    • :owner - The repository owner or organization name.
    • :repo - The repository name.
    • :ref - The reference (branch, tag, or commit).
  • format - The desired archive format (e.g., "zip", "tar.gz").

Returns

  • A string containing the constructed URL for the archive.
  • :error if the provider is unknown.

Examples

iex> input = %{owner: "elixir-lang", repo: "elixir", ref: "main"}
iex> Gitly.Utils.Git.Provider.build_url(:github, input, "zip")
"https://github.com/elixir-lang/elixir/archive/main.zip"

iex> input = %{owner: "gitlab-org", repo: "gitlab", ref: "master"}
iex> Gitly.Utils.Git.Provider.build_url(:gitlab, input, "tar.gz")
"https://gitlab.com/gitlab-org/gitlab/-/archive/master/gitlab-master.tar.gz"

iex> input = %{owner: "atlassian", repo: "bitbucket", ref: "main"}
iex> Gitly.Utils.Git.Provider.build_url(:bitbucket, input, "tar.gz")
"https://bitbucket.org/atlassian/bitbucket/get/main.tar.gz"

iex> Gitly.Utils.Git.Provider.build_url(:unknown, %{}, "zip")
:error
@spec from_string(String.t()) :: host()

Returns the host type based on the given string.

Parameters

  • string - A string containing the host name or URL.

Returns

  • The host type as an atom (:github, :gitlab, :bitbucket, or :unknown).

Examples

iex> Gitly.Utils.Git.Provider.from_string("github.com")
:github

iex> Gitly.Utils.Git.Provider.from_string("gitlab")
:gitlab

iex> Gitly.Utils.Git.Provider.from_string("example.com")
:unknown