Skip to content

Commit 0b7222a

Browse files
mnriemCopilot
andcommitted
refactor: deduplicate release URL resolution; fix test issues
- ExtensionCatalog._resolve_github_release_asset_api_url now delegates to the shared helper in _github_http.py (also gains URL-encoding fix) - Remove unused 'io' import from test_github_http.py - Remove duplicate 'provides' dict keys accidentally added to test_presets.py Co-authored-by: Copilot <[email protected]>
1 parent 4943ef0 commit 0b7222a

3 files changed

Lines changed: 7 additions & 46 deletions

File tree

‎src/specify_cli/extensions.py‎

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,41 +1861,15 @@ def _resolve_github_release_asset_api_url(
18611861
download_url: str,
18621862
timeout: int = 60,
18631863
) -> Optional[str]:
1864-
"""Resolve a GitHub release asset URL to its API asset URL."""
1865-
import urllib.error
1866-
from urllib.parse import unquote, urlparse
1867-
1868-
parsed = urlparse(download_url)
1869-
parts = [unquote(part) for part in parsed.path.strip("/").split("/")]
1870-
if (
1871-
parsed.hostname == "api.github.com"
1872-
and len(parts) >= 6
1873-
and parts[:1] == ["repos"]
1874-
and parts[3:5] == ["releases", "assets"]
1875-
):
1876-
return download_url
1877-
1878-
if parsed.hostname != "github.com":
1879-
return None
1880-
1881-
if len(parts) < 6 or parts[2:4] != ["releases", "download"]:
1882-
return None
1883-
1884-
owner, repo, tag = parts[0], parts[1], parts[4]
1885-
asset_name = "/".join(parts[5:])
1886-
release_url = f"https://api.github.com/repos/{owner}/{repo}/releases/tags/{tag}"
1864+
"""Resolve a GitHub release asset URL to its API asset URL.
18871865
1888-
try:
1889-
with self._open_url(release_url, timeout=timeout) as response:
1890-
release_data = json.loads(response.read())
1891-
except (urllib.error.URLError, json.JSONDecodeError):
1892-
return None
1893-
1894-
for asset in release_data.get("assets", []):
1895-
if asset.get("name") == asset_name and asset.get("url"):
1896-
return str(asset["url"])
1866+
Delegates to the shared helper in :mod:`specify_cli._github_http`.
1867+
"""
1868+
from specify_cli._github_http import resolve_github_release_asset_api_url
18971869

1898-
return None
1870+
return resolve_github_release_asset_api_url(
1871+
download_url, self._open_url, timeout=timeout
1872+
)
18991873

19001874
def get_active_catalogs(self) -> List[CatalogEntry]:
19011875
"""Get the ordered list of active catalogs.

‎tests/test_github_http.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for GitHub-authenticated HTTP request helpers."""
22

3-
import io
43
import json
54
import os
65
from contextlib import contextmanager

‎tests/test_presets.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,6 @@ def test_extension_command_skipped_when_extension_missing(self, project_dir, tem
22392239
"description": "Test",
22402240
},
22412241
"requires": {"speckit_version": ">=0.1.0"},
2242-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
22432242
"provides": {
22442243
"templates": [
22452244
{
@@ -2284,7 +2283,6 @@ def test_extension_command_registered_when_extension_present(self, project_dir,
22842283
"description": "Test",
22852284
},
22862285
"requires": {"speckit_version": ">=0.1.0"},
2287-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
22882286
"provides": {
22892287
"templates": [
22902288
{
@@ -2544,7 +2542,6 @@ def _create_command_preset(self, temp_dir, preset_id, command_name, description,
25442542
"description": "Test",
25452543
},
25462544
"requires": {"speckit_version": ">=0.1.0"},
2547-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
25482545
"provides": {
25492546
"templates": [
25502547
{
@@ -2702,7 +2699,6 @@ def test_extension_restore_resolves_command_refs(self, project_dir, temp_dir):
27022699
"description": "Test",
27032700
},
27042701
"requires": {"speckit_version": ">=0.1.0"},
2705-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
27062702
"provides": {
27072703
"commands": [
27082704
{
@@ -2756,7 +2752,6 @@ def test_core_command_override_skill_uses_preset_command_description(self, proje
27562752
"description": "Test",
27572753
},
27582754
"requires": {"speckit_version": ">=0.1.0"},
2759-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
27602755
"provides": {
27612756
"templates": [
27622757
{
@@ -2997,7 +2992,6 @@ def test_extension_skill_override_matches_hyphenated_multisegment_name(self, pro
29972992
"description": "Test",
29982993
},
29992994
"requires": {"speckit_version": ">=0.1.0"},
3000-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
30012995
"provides": {
30022996
"templates": [
30032997
{
@@ -3050,7 +3044,6 @@ def test_extension_skill_restored_on_preset_remove(self, project_dir, temp_dir):
30503044
"description": "Test",
30513045
},
30523046
"requires": {"speckit_version": ">=0.1.0"},
3053-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
30543047
"provides": {
30553048
"commands": [
30563049
{
@@ -3079,7 +3072,6 @@ def test_extension_skill_restored_on_preset_remove(self, project_dir, temp_dir):
30793072
"description": "Test",
30803073
},
30813074
"requires": {"speckit_version": ">=0.1.0"},
3082-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
30833075
"provides": {
30843076
"templates": [
30853077
{
@@ -3133,7 +3125,6 @@ def test_preset_remove_skips_skill_dir_without_skill_file(self, project_dir, tem
31333125
"description": "Test",
31343126
},
31353127
"requires": {"speckit_version": ">=0.1.0"},
3136-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
31373128
"provides": {
31383129
"templates": [
31393130
{
@@ -3230,7 +3221,6 @@ def test_kimi_new_skill_created_even_when_ai_skills_disabled(self, project_dir,
32303221
"description": "Test",
32313222
},
32323223
"requires": {"speckit_version": ">=0.1.0"},
3233-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
32343224
"provides": {
32353225
"templates": [
32363226
{
@@ -3284,7 +3274,6 @@ def test_kimi_preset_skill_override_resolves_script_placeholders(self, project_d
32843274
"description": "Test",
32853275
},
32863276
"requires": {"speckit_version": ">=0.1.0"},
3287-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
32883277
"provides": {
32893278
"templates": [
32903279
{
@@ -3341,7 +3330,6 @@ def test_agy_skill_restored_on_preset_remove(self, project_dir, temp_dir):
33413330
"description": "Test",
33423331
},
33433332
"requires": {"speckit_version": ">=0.1.0"},
3344-
"provides": {"templates": [{"type": "template", "name": "t", "file": "templates/t.md", "description": "t"}]},
33453333
"provides": {
33463334
"templates": [
33473335
{

0 commit comments

Comments
 (0)