Skip to content

Commit

Permalink
Add gitlab/github username:access_token parse support (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
protoroto committed Sep 12, 2023
1 parent f7255c0 commit 4f783b3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Exposed attributes
* ``path``: path to file or directory (includes the branch name) - gitlab / github only
* ``path_raw``: raw path starting from the repo name (might include platform keyword) - gitlab / github only
* ``branch``: branch name (when parseable) - gitlab / github only
* ``username``: username from ``<username>:<access_token>@<url>`` gitlab / github urls
* ``access_token``: access token from ``<username>:<access_token>@<url>`` gitlab / github urls

Parse
==================
Expand Down
1 change: 1 addition & 0 deletions changes/21.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add github/gitlab username:access_token parse support
2 changes: 2 additions & 0 deletions giturlparse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"url",
"platform",
"protocol",
"username",
"access_token",
)


Expand Down
3 changes: 2 additions & 1 deletion giturlparse/platforms/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
class GitHubPlatform(BasePlatform):
PATTERNS = {
"https": (
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?P<domain>[^/]+?)"
r"(?P<protocols>(git\+)?(?P<protocol>https))://"
r"((?P<username>[^/]+?):(?P<access_token>[^/]+?)@)?(?P<domain>[^/]+?)"
r"(?P<pathname>/(?P<owner>[^/]+?)/(?P<repo>[^/]+?)(?:(\.git)?(/)?)(?P<path_raw>(/blob/|/tree/).+)?)$"
),
"ssh": (
Expand Down
3 changes: 2 additions & 1 deletion giturlparse/platforms/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
class GitLabPlatform(BasePlatform):
PATTERNS = {
"https": (
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?P<domain>[^:/]+)(?P<port>:[0-9]+)?"
r"(?P<protocols>(git\+)?(?P<protocol>https))://"
r"((?P<username>[^/]+?):(?P<access_token>[^/]+?)@)?(?P<domain>[^:/]+)(?P<port>:[0-9]+)?"
r"(?P<pathname>/(?P<owner>[^/]+?)/"
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
Expand Down
52 changes: 52 additions & 0 deletions giturlparse/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,33 @@
},
),
),
(
"HTTPS",
(
"https://username:access_token@github.com/Org/Repo.git",
{
"host": "github.com",
"resource": "github.com",
"user": "git",
"port": "",
"owner": "Org",
"repo": "Repo",
"name": "Repo",
"groups": [],
"path": "",
"path_raw": "",
"pathname": "/Org/Repo.git",
"branch": "",
"protocol": "https",
"protocols": ["https"],
"username": "username",
"access_token": "access_token",
"github": True,
"bitbucket": False,
"assembla": False,
},
),
),
(
"HTTPS",
(
Expand Down Expand Up @@ -454,6 +481,31 @@
},
),
),
(
"HTTPS",
(
"https://username:access_token@gitlab.com/nephila/giturlparse/blob/master/giturlparse/github.py",
{
"host": "gitlab.com",
"resource": "gitlab.com",
"user": "git",
"port": "",
"owner": "nephila",
"repo": "giturlparse",
"name": "giturlparse",
"groups": [],
"path": "master/giturlparse/github.py",
"path_raw": "/blob/master/giturlparse/github.py",
"pathname": "/nephila/giturlparse/blob/master/giturlparse/github.py",
"branch": "",
"username": "username",
"access_token": "access_token",
"protocol": "https",
"protocols": ["https"],
"platform": "gitlab",
},
),
),
(
"HTTPS",
(
Expand Down

0 comments on commit 4f783b3

Please sign in to comment.