gh-fix-ci

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Gh Pr Checks Plan Fix

Gh PR检查修复计划

Overview

概述

Use gh to locate failing PR checks, fetch GitHub Actions logs for actionable failures, summarize the failure snippet, then propose a fix plan and implement after explicit approval.
  • Depends on the
    plan
    skill for drafting and approving the fix plan.
Prereq: ensure
gh
is authenticated (for example, run
gh auth login
once), then run
gh auth status
with escalated permissions (include workflow/repo scopes) so
gh
commands succeed. If sandboxing blocks
gh auth status
, rerun it with
sandbox_permissions=require_escalated
.
使用gh工具定位失败的PR检查任务,拉取可用于排查的GitHub Actions失败日志,总结失败片段,然后提出修复计划并在明确获得用户批准后实施。
  • 依赖
    plan
    技能来起草和审批修复计划。
前置条件:确保
gh
已完成身份验证(例如,运行一次
gh auth login
),然后使用提升的权限(包含workflow/repo权限范围)运行
gh auth status
,以保证gh命令可以成功执行。如果沙箱环境阻止了
gh auth status
的运行,请添加参数
sandbox_permissions=require_escalated
重新运行该命令。

Inputs

输入参数

  • repo
    : path inside the repo (default
    .
    )
  • pr
    : PR number or URL (optional; defaults to current branch PR)
  • gh
    authentication for the repo host
  • repo
    : 仓库内的路径(默认值为
    .
  • pr
    : PR编号或URL(可选;默认使用当前分支对应的PR)
  • 针对仓库托管平台的gh身份验证信息

Quick start

快速开始

  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<number-or-url>"
  • Add
    --json
    if you want machine-friendly output for summarization.
  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<编号或URL>"
  • 如果需要适合机器处理的输出以用于总结,可以添加
    --json
    参数。

Workflow

工作流程

  1. Verify gh authentication.
    • Run
      gh auth status
      in the repo with escalated scopes (workflow/repo) after running
      gh auth login
      .
    • If sandboxed auth status fails, rerun the command with
      sandbox_permissions=require_escalated
      to allow network/keyring access.
    • If unauthenticated, ask the user to log in before proceeding.
  2. Resolve the PR.
    • Prefer the current branch PR:
      gh pr view --json number,url
      .
    • If the user provides a PR number or URL, use that directly.
  3. Inspect failing checks (GitHub Actions only).
    • Preferred: run the bundled script (handles gh field drift and job-log fallbacks):
      • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<number-or-url>"
      • Add
        --json
        for machine-friendly output.
    • Manual fallback:
      • gh pr checks <pr> --json name,state,bucket,link,startedAt,completedAt,workflow
        • If a field is rejected, rerun with the available fields reported by
          gh
          .
      • For each failing check, extract the run id from
        detailsUrl
        and run:
        • gh run view <run_id> --json name,workflowName,conclusion,status,url,event,headBranch,headSha
        • gh run view <run_id> --log
      • If the run log says it is still in progress, fetch job logs directly:
        • gh api "/repos/<owner>/<repo>/actions/jobs/<job_id>/logs" > "<path>"
  4. Scope non-GitHub Actions checks.
    • If
      detailsUrl
      is not a GitHub Actions run, label it as external and only report the URL.
    • Do not attempt Buildkite or other providers; keep the workflow lean.
  5. Summarize failures for the user.
    • Provide the failing check name, run URL (if any), and a concise log snippet.
    • Call out missing logs explicitly.
  6. Create a plan.
    • Use the
      plan
      skill to draft a concise plan and request approval.
  7. Implement after approval.
    • Apply the approved plan, summarize diffs/tests, and ask about opening a PR.
  8. Recheck status.
    • After changes, suggest re-running the relevant tests and
      gh pr checks
      to confirm.
  1. 验证gh身份验证状态
    • 在运行
      gh auth login
      后,在仓库中使用提升的权限范围(workflow/repo)运行
      gh auth status
    • 如果在沙箱环境中身份验证状态检查失败,请添加参数
      sandbox_permissions=require_escalated
      重新运行命令,以允许网络和密钥环访问。
    • 如果未完成身份验证,请要求用户先登录再继续。
  2. 确定目标PR
    • 优先使用当前分支对应的PR:运行
      gh pr view --json number,url
    • 如果用户提供了PR编号或URL,则直接使用该值。
  3. 检查失败的检查任务(仅针对GitHub Actions)
    • 推荐方式:运行内置脚本(可处理gh字段变更和作业日志回退):
      • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<编号或URL>"
      • 添加
        --json
        参数以获取适合机器处理的输出。
    • 手动回退方案:
      • gh pr checks <pr> --json name,state,bucket,link,startedAt,completedAt,workflow
        • 如果某个字段不被支持,请使用gh返回的可用字段重新运行命令。
      • 对于每个失败的检查任务,从
        detailsUrl
        中提取运行ID并执行:
        • gh run view <run_id> --json name,workflowName,conclusion,status,url,event,headBranch,headSha
        • gh run view <run_id> --log
      • 如果运行日志显示任务仍在进行中,则直接拉取作业日志:
        • gh api "/repos/<owner>/<repo>/actions/jobs/<job_id>/logs" > "<路径>"
  4. 处理非GitHub Actions的检查任务
    • 如果
      detailsUrl
      指向的不是GitHub Actions运行任务,则标记为外部检查任务,仅报告其URL。
    • 不要尝试处理Buildkite或其他第三方检查工具;保持工作流程简洁。
  5. 为用户总结失败信息
    • 提供失败检查任务的名称、运行URL(如有)以及简洁的日志片段。
    • 明确指出缺失的日志。
  6. 制定修复计划
    • 使用
      plan
      技能起草简洁的修复计划并请求用户批准。
  7. 批准后实施修复
    • 执行已批准的计划,总结代码变更和测试情况,并询问是否需要创建PR。
  8. 重新检查状态
    • 完成变更后,建议重新运行相关测试并执行
      gh pr checks
      以确认修复效果。

Bundled Resources

内置资源

scripts/inspect_pr_checks.py

scripts/inspect_pr_checks.py

Fetch failing PR checks, pull GitHub Actions logs, and extract a failure snippet. Exits non-zero when failures remain so it can be used in automation.
Usage examples:
  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "123"
  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "https://github.com/org/repo/pull/123" --json
  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --max-lines 200 --context 40
该脚本用于获取失败的PR检查任务,拉取GitHub Actions日志,并提取失败片段。当存在失败任务时,脚本会以非零状态码退出,因此可用于自动化流程。
使用示例:
  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "123"
  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "https://github.com/org/repo/pull/123" --json
  • python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --max-lines 200 --context 40