Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
fd76ecf
chore(test): add test cases
linrongbin16 Jan 8, 2024
36a0b92
chore
linrongbin16 Jan 8, 2024
8737de9
chore
linrongbin16 Jan 8, 2024
e70b999
chore
linrongbin16 Jan 8, 2024
ddee384
chore
linrongbin16 Jan 8, 2024
ed565a7
chore
linrongbin16 Jan 8, 2024
230c4ac
chore
linrongbin16 Jan 8, 2024
4ab7d52
chore
linrongbin16 Jan 8, 2024
4ca43bd
chore
linrongbin16 Jan 8, 2024
cc76375
chore
linrongbin16 Jan 8, 2024
ba99054
chore
linrongbin16 Jan 8, 2024
755cc9e
chore
linrongbin16 Jan 8, 2024
7ca912b
chore
linrongbin16 Jan 8, 2024
3b18863
chore
linrongbin16 Jan 8, 2024
0ecebac
chore
linrongbin16 Jan 8, 2024
6ec66e9
chore
linrongbin16 Jan 8, 2024
d27c7a3
chore
linrongbin16 Jan 8, 2024
1f6d063
chore
linrongbin16 Jan 8, 2024
5f235d6
chore
linrongbin16 Jan 8, 2024
0a3472e
chore
linrongbin16 Jan 8, 2024
4743690
chore
linrongbin16 Jan 8, 2024
0013785
chore
linrongbin16 Jan 8, 2024
166dbe0
chore
linrongbin16 Jan 8, 2024
f3a5ce8
chore
linrongbin16 Jan 8, 2024
0d1f940
chore
linrongbin16 Jan 8, 2024
2dde349
chore
linrongbin16 Jan 8, 2024
ab1afcf
chore
linrongbin16 Jan 8, 2024
62080ae
chore
linrongbin16 Jan 8, 2024
40ba5fc
chore
linrongbin16 Jan 8, 2024
0069042
chore
linrongbin16 Jan 8, 2024
ff5c442
chore
linrongbin16 Jan 8, 2024
3633b16
chore
linrongbin16 Jan 8, 2024
b9f4fea
chore
linrongbin16 Jan 8, 2024
05e2a55
chore
linrongbin16 Jan 8, 2024
185f7f6
chore
linrongbin16 Jan 8, 2024
af55d6f
chore
linrongbin16 Jan 8, 2024
2348a87
chore
linrongbin16 Jan 8, 2024
7b79439
chore
linrongbin16 Jan 8, 2024
17a9970
chore
linrongbin16 Jan 8, 2024
13041ca
chore
linrongbin16 Jan 8, 2024
41cfe1e
chore
linrongbin16 Jan 8, 2024
314c85b
chore
linrongbin16 Jan 8, 2024
dad0461
chore
linrongbin16 Jan 8, 2024
e4214f6
chore
linrongbin16 Jan 8, 2024
f7c7c11
chore
linrongbin16 Jan 8, 2024
f160d62
chore
linrongbin16 Jan 8, 2024
0bb4a1c
chore
linrongbin16 Jan 8, 2024
d3e0c5f
cohre
linrongbin16 Jan 8, 2024
f9db5b2
chore
linrongbin16 Jan 8, 2024
c0fd8dd
chore
linrongbin16 Jan 8, 2024
8b656f4
chore
linrongbin16 Jan 8, 2024
d3649d2
chore
linrongbin16 Jan 8, 2024
c32e741
chore
linrongbin16 Jan 8, 2024
aeed001
chore
linrongbin16 Jan 8, 2024
363e97a
chore
linrongbin16 Jan 8, 2024
757ba8d
chore
linrongbin16 Jan 8, 2024
2517e40
chore
linrongbin16 Jan 8, 2024
f39444f
chore
linrongbin16 Jan 8, 2024
a05d684
chore
linrongbin16 Jan 8, 2024
ddbb380
chore
linrongbin16 Jan 8, 2024
47611d4
chore
linrongbin16 Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ max_line_length = 500
unused = false
unused_args = false
exclude_files = {}
ignore = { "542" }
6 changes: 0 additions & 6 deletions Makefile

This file was deleted.

90 changes: 68 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- markdownlint-disable MD001 MD013 MD034 MD033 MD051 -->

# giturlparser.lua

<p align="center">
Expand All @@ -10,20 +12,69 @@
Pure Lua implemented git URL parsing library, e.g. the output of <code>git remote get-url origin</code>.
</p>

## Table of Contents

