Skip to content

Commit 4db5dc6

Browse files
taminomaramathrickpre-commit-ci[bot]protoroto
authored
Bugfix/issue 107 fix bitbucked url parse (#118)
* Fix BitBucket regex user@ is optional for HTTPS URLs. Fixes #107 * Add tests for BitBucket HTTPS URLs * Properly apply platform defaults when parsing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update changelog * Update changes/107.bugfix Co-authored-by: Leonardo Cavallucci <leo.cavallucci@gmail.com> --------- Co-authored-by: Maciej Katafiasz <mathrick@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Leonardo Cavallucci <leo.cavallucci@gmail.com>
1 parent b9f7d15 commit 4db5dc6

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

changes/107.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix Bitbucket url parse and add bitbucket.com to recognized domains

giturlparse/parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def parse(url, check_domain=True):
5252
parsed_info.update(platform.DEFAULTS)
5353

5454
# Get matches as dictionary
55-
matches = platform.clean_data(match.groupdict(default=""))
55+
matches = platform.clean_data(
56+
{k: v if v is not None else platform.DEFAULTS.get(k, "") for k, v in match.groupdict().items()}
57+
)
5658

5759
# Update info with matches
5860
parsed_info.update(matches)

giturlparse/platforms/bitbucket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class BitbucketPlatform(BasePlatform):
55
PATTERNS = {
66
"https": (
7-
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?P<_user>.+)@(?P<domain>.+?)"
7+
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?:(?P<_user>.+)@)?(?P<domain>.+?)"
88
r"(?P<pathname>/(?P<owner>.+)/(?P<repo>.+?)(?:\.git)?)$"
99
),
1010
"ssh": (
@@ -16,5 +16,5 @@ class BitbucketPlatform(BasePlatform):
1616
"https": r"https://%(owner)s@%(domain)s/%(owner)s/%(repo)s%(dot_git)s",
1717
"ssh": r"git@%(domain)s:%(owner)s/%(repo)s%(dot_git)s",
1818
}
19-
DOMAINS = ("bitbucket.org",)
19+
DOMAINS = ("bitbucket.org", "bitbucket.com")
2020
DEFAULTS = {"_user": "git"}

giturlparse/tests/test_parse.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,75 @@
273273
},
274274
),
275275
),
276+
(
277+
"HTTPS",
278+
(
279+
"https://bitbucket.org/Org/Repo.git",
280+
{
281+
"host": "bitbucket.org",
282+
"resource": "bitbucket.org",
283+
"user": "git",
284+
"port": "",
285+
"owner": "Org",
286+
"repo": "Repo",
287+
"name": "Repo",
288+
"groups": [],
289+
"path": "",
290+
"path_raw": "",
291+
"pathname": "/Org/Repo.git",
292+
"branch": "",
293+
"protocol": "https",
294+
"protocols": ["https"],
295+
"platform": "bitbucket",
296+
},
297+
),
298+
),
299+
(
300+
"HTTPS",
301+
(
302+
"https://bitbucket.org/Org/Repo",
303+
{
304+
"host": "bitbucket.org",
305+
"resource": "bitbucket.org",
306+
"user": "git",
307+
"port": "",
308+
"owner": "Org",
309+
"repo": "Repo",
310+
"name": "Repo",
311+
"groups": [],
312+
"path": "",
313+
"path_raw": "",
314+
"pathname": "/Org/Repo",
315+
"branch": "",
316+
"protocol": "https",
317+
"protocols": ["https"],
318+
"platform": "bitbucket",
319+
},
320+
),
321+
),
322+
(
323+
"HTTPS",
324+
(
325+
"https://bitbucket.com/Org/Repo",
326+
{
327+
"host": "bitbucket.com",
328+
"resource": "bitbucket.com",
329+
"user": "git",
330+
"port": "",
331+
"owner": "Org",
332+
"repo": "Repo",
333+
"name": "Repo",
334+
"groups": [],
335+
"path": "",
336+
"path_raw": "",
337+
"pathname": "/Org/Repo",
338+
"branch": "",
339+
"protocol": "https",
340+
"protocols": ["https"],
341+
"platform": "bitbucket",
342+
},
343+
),
344+
),
276345
# Gitlab
277346
(
278347
"SSH",

0 commit comments

Comments
 (0)