diff --git a/server.py b/server.py index f1585b5..115a175 100644 --- a/server.py +++ b/server.py @@ -355,19 +355,30 @@ async def get_workflow_run_logs( run_status = target_run.get("status") run_title = target_run.get("display_title", "") - # Step 2: Get jobs for this run to find the job ID - # Note: Gitea's API uses the internal run ID, not run_number for jobs endpoint - jobs_result = await client.request("GET", f"/repos/{owner}/{repo}/actions/runs/{run_id}/jobs") + # Step 2: Get jobs list and find the job matching this run_number + # 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/jobs") job_id = None if isinstance(jobs_result, dict): jobs = jobs_result.get("jobs", []) - if jobs: - job_id = jobs[0].get("id") + # Find job whose html_url contains /runs/{run_number}/ + 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: - 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 logs_result = await client.request("GET", f"/repos/{owner}/{repo}/actions/jobs/{job_id}/logs")