获取失败的PR检查

MotleyAI2026-10-27查看 916复制 651

当用户要求在 GitHub PR 上检查/获取/列出/显示失败的 CI 检查(GitHub 操作、外部 CI)时使用 - 包括失败的详细信息/日志。拉取 statusCheckRollup,过滤到未通过的终端状态,并(对于 GitHub Actions 运行)附加失败步骤日志摘录。

Download (.md)

📘如何使用这个技能

  1. 1
    复制技能内容·点击上方「Copy SKILL.md」复制全部内容,或 Download 下载到本地
  2. 2
    打开你的 AI 客户端·支持 Claude Code、Trae、Cursor、ChatGPT、DeepSeek、Kimi 等任意 AI 助手
  3. 3
    粘贴为系统提示/知识文件·Claude Code:放入 .claude/skills/ 目录;普通对话:作为首条消息发送并说「请严格按这份技能文档执行」
  4. 4
    直接提出你的需求·AI 会按技能定义的工作流、格式和约束来处理,无需再解释背景

💡 提示:技能生效后,每次对话只需一句需求,AI 会按 SKILL.md 的流程执行。

SKILL.md3225 chars
---
name: fetch-failed-pr-checks
description: Use when the user asks to check / fetch / list / show failed CI checks (GitHub Actions, external CI) on a GitHub PR — including details/logs of the failures. Pulls the statusCheckRollup, filters to non-passing terminal states, and (for GitHub Actions runs) appends the failed-step log excerpt.
---

**Preflight:** run `la-doctor --plugin <this skill's base directory>` once per session before using any `la-*` or `dr-*` command; if it fails, stop and show the user its output.

# Fetch failed CI checks (and their failed-step logs) for a PR

## How to run

```bash
la-fetch-failed-pr-checks <PR_NUMBER> [--repo OWNER/REPO] [--max-log-lines N]
```

- `<PR_NUMBER>` — required.
- `--repo OWNER/REPO` — optional; defaults to the cwd repo via `gh repo view`.
- `--max-log-lines N` — cap each failed job's log excerpt at N lines (default 200). Pass `0` to skip log fetching entirely.

## Output

Always emits **both**:

- **Markdown to stdout** — one section per failed check: workflow / job name, conclusion, details URL, and (when available) the failed-step log excerpt inside a collapsible `<details>` block.
- **JSON file** at `${TMPDIR:-/tmp}/failed-pr-checks-<pr>-<utc-ts>.json`. Path printed on the last line, prefixed `JSON: `. Schema:

  ```json
  {
    "pr": 70,
    "repo": "owner/name",
    "failed_checks": [
      {
        "typename": "CheckRun" | "StatusContext" | "WorkflowRun",
        "name": "test",
        "workflow_name": "CI",
        "conclusion": "FAILURE",
        "status": "COMPLETED",
        "details_url": "https://github.com/.../actions/runs/12345/job/67890",
        "completed_at": "2026-05-03T07:42:13Z",
        "run_id": "12345",
        "job_id": "67890",
        "log_excerpt": "..."
      }
    ]
  }
  ```

## What counts as "failed"

Any check whose `conclusion` (CheckRun/WorkflowRun) or `state` (StatusContext) is one of:

- `FAILURE`
- `TIMED_OUT`
- `CANCELLED`
- `ACTION_REQUIRED`
- `STARTUP_FAILURE`
- `ERROR` (StatusContext only)

In-progress / pending / skipped checks are excluded.

## Steps

1. Run the script with the PR number the user gave (or infer from `gh pr view --json number -q .number`).
2. Read the Markdown output and present a concise summary — count, which workflows / jobs failed, the most likely root cause if visible in the log excerpt.
3. The log excerpt is `--log-failed` filtered (falling back to the full log's tail when no step is marked failed), so it already targets failing steps. If the default 200-line excerpt isn't enough, re-run with a larger `--max-log-lines` (e.g. `--max-log-lines 1000`). Don't reach for `gh run view --log` directly — keep this workflow inside the command.

## Why use this instead of `gh pr checks` / `gh run view` directly

- One call gives you all failed checks plus their failed-step logs, in both Markdown and JSON form.
- Handles the three `statusCheckRollup` typenames (CheckRun / StatusContext / WorkflowRun) — `gh pr checks` doesn't expose StatusContext cleanly.
- Truncated logs (default 200 lines per job) keep output bounded; raise with `--max-log-lines` when you need more.

If the command is missing a flag you need, extend it rather than reaching for `gh` directly.
来源:skillsdirectory

评论0

登录后参与评论

还没有评论,来抢沙发吧