🐛 fix(gitea-fix-ci): trace workflow_run CI chains
This commit is contained in:
@@ -466,14 +466,30 @@ def _outcome(item: dict[str, Any]) -> str:
|
||||
return (conclusion or status).lower()
|
||||
|
||||
|
||||
def _workflow_name(run: dict[str, Any]) -> str:
|
||||
workflow = run.get("name") or run.get("workflow_id") or ""
|
||||
if workflow:
|
||||
return str(workflow)
|
||||
path = str(run.get("path") or "")
|
||||
return path.rsplit("@", 1)[0] if path else ""
|
||||
|
||||
|
||||
def _run_row(run: dict[str, Any]) -> dict[str, Any]:
|
||||
workflow = _workflow_name(run)
|
||||
return {
|
||||
"id": run.get("id"),
|
||||
"name": run.get("name") or run.get("workflow_id") or "",
|
||||
"name": workflow,
|
||||
"workflow": workflow,
|
||||
"path": run.get("path") or "",
|
||||
"title": run.get("display_title") or "",
|
||||
"outcome": _outcome(run),
|
||||
"event": run.get("event") or "",
|
||||
"branch": run.get("head_branch") or run.get("branch") or "",
|
||||
"sha": (run.get("head_sha") or run.get("commit_sha") or "")[:12],
|
||||
"sha": run.get("head_sha") or run.get("commit_sha") or "",
|
||||
"started_at": run.get("started_at") or "",
|
||||
"completed_at": run.get("completed_at") or "",
|
||||
"run_number": run.get("run_number"),
|
||||
"run_attempt": run.get("run_attempt"),
|
||||
"url": run.get("html_url") or run.get("url") or "",
|
||||
}
|
||||
|
||||
@@ -483,24 +499,30 @@ def cmd_runs(
|
||||
target: RepoTarget,
|
||||
client: ApiClient,
|
||||
) -> int:
|
||||
if args.sha and not re.fullmatch(r"[0-9a-fA-F]{40}", args.sha):
|
||||
raise ConfigError("--sha requires a full 40-character hexadecimal commit SHA")
|
||||
query: dict[str, str] = {}
|
||||
if args.branch:
|
||||
query["branch"] = args.branch
|
||||
if args.event:
|
||||
query["event"] = args.event
|
||||
if args.status:
|
||||
if args.status and args.status != "all":
|
||||
query["status"] = args.status
|
||||
if args.sha:
|
||||
query["head_sha"] = args.sha
|
||||
if args.limit:
|
||||
query["limit"] = str(args.limit)
|
||||
suffix = "/actions/runs"
|
||||
if args.workflow:
|
||||
workflow = urllib.parse.quote(args.workflow, safe="")
|
||||
suffix = f"/actions/workflows/{workflow}/runs"
|
||||
else:
|
||||
suffix = "/actions/runs"
|
||||
if query:
|
||||
suffix += "?" + urllib.parse.urlencode(query)
|
||||
payload = client.get_json(target.repo_path(suffix))
|
||||
runs = [_run_row(run) for run in _as_list(payload, "workflow_runs")]
|
||||
if args.sha:
|
||||
runs = [row for row in runs if row["sha"].startswith(args.sha[:12])]
|
||||
runs = [row for row in runs if row["sha"].lower() == args.sha.lower()]
|
||||
runs = runs[: args.limit] if args.limit else runs
|
||||
|
||||
if args.json:
|
||||
@@ -511,10 +533,20 @@ def cmd_runs(
|
||||
return 1
|
||||
print(f"{len(runs)} run(s):")
|
||||
for row in runs:
|
||||
number = f" number={row['run_number']}" if row["run_number"] else ""
|
||||
attempt = f" attempt={row['run_attempt']}" if row["run_attempt"] else ""
|
||||
print(
|
||||
f" run {row['id']} [{row['outcome']}] {row['name']} "
|
||||
f"{row['event']} {row['branch']} {row['sha']}"
|
||||
f" run {row['id']} [{row['outcome']}] {row['workflow']} "
|
||||
f"{row['event']} {row['branch']} {row['sha'][:12]}"
|
||||
f"{number}{attempt}"
|
||||
)
|
||||
if row["started_at"] or row["completed_at"]:
|
||||
print(
|
||||
f" started={row['started_at'] or '-'} "
|
||||
f"completed={row['completed_at'] or '-'}"
|
||||
)
|
||||
if row["title"]:
|
||||
print(f" title: {row['title']}")
|
||||
if row["url"]:
|
||||
print(f" {row['url']}")
|
||||
return 0
|
||||
@@ -651,10 +683,18 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
sub.add_parser("version", help="probe /api/v1/version")
|
||||
|
||||
runs = sub.add_parser("runs", help="list workflow runs")
|
||||
runs.add_argument(
|
||||
"--workflow",
|
||||
help="workflow file or ID (for example checks.yml)",
|
||||
)
|
||||
runs.add_argument("--branch")
|
||||
runs.add_argument("--event")
|
||||
runs.add_argument("--status", default="failure")
|
||||
runs.add_argument("--sha")
|
||||
runs.add_argument(
|
||||
"--status",
|
||||
default="failure",
|
||||
help="run outcome/status (default failure; use all to omit this filter)",
|
||||
)
|
||||
runs.add_argument("--sha", help="full triggering commit SHA")
|
||||
runs.add_argument("--limit", type=int, default=20)
|
||||
|
||||
jobs = sub.add_parser("jobs", help="list jobs of a run, flag failed ones")
|
||||
|
||||
Reference in New Issue
Block a user