View Source Gitly.Parser (gitly v0.1.0)
A module to parse repository URLs and return metadata.
This module can handle various formats of repository URLs and convert them into a standardized metadata map.
Summary
Functions
Parses a binary string and returns a metadata map.
Parses a binary string with additional options and returns a metadata map.
Functions
Parses a binary string and returns a metadata map.
The following strings are valid:
- owner/repo
- https://host.com/owner/repo
- https://host.com/owner/repo.git
- host.com/owner/repo
- host:owner/repo
Parameters
str
- A binary string representing the repository URL.
Returns
{:ok, map}
where the map contains::host
- the host of the repository:owner
- the owner of the repository:repo
- the repository name:ref
- the reference (default is "main")
{:error, reason}
if the parsing fails.
Examples
iex> Gitly.Parser.parse("iwatakeshi/gitly")
{:ok, %{host: "github.com", owner: "iwatakeshi", repo: "gitly", ref: "main"}}
iex> Gitly.Parser.parse("https://github.com/iwatakeshi/gitly")
{:ok, %{host: "github.com", owner: "iwatakeshi", repo: "gitly", ref: "main"}}
iex> Gitly.Parser.parse("github.com/iwatakeshi/gitly")
{:ok, %{host: "github.com", owner: "iwatakeshi", repo: "gitly", ref: "main"}}
iex> Gitly.Parser.parse("github:iwatakeshi/gitly")
{:ok, %{host: "github.com", owner: "iwatakeshi", repo: "gitly", ref: "main"}}
iex> Gitly.Parser.parse("blah")
{:error, "Invalid URL"}
Parses a binary string with additional options and returns a metadata map.
This function is similar to parse/1
but allows specifying additional options.
Parameters
str
- A binary string representing the repository URL.opts
- A map of options::host
- the host of the repository (default is "github.com"):ref
- the ref of the repository (default is "main")
Returns
{:ok, map}
where the map contains the parsed metadata.{:error, reason}
if the parsing fails.
Examples
iex> Gitly.Parser.parse("iwatakeshi/gitly", %{host: "gitlab.com", ref: "develop"})
{:ok, %{host: "gitlab.com", owner: "iwatakeshi", repo: "gitly", ref: "develop"}}