fix(api): avoid slow weekly git fallback
This commit is contained in:
@@ -58,6 +58,7 @@ class TestWeeklyReportGitStats:
|
||||
)
|
||||
|
||||
svc = WeeklyReportService(stats_service=object(), k3s_monitor=object())
|
||||
monkeypatch.setattr(svc, "_has_local_git_worktree", lambda cwd: True)
|
||||
monkeypatch.setattr(svc, "_get_gitea_commit_stats", lambda since: (0, 0, False))
|
||||
commits, deploys, source_ok = svc._get_git_stats(datetime.now(_TZ_TAIPEI))
|
||||
|
||||
@@ -78,6 +79,7 @@ class TestWeeklyReportGitStats:
|
||||
)
|
||||
|
||||
svc = WeeklyReportService(stats_service=object(), k3s_monitor=object())
|
||||
monkeypatch.setattr(svc, "_has_local_git_worktree", lambda cwd: True)
|
||||
monkeypatch.setattr(svc, "_get_gitea_commit_stats", lambda since: (12, 4, True))
|
||||
commits, deploys, source_ok = svc._get_git_stats(datetime.now(_TZ_TAIPEI))
|
||||
|
||||
@@ -105,6 +107,7 @@ class TestWeeklyReportGitStats:
|
||||
monkeypatch.setattr(weekly_report_module.subprocess, "run", fake_run)
|
||||
|
||||
svc = WeeklyReportService(stats_service=object(), k3s_monitor=object())
|
||||
monkeypatch.setattr(svc, "_has_local_git_worktree", lambda cwd: True)
|
||||
monkeypatch.setattr(svc, "_get_gitea_commit_stats", lambda since: (0, 0, False))
|
||||
commits, deploys, source_ok = svc._get_git_stats(datetime.now(_TZ_TAIPEI))
|
||||
|
||||
@@ -112,6 +115,21 @@ class TestWeeklyReportGitStats:
|
||||
assert deploys == 0
|
||||
assert source_ok is False
|
||||
|
||||
def test_missing_local_git_worktree_uses_gitea_without_subprocess(self, monkeypatch):
|
||||
def fail_run(*_args, **_kwargs):
|
||||
raise AssertionError("subprocess git log should not run without local .git")
|
||||
|
||||
monkeypatch.setattr(weekly_report_module.subprocess, "run", fail_run)
|
||||
|
||||
svc = WeeklyReportService(stats_service=object(), k3s_monitor=object())
|
||||
monkeypatch.setattr(svc, "_has_local_git_worktree", lambda cwd: False)
|
||||
monkeypatch.setattr(svc, "_get_gitea_commit_stats", lambda since: (21, 7, True))
|
||||
commits, deploys, source_ok = svc._get_git_stats(datetime.now(_TZ_TAIPEI))
|
||||
|
||||
assert commits == 21
|
||||
assert deploys == 7
|
||||
assert source_ok is True
|
||||
|
||||
def test_gitea_commit_stats_counts_deploy_markers(self, monkeypatch):
|
||||
payload = [
|
||||
{"commit": {"message": "chore(cd): deploy abc123 [skip ci]\n"}},
|
||||
@@ -131,7 +149,7 @@ class TestWeeklyReportGitStats:
|
||||
|
||||
def fake_urlopen(request, timeout):
|
||||
assert "/api/v1/repos/wooo/awoooi/commits?" in request.full_url
|
||||
assert timeout == 8
|
||||
assert timeout == 3
|
||||
return Response()
|
||||
|
||||
monkeypatch.setattr(weekly_report_module, "urlopen", fake_urlopen)
|
||||
|
||||
Reference in New Issue
Block a user