Home

Awesome

<!-- markdownlint-disable MD001 MD013 MD034 MD033 MD051 -->

giturlparser.lua

<p align="center"> <a href="https://luarocks.org/modules/linrongbin16/giturlparser"><img alt="luarocks" src="https://custom-icon-badges.demolab.com/luarocks/v/linrongbin16/giturlparser?label=LuaRocks&labelColor=2C2D72&logo=tag&logoColor=fff&color=blue" /></a> <a href="https://github.com/linrongbin16/giturlparser.lua/actions/workflows/ci.yml"><img alt="ci.yml" src="https://img.shields.io/github/actions/workflow/status/linrongbin16/giturlparser.lua/ci.yml?label=GitHub%20CI&labelColor=181717&logo=github&logoColor=fff" /></a> <a href="https://app.codecov.io/github/linrongbin16/giturlparser.lua"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/giturlparser.lua?logo=codecov&logoColor=F01F7A&label=Codecov" /></a> </p> <p align="center"> Git url parsing library for lua, e.g. the output of <code>git remote get-url origin</code>. </p>

Table of Contents

Requirements

Features

Install

luarocks install giturlparser

Patterns

There are (mainly) three types of git url pattern:

[!NOTE]

They are (just help to explain) written with a regex-like syntax:

  1. The {} contains parsed components returned from giturlparser.GitUrlInfo.
  2. The [] contains optional (0 or 1) component.
  3. The []* contains 0 or more component.
  4. The []+ contains 1 or more component.
  5. The | inside [] is or operator.

Full Protocols

{protocol}://[[{user}[:{password}]@]{host}[:{port}]]/[{org}/]*{repo}

For example:

SSH Omitted Protocols

[{user}[:{password}]@]{host}:[{org}/]*{repo}

For example:

Local File System

[[.|..|~]/][{org}/]*{repo}

For example:

API

Types

giturlparser.GitUrlPos

The string position of a component.

--- @alias giturlparser.GitUrlPos {start_pos:integer?,end_pos:integer?}

It contains below fields:

giturlparser.GitUrlInfo

Parsed information.

--- @alias giturlparser.GitUrlInfo {protocol:string?,protocol_pos:giturlparser.GitUrlPos?,user:string?,user_pos:giturlparser.GitUrlPos?,password:string?,password_pos:giturlparser.GitUrlPos?,host:string?,host_pos:giturlparser.GitUrlPos?,org:string?,org_pos:giturlparser.GitUrlPos?,repo:string,repo_pos:giturlparser.GitUrlPos,path:string,path_pos:giturlparser.GitUrlPos}

It contains below fields:

There're 2 more sugar fields:

[!NOTE]

Functions

parse

Parse url and returns the parsed info (lua table).

--- @param url string
--- @return giturlparser.GitUrlInfo?, string?
M.parse = function(url)

Parameters:

Returns:

References

  1. What are the supported git url formats?

Development

To develop the project and make PR, please setup with:

To run unit tests, please install below dependencies:

Contribute

Please open issue/PR for anything about giturlparser.lua.

Like giturlparser.lua? Consider

Github Sponsor Wechat Pay Alipay