fix: correct job ID discovery for workflow logs
All checks were successful
Build and Push Gitea MCP Docker Image / build (push) Successful in 19s

Gitea uses different ID namespaces for tasks vs jobs. Now searches
the /actions/jobs endpoint and matches by html_url containing the
run_number to find the correct job_id for logs retrieval.
This commit is contained in:
Ben
2025-12-22 14:40:04 +00:00
parent d43cc4717c
commit 7c4b35dc68

View File

@@ -355,19 +355,30 @@ async def get_workflow_run_logs(
run_status = target_run.get("status") run_status = target_run.get("status")
run_title = target_run.get("display_title", "") run_title = target_run.get("display_title", "")
# Step 2: Get jobs for this run to find the job ID # Step 2: Get jobs list and find the job matching this run_number
# Note: Gitea's API uses the internal run ID, not run_number for jobs endpoint # Note: Gitea's jobs endpoint uses different IDs than tasks, so we match by html_url
jobs_result = await client.request("GET", f"/repos/{owner}/{repo}/actions/runs/{run_id}/jobs") jobs_result = await client.request("GET", f"/repos/{owner}/{repo}/actions/jobs")
job_id = None job_id = None
if isinstance(jobs_result, dict): if isinstance(jobs_result, dict):
jobs = jobs_result.get("jobs", []) jobs = jobs_result.get("jobs", [])
if jobs: # Find job whose html_url contains /runs/{run_number}/
job_id = jobs[0].get("id") run_url_pattern = f"/runs/{run_number}/"
for job in jobs:
html_url = job.get("html_url", "")
if run_url_pattern in html_url:
job_id = job.get("id")
break
# If jobs endpoint didn't work, try to use run_id as job_id (they're sometimes the same)
if not job_id: if not job_id:
job_id = run_id return json.dumps({
"run_number": run_number,
"run_id": run_id,
"status": run_status,
"title": run_title,
"error": "Could not find job ID for this run",
"detail": "The job may still be queued or the run data is not available"
})
# Step 3: Fetch the logs # Step 3: Fetch the logs
logs_result = await client.request("GET", f"/repos/{owner}/{repo}/actions/jobs/{job_id}/logs") logs_result = await client.request("GET", f"/repos/{owner}/{repo}/actions/jobs/{job_id}/logs")