DEVX-1: fix: add User-Agent header to _download in install_tools

This commit is contained in:
emo
2026-08-03 14:40:51 +00:00
parent 004b890463
commit aa93e894a6
4 changed files with 15 additions and 5 deletions
+2 -2
View File
@@ -90,7 +90,7 @@ jobs:
if: github.event_name == 'pull_request'
env:
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
DEVX_VIKUNJA_PROJECT_ID: "8"
DEVX_VIKUNJA_PROJECT_ID: "2"
HEAD_REF: ${{ github.head_ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
REPOSITORY: ${{ github.repository }}
@@ -173,7 +173,7 @@ jobs:
env:
CI_GITEA_API_TOKEN: ${{ secrets.CI_GITEA_API_TOKEN }}
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
DEVX_VIKUNJA_PROJECT_ID: "8"
DEVX_VIKUNJA_PROJECT_ID: "2"
HEAD_REF: ${{ github.head_ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
REPOSITORY: ${{ github.repository }}
+1 -1
View File
@@ -152,7 +152,7 @@ jobs:
if: needs.detect-and-configure.outputs.is-automated == 'false'
env:
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
DEVX_VIKUNJA_PROJECT_ID: "8"
DEVX_VIKUNJA_PROJECT_ID: "2"
run: |
. .venv/bin/activate 2>/dev/null || true
python3 -m devx.ci.post_merge --git-sha "${{ github.sha }}"
+7 -2
View File
@@ -65,8 +65,13 @@ def _ensure_target_dir() -> Path:
def _download(url: str, dest: Path) -> None:
"""Download a file from ``url`` to ``dest`` with a 60s timeout."""
with urllib.request.urlopen(url, timeout=60) as resp, open(dest, "wb") as f: # nosec B310
"""Download a file from ``url`` to ``dest`` with a 60s timeout.
A User-Agent header is set because some CDNs (e.g. dl.gitea.com)
return 403 to requests with Python's default User-Agent.
"""
req = urllib.request.Request(url, headers={"User-Agent": "devx/install-tools"})
with urllib.request.urlopen(req, timeout=60) as resp, open(dest, "wb") as f: # nosec B310
shutil.copyfileobj(resp, f)
+5
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import platform
import urllib.request
from pathlib import Path
from unittest.mock import patch
@@ -66,6 +67,10 @@ class TestDownload:
with patch("urllib.request.urlopen", return_value=_FakeResponse()) as mock_urlopen:
install_tools._download("https://example.com/file", dest)
mock_urlopen.assert_called_once()
call_args = mock_urlopen.call_args
req = call_args.args[0]
assert isinstance(req, urllib.request.Request)
assert req.get_header("User-agent") == "devx/install-tools"
assert dest.read_bytes() == b"data"