- [Requirements](#requirements)
- [Features](#features)
- [Install](#install)
- [API](#api)
- [Types](#types)
- [`giturlparser.GitUrlPos`](#giturlparsergiturlpos)
- [`giturlparser.GitUrlInfo`](#giturlparsergiturlinfo)
- [Functions](#functions)
- [`parse`](#parse)
- [References](#references)
- [Development](#development)
- [Contribute](#contribute)

## Requirements

- Lua >= 5.1, luajit >= 2.0.0.

## Features

- [x] Single file & zero dependency.
- [x] Full [Git Protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) support.
Single file & zero dependency.

Full [Git Protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) support:

> [!NOTE]
>
> Below pattern are (just easier to help explain the parsing algorithm) written in a regex-like syntax:
>
> 1. The `{}` contains parsed components returned from [`giturlparser.GitUrlInfo`](#giturlparsergiturlinfo).
> 2. The `[]` contains optional (0 or 1) component.
> 3. The `[]*` contains zero or more (&ge; 0) component.
> 4. The `[]+` contains 1 or more (&ge; 1) component.
> 5. The `|` inside `[]` is **_or_** operator.

1. `{protocol}://[[{user}[:{password}]@]{host}[:{port}]]/[{org}/]*{repo}`, for example:
- `http://host.xyz/repo.git`
- `https://git@127.0.0.1:12345/repo.git`
- `ssh://username:password@host.xyz:port/path/to/the/repo.git`
- `ssh://host.xyz:port/path/to/the/repo.git`
- `file:///repo.git`
- `file://user:passwd@host.xyz:port/path/to/the/repo.git`
- `file://~/home/to/the/repo.git`
2. `[{user}[:{password}]@]{host}:[{org}/]*{repo}`, for example:
- `git@host.xyz:repo.git`
- `user:passwd@host.xyz:path/to/the/repo.git`
3. `[.|..|~][/{org}]*/{repo}`, for example:
- `repo.git`
- `./repo.git`
- `../path/to/the/repo.git`
- `~/home/to/the/repo.git`
- `/usr/home/to/the/repo.git`

All of above can be written by:

1. `[{protocol}://][[{user}[:{password}]@]host[:{port}]]/[{org}/]*{repo}`
2. `[.|..|~][/{org}]*/{repo}`

## Install

`luarocks install giturlparser`

## Documents
## API

### Types

Expand All @@ -50,28 +101,23 @@ Parsed information.

It contains below fields:

- `protocol`: Protocol, e.g. `http` (`http://`), `https` (`https://`), `ssh` (`ssh://`), `file` (`file://`).
- `protocol_pos`: Protocol position.
- `user`: User name, e.g. `username` in `ssh://username@githost.com`.
- `user_pos`: User name position.
- `password`: Password, e.g. `password` in `ssh://username:password@githost.com`.
- `password_pos`: Password position.
- `host`: Host name, e.g. `githost.com` in `ssh://githost.com`.
- `host_pos`: Host name position.
- `path`: All the left parts after `host/`, e.g. `linrongbin16/giturlparser.lua.git` in `https://github.com/linrongbin16/giturlparser.lua.git`.
- `path_pos`: Path position.
- `repo`: Repository (the left parts after the last slash `/`, if exists), e.g. `giturlparser.lua.git` in `https://github.com/linrongbin16/giturlparser.lua.git`.
- `repo_pos`: Repository position.
- `org`: , Organization (the parts after `host/` and before the last slash `/`, if exists), e.g. `linrongbin16` in `https://github.com/linrongbin16/giturlparser.lua.git`.
- `org_pos`: Organization position.
- `protocol`/`protocol_pos`: Protocol, e.g. `http` in `http://github.com`, and its position.
- `user`/`user_pos`: User name, e.g. `username` in `ssh://username@githost.com`, and its position.
- `password`/`password_pos`: Password, e.g. `password` in `ssh://username:password@githost.com`, and its position.
- `host`/`host_pos`: Host name, e.g. `githost.com` in `ssh://githost.com`, and its position.
- `port`/`port_pos`: Port, e.g. `12345` in `ssh://127.0.0.1:12345/org/repo.git`, and its position.
- `path`/`path_pos`: All the left parts after host name (and optional port), e.g. `/linrongbin16/giturlparser.lua.git` in `https://github.com/linrongbin16/giturlparser.lua.git`, and its position.

> [!NOTE]
>
> The `{path}` component is equivalent to `{org}/{repo}`.
There're 2 more sugar fields:

> [!IMPORTANT]
- `repo`/`repo_pos`: Repository (the last part after the last slash `/`), e.g. `giturlparser.lua.git` in `https://github.com/linrongbin16/giturlparser.lua.git`, and its position.
- `org`/`org_pos`: , Organization (the parts after host name (and optional port), before the last slash `/`), e.g. `linrongbin16` in `https://github.com/linrongbin16/giturlparser.lua.git`, and its position.

> [!NOTE]
>
> If there's only 1 slash, the `org` component is omitted.
> - The `{path}` component is (almost) equivalent to `/{org}/{repo}`.
> - The `{org}` and `{repo}` component are trimmed from around slashes if there's any.
> - If there's only 1 slash, the `org` component is omitted.

### Functions

Expand Down
3 changes: 3 additions & 0 deletions giturlparser-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ description = {
dependencies = {
"lua >= 5.1, luajit >= 2.0.0",
}
test_dependencies = {
"inspect",
}
build = {
type = "builtin",
modules = {
Expand Down
Loading