Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine Lambert
swh-core
Commits
98fe7fe8
Commit
98fe7fe8
authored
2 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Fix _sanitize_github_url removing suffixes too greedily
.rstrip() is not .removesuffix()
parent
6a5ad761
No related branches found
Branches containing commit
Tags
v2.16.1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/core/github/tests/test_github_utils.py
+6
-0
6 additions, 0 deletions
swh/core/github/tests/test_github_utils.py
swh/core/github/utils.py
+6
-1
6 additions, 1 deletion
swh/core/github/utils.py
with
12 additions
and
1 deletion
swh/core/github/tests/test_github_utils.py
+
6
−
0
View file @
98fe7fe8
...
...
@@ -16,6 +16,7 @@ from swh.core.github.utils import (
)
KNOWN_GH_REPO
=
"
https://github.com/user/repo
"
KNOWN_GH_REPO2
=
"
https://github.com/user/reposit
"
@pytest.mark.parametrize
(
...
...
@@ -26,6 +27,11 @@ KNOWN_GH_REPO = "https://github.com/user/repo"
(
"
user/repo/
"
,
KNOWN_GH_REPO
),
(
"
user/repo
"
,
KNOWN_GH_REPO
),
(
"
user/repo/.git
"
,
KNOWN_GH_REPO
),
(
"
user/reposit.git
"
,
KNOWN_GH_REPO2
),
(
"
user/reposit.git/
"
,
KNOWN_GH_REPO2
),
(
"
user/reposit/
"
,
KNOWN_GH_REPO2
),
(
"
user/reposit
"
,
KNOWN_GH_REPO2
),
(
"
user/reposit/.git
"
,
KNOWN_GH_REPO2
),
(
"
unknown/page
"
,
None
),
# unknown gh origin returns None
(
"
user/with/deps
"
,
None
),
# url kind is not dealt with
],
...
...
This diff is collapsed.
Click to expand it.
swh/core/github/utils.py
+
6
−
1
View file @
98fe7fe8
...
...
@@ -32,9 +32,14 @@ def _url_github_api(user_repo: str) -> str:
return
f
"
https://api.github.com/repos/
{
user_repo
}
"
_SANITIZATION_RE
=
re
.
compile
(
r
"
^(.*?)/?(\.git)?/?$
"
)
def
_sanitize_github_url
(
url
:
str
)
->
str
:
"""
Sanitize github url.
"""
return
url
.
lower
().
rstrip
(
"
/
"
).
rstrip
(
"
.git
"
).
rstrip
(
"
/
"
)
m
=
_SANITIZATION_RE
.
match
(
url
.
lower
())
assert
m
is
not
None
,
url
# impossible, but mypy doesn't know it
return
m
.
group
(
1
)
def
get_canonical_github_origin_url
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment