Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(release): 兼容 CI 令牌的公开元数据读取

longmeidao60c410f92469
diff --git a/scripts/release_forge.py b/scripts/release_forge.py
index 02603974c..24481c307 100644
--- a/scripts/release_forge.py
+++ b/scripts/release_forge.py
@@ -35,7 +35,7 @@ class GitLabForge:
return json.loads(self.command(executable, "api", "--hostname", self.host,
"--method", "GET", path))
except subprocess.CalledProcessError as error:
- if "403" not in (error.stderr or ""):
+ if not any(status in (error.stderr or "") for status in ("401", "403")):
raise
# 公开项目的只读元数据可匿名取得,不扩大本机细粒度凭据权限。
request = Request(f"https://{self.host}/api/v4/{path}",
diff --git a/tests/test_scripts.py b/tests/test_scripts.py
index c56136a29..711af553c 100644
--- a/tests/test_scripts.py
+++ b/tests/test_scripts.py
@@ -4796,16 +4796,17 @@ class GitLabReleaseTests(unittest.TestCase):
def test_public_ci_metadata_does_not_require_expanding_token_permissions(self):
from scripts import release_forge
forge = self.forge()
- forge.command.side_effect = subprocess.CalledProcessError(1, ["glab"], stderr="glab: HTTP 403")
response = mock.MagicMock()
response.__enter__.return_value.read.return_value = b'[{"id":7}]'
- with mock.patch.dict(os.environ, {"PEACH_GLAB": "glab"}), \
- mock.patch.object(release_forge, "urlopen", return_value=response) as fetch:
- self.assertEqual(forge.api("owner/repo", "pipelines"), [{"id": 7}])
- request = fetch.call_args.args[0]
- self.assertEqual(request.full_url, "https://gitgud.io/api/v4/projects/owner%2Frepo/pipelines")
- self.assertNotIn("Private-token", request.headers)
- self.assertNotIn("Authorization", request.headers)
+ for status in (401, 403):
+ forge.command.side_effect = subprocess.CalledProcessError(1, ["glab"], stderr=f"glab: HTTP {status}")
+ with self.subTest(status=status), mock.patch.dict(os.environ, {"PEACH_GLAB": "glab"}), \
+ mock.patch.object(release_forge, "urlopen", return_value=response) as fetch:
+ self.assertEqual(forge.api("owner/repo", "pipelines"), [{"id": 7}])
+ request = fetch.call_args.args[0]
+ self.assertEqual(request.full_url, "https://gitgud.io/api/v4/projects/owner%2Frepo/pipelines")
+ self.assertNotIn("Private-token", request.headers)
+ self.assertNotIn("Authorization", request.headers)
forge.command.side_effect = subprocess.CalledProcessError(1, ["glab"], stderr="network unavailable")
with mock.patch.dict(os.environ, {"PEACH_GLAB": "glab"}), \
mock.patch.object(release_forge, "urlopen") as fetch, self.assertRaises(subprocess.CalledProcessError):