Skip to content

Commit 45f2ca6

Browse files
committed
Simplify extract_github_host
1 parent 0a187b8 commit 45f2ca6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

coverage_comment/github.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io
55
import json
66
import pathlib
7+
import re
78
import sys
89
import zipfile
910
from urllib.parse import urlparse
@@ -63,13 +64,10 @@ def extract_github_host(api_url: str) -> str:
6364
scheme = parsed_url.scheme
6465
netloc = parsed_url.netloc # This includes the domain and potentially the port
6566

66-
# Special case for GitHub.com API
67-
if netloc == "api.github.com":
68-
host_domain = "github.com"
69-
# Special case for GitHub.com with port (less common but good practice)
70-
elif netloc.startswith("api.github.com:"):
67+
# Special case for GitHub.com API (including possible port)
68+
if re.match(r"api\.github\.com(:|$)", netloc):
7169
# Remove 'api.' prefix but keep the port
72-
host_domain = netloc.replace("api.", "", 1)
70+
host_domain = netloc.removeprefix("api.")
7371
# General case for GitHub Enterprise (netloc is already the host:port)
7472
else:
7573
host_domain = netloc

0 commit comments

Comments
 (0)