Skip to content

Commit

Permalink
Strip "www." prefix for hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 11, 2023
1 parent 2287a30 commit 87a34a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,28 @@ def get_item(string: str) -> Item | None:
Get Item from string
"""
if "#" not in string:
# URL
string = string if string.startswith("https://") else f"https://{string}"
url = urlparse(string)
assert url.hostname is not None
hostname = url.hostname.removeprefix("www.") if url.hostname is not None else ""
repo: str = ""
if url.hostname.startswith("git"):
if hostname.startswith("git"):
repo = os.path.dirname(
os.path.dirname(url.path.replace("/-/", "/"))
).lstrip("/")
issue_id = os.path.basename(url.path)
elif url.hostname.startswith("bugzilla"):
elif hostname.startswith("bugzilla"):
issue_id = parse_qs(url.query)["id"][0]
elif url.hostname == "progress.opensuse.org":
elif hostname == "progress.opensuse.org":
issue_id = os.path.basename(url.path)
else:
return None
return Item(
item_id=int(issue_id),
host=url.hostname,
host=hostname,
repo=repo,
)
# Tag
try:
code, repo, issue = string.split("#", 2)
except ValueError:
Expand Down
7 changes: 7 additions & 0 deletions test_bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def test_get_item_with_gsd_url():
assert item.__dict__ == expected_item.__dict__


def test_get_item_with_www_prefix():
url = "https://gitlab.com/gitlab-org/gitlab/-/issues/424503"
item = get_item(url)
expected_item = Item(item_id=424503, host="gitlab.com", repo="gitlab-org/gitlab")
assert item.__dict__ == expected_item.__dict__


# Test case for an unsupported format
def test_get_item_with_unsupported_format():
string = "unsupported#12345"
Expand Down

0 comments on commit 87a34a9

Please sign in to comment.