fix(api): cap weekly gitea stats readback
This commit is contained in:
@@ -162,12 +162,14 @@ class WeeklyReportService:
|
||||
deploys = 0
|
||||
page = 1
|
||||
limit = 50
|
||||
max_pages = 4
|
||||
try:
|
||||
for api_url in self._gitea_api_candidates():
|
||||
commits = deploys = 0
|
||||
page = 1
|
||||
total_commits: int | None = None
|
||||
try:
|
||||
while page <= 20:
|
||||
while page <= max_pages:
|
||||
query = urlencode({
|
||||
"sha": "main",
|
||||
"since": since_utc,
|
||||
@@ -177,6 +179,9 @@ class WeeklyReportService:
|
||||
url = f"{api_url}/api/v1/repos/{owner}/{repo}/commits?{query}"
|
||||
request = Request(url, headers=headers)
|
||||
with urlopen(request, timeout=3) as response:
|
||||
total_header = response.headers.get("X-Total-Count") or response.headers.get("X-Total")
|
||||
if total_header and total_header.isdigit():
|
||||
total_commits = int(total_header)
|
||||
payload = json.loads(response.read().decode("utf-8"))
|
||||
if not isinstance(payload, list):
|
||||
logger.warning("gitea_git_stats_unexpected_payload", payload_type=type(payload).__name__)
|
||||
@@ -189,8 +194,16 @@ class WeeklyReportService:
|
||||
if "deploy" in subject or subject.startswith("chore(cd):"):
|
||||
deploys += 1
|
||||
if len(payload) < limit:
|
||||
return commits, deploys, True
|
||||
return total_commits or commits, deploys, True
|
||||
page += 1
|
||||
if total_commits is not None and total_commits > 0:
|
||||
logger.info(
|
||||
"gitea_git_stats_sampled",
|
||||
total_commits=total_commits,
|
||||
sampled_pages=max_pages,
|
||||
sampled_deploys=deploys,
|
||||
)
|
||||
return total_commits, deploys, True
|
||||
except Exception as candidate_exc:
|
||||
logger.warning(
|
||||
"gitea_git_stats_candidate_failed",
|
||||
|
||||
Reference in New Issue
Block a user