Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/bump-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
import sys

sys.path.append("../../")
from clang_tools import release_tag # noqa E402
from clang_tools import binary_repo, binary_tag # noqa E402


def get_latest_tag() -> str:
response = requests.get(
"https://api.github.com/repos/cpp-linter/clang-tools-static-binaries/releases/latest"
)
response = requests.get(f"{binary_repo}/releases/latest")
Copy link

Copilot AI Aug 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requests module is used but not imported. Add import requests at the top of the file.

Copilot uses AI. Check for mistakes.

return response.json()["tag_name"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix JSONDecodeError: use GitHub API URL, add timeout/auth, and robust error handling.

https://github.com/.../releases/latest returns HTML; parsing as JSON fails in CI. Normalize binary_repo to the GitHub API endpoint, add a timeout, pass GITHUB_TOKEN when available, and validate the response.

Apply this diff:

-def get_latest_tag() -> str:
-    response = requests.get(f"{binary_repo}/releases/latest")
-    return response.json()["tag_name"]
+def get_latest_tag() -> str:
+    # Normalize to GitHub API URL
+    from urllib.parse import urlparse
+    import os
+    repo = binary_repo.rstrip("/")
+    parsed = urlparse(repo)
+    if "api.github.com" in parsed.netloc:
+        api_url = f"{repo}/releases/latest"
+    elif "github.com" in parsed.netloc:
+        parts = [p for p in parsed.path.split("/") if p]
+        if len(parts) < 2:
+            raise ValueError(f"Invalid binary_repo: {binary_repo}")
+        owner, name = parts[0], parts[1]
+        api_url = f"https://api.github.com/repos/{owner}/{name}/releases/latest"
+    else:
+        raise ValueError(f"Unsupported host in binary_repo: {binary_repo}")
+    headers = {"Accept": "application/vnd.github+json"}
+    token = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN")
+    if token:
+        headers["Authorization"] = f"Bearer {token}"
+    resp = requests.get(api_url, headers=headers, timeout=15)
+    resp.raise_for_status()
+    data = resp.json()
+    tag = data.get("tag_name")
+    if not tag:
+        raise RuntimeError(f"Missing tag_name in response: {data}")
+    return tag
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
response = requests.get(f"{binary_repo}/releases/latest")
return response.json()["tag_name"]
def get_latest_tag() -> str:
# Normalize to GitHub API URL
from urllib.parse import urlparse
import os
repo = binary_repo.rstrip("/")
parsed = urlparse(repo)
if "api.github.com" in parsed.netloc:
api_url = f"{repo}/releases/latest"
elif "github.com" in parsed.netloc:
parts = [p for p in parsed.path.split("/") if p]
if len(parts) < 2:
raise ValueError(f"Invalid binary_repo: {binary_repo}")
owner, name = parts[0], parts[1]
api_url = f"https://api.github.com/repos/{owner}/{name}/releases/latest"
else:
raise ValueError(f"Unsupported host in binary_repo: {binary_repo}")
headers = {"Accept": "application/vnd.github+json"}
token = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN")
if token:
headers["Authorization"] = f"Bearer {token}"
resp = requests.get(api_url, headers=headers, timeout=15)
resp.raise_for_status()
data = resp.json()
tag = data.get("tag_name")
if not tag:
raise RuntimeError(f"Missing tag_name in response: {data}")
return tag
🧰 Tools
🪛 Ruff (0.12.2)

9-9: Probable use of requests call without timeout

(S113)

🪛 GitHub Actions: Bump clang-tools binaries version

[error] 10-10: JSONDecodeError: Expecting value: line 8 column 1 (char 7) while parsing API response in get_latest_tag() (response.json() call).

🤖 Prompt for AI Agents
In .github/workflows/bump-version.py around lines 9-10, change the call that
GETs "{binary_repo}/releases/latest" (which returns HTML) to call the GitHub API
releases endpoint instead, add a timeout, include an Authorization header when
GITHUB_TOKEN is set, and robustly validate the response and JSON. Specifically,
normalize binary_repo into an API URL like
"https://api.github.com/repos/{owner}/{repo}/releases/latest", call requests.get
with headers {"Accept":"application/vnd.github.v3+json", "Authorization":
f"token {GITHUB_TOKEN}"} only if the token exists, and a reasonable timeout
(e.g., 10s); check response.status_code == 200, attempt response.json() inside
try/except to catch JSONDecodeError and requests.RequestException, verify the
JSON contains "tag_name" before returning it, and raise or log a clear error if
any step fails.



Expand All @@ -25,7 +23,7 @@ def update_tag(current_tag, latest_tag) -> None:

if __name__ == "__main__":
latest_tag = get_latest_tag()
current_tag = release_tag
current_tag = binary_tag

if latest_tag != current_tag:
update_tag(current_tag, latest_tag)
Expand Down
Loading