Skip to content

Commit 033a3d2

Browse files
fix: improve exception for issue comments (#6796)
1 parent 93e18c4 commit 033a3d2

3 files changed

Lines changed: 70 additions & 11 deletions

File tree

.github/workflows/ci-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: CI Tests
33
permissions: {}
44

55
env:
6+
NODE_VERSION: '24'
67
PYTHON_VERSION: '3.14'
78

89
on:
@@ -28,7 +29,7 @@ jobs:
2829
- name: Setup Node
2930
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
3031
with:
31-
node-version: latest
32+
node-version: ${{ env.NODE_VERSION }}
3233

3334
- name: Install uv
3435
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0

src/updater.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,13 @@ def _load_tmdb_item_data(item_type: str, item_id: Union[int, str]) -> tuple[str,
10291029

10301030
if response.status_code == 404:
10311031
_remove_stale_tmdb_file(database_path=database_path, item_type=item_type, item_id=item_id)
1032+
if getattr(args, 'issue_update', False):
1033+
exception_writer(
1034+
error=Exception(
1035+
f'Error processing TMDB url: {item_type} id {item_id} not found or unavailable',
1036+
),
1037+
name='tmdb',
1038+
)
10321039
return database_path, item_id, {}
10331040

10341041
if response.status_code != 200:
@@ -1410,15 +1417,18 @@ def update_contributor_info(original: bool, base_dir: str) -> None:
14101417
def _load_issue_submission_values(database_url: Optional[str],
14111418
youtube_url: Optional[str]) -> tuple[Optional[str], Optional[str], dict]:
14121419
"""Load missing issue-update values from the submission file."""
1413-
if database_url and youtube_url:
1414-
return database_url, youtube_url, {}
1420+
issue_submission = {}
1421+
if not database_url or not youtube_url:
1422+
issue_submission = process_submission()
14151423

1416-
issue_submission = process_submission()
14171424
if not database_url:
14181425
database_url = issue_submission['database_url'].strip()
14191426

14201427
if not youtube_url:
1421-
youtube_url = check_youtube(data=issue_submission)
1428+
youtube_url = issue_submission['youtube_theme_url']
1429+
1430+
if youtube_url:
1431+
youtube_url = check_youtube(data={'youtube_theme_url': youtube_url})
14221432

14231433
return database_url, youtube_url, issue_submission
14241434

@@ -1454,13 +1464,13 @@ def process_issue_update(database_url: Optional[str] = None, youtube_url: Option
14541464

14551465
item_type, item_id, exceptions = _match_database_url(database_url=database_url)
14561466
if item_type:
1457-
process_item_id(
1467+
data = process_item_id(
14581468
item_type=item_type,
14591469
item_id=item_id,
14601470
youtube_url=youtube_url,
14611471
issue_submission=issue_submission,
14621472
)
1463-
return item_type
1473+
return item_type if data else False
14641474

14651475
# if we get here, we didn't find a match
14661476
for exception in exceptions:

tests/unit/test_issue_updater.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,16 +500,17 @@ def test_write_item_files_writes_primary_and_imdb_copy(tmp_path, monkeypatch):
500500

501501

502502
def test_load_issue_submission_values_uses_supplied_values(monkeypatch):
503-
"""Test fully supplied issue-update values bypass submission processing."""
503+
"""Test fully supplied issue-update values bypass submission loading but still validate YouTube."""
504504
monkeypatch.setattr(
505505
updater,
506506
'process_submission',
507507
lambda: pytest.fail('submission file should not be read'),
508508
)
509+
monkeypatch.setattr(updater, 'check_youtube', lambda data: f"canonical-{data['youtube_theme_url']}")
509510

510511
assert updater._load_issue_submission_values(database_url='database-url', youtube_url='youtube-url') == (
511512
'database-url',
512-
'youtube-url',
513+
'canonical-youtube-url',
513514
{},
514515
)
515516

@@ -564,6 +565,7 @@ def test_process_issue_update(
564565
issue_update_args,
565566
mock_igdb_api,
566567
mock_tmdb_api,
568+
mock_youtube_api,
567569
youtube_url,
568570
tmp_path,
569571
monkeypatch,
@@ -1273,7 +1275,7 @@ def test_update_contributor_info_increments_existing_edit(tmp_path, monkeypatch)
12731275
}
12741276

12751277

1276-
def test_process_issue_update_reports_unsupported_database_url(tmp_path, monkeypatch, youtube_url):
1278+
def test_process_issue_update_reports_unsupported_database_url(tmp_path, monkeypatch, mock_youtube_api, youtube_url):
12771279
"""Test that unsupported database URLs report every regex miss."""
12781280
monkeypatch.chdir(tmp_path)
12791281

@@ -1284,10 +1286,12 @@ def test_process_issue_update_reports_unsupported_database_url(tmp_path, monkeyp
12841286

12851287
assert result is False
12861288
exceptions = (tmp_path / 'exceptions.md').read_text()
1289+
comment = (tmp_path / 'comment.md').read_text(encoding='utf-8')
12871290
assert exceptions.count('Exception Occurred') == 6
1291+
assert comment.count('Exception Occurred') == 6
12881292

12891293

1290-
def test_process_issue_update_writes_author_badges_first(tmp_path, monkeypatch, youtube_url):
1294+
def test_process_issue_update_writes_author_badges_first(tmp_path, monkeypatch, mock_youtube_api, youtube_url):
12911295
"""Test issue update comments start with the author badges."""
12921296
monkeypatch.chdir(tmp_path)
12931297
monkeypatch.setenv('GITHUB_REPOSITORY', 'LizardByte/ThemerrDB')
@@ -1315,6 +1319,50 @@ def test_process_issue_update_writes_author_badges_first(tmp_path, monkeypatch,
13151319
assert 'Exception Occurred' in comment
13161320

13171321

1322+
def test_process_issue_update_reports_invalid_supplied_youtube_url(tmp_path, monkeypatch):
1323+
"""Test supplied invalid YouTube URLs are written to the issue comment."""
1324+
monkeypatch.chdir(tmp_path)
1325+
1326+
result = updater.process_issue_update(
1327+
database_url='https://www.igdb.com/games/goldeneye-007',
1328+
youtube_url='https://www.youtube.com/watch?v=invalid',
1329+
)
1330+
1331+
comment = (tmp_path / 'comment.md').read_text(encoding='utf-8')
1332+
assert result is False
1333+
assert 'Could not extract video ID from URL' in comment
1334+
1335+
1336+
def test_process_issue_update_reports_tmdb_not_found_in_comment(
1337+
tmp_path,
1338+
monkeypatch,
1339+
issue_update_args,
1340+
mock_youtube_api,
1341+
youtube_url,
1342+
):
1343+
"""Test issue-update TMDB 404 responses are written to the issue comment."""
1344+
monkeypatch.chdir(tmp_path)
1345+
monkeypatch.setenv('TMDB_API_KEY_V3', 'test-key')
1346+
monkeypatch.setitem(
1347+
updater.databases['movie'],
1348+
'path',
1349+
str(tmp_path / 'database' / 'movies' / 'themoviedb'),
1350+
)
1351+
1352+
response = MagicMock()
1353+
response.status_code = 404
1354+
monkeypatch.setattr(updater, 'requests_loop', lambda **kwargs: response)
1355+
1356+
result = updater.process_issue_update(
1357+
database_url='https://www.themoviedb.org/movie/42903-missing',
1358+
youtube_url=youtube_url,
1359+
)
1360+
1361+
comment = (tmp_path / 'comment.md').read_text(encoding='utf-8')
1362+
assert result is False
1363+
assert 'Error processing TMDB url: movie id 42903 not found or unavailable' in comment
1364+
1365+
13181366
def mock_youtube_build(monkeypatch, response=None, exception=None):
13191367
"""Patch googleapiclient discovery build with a fake YouTube service."""
13201368
class Request:

0 commit comments

Comments
 (0)