mcpField
P
push

push

github.com/odysseus0开发82524 次安装1 周前更新
代码仓库

关于 push

push 是用于安全推送当前分支并创建或更新拉取请求的仓库技能,涵盖验证、同步失败处理、PR 内容检查及返回结果链接。

主要功能

  1. 01使用 make -C elixir all 验证
  2. 02推送到已配置的 origin
  3. 03创建或更新分支拉取请求
  4. 04使用 mix pr_body.check 检查 PR 正文
  5. 05区分同步问题与远程错误

适用场景

  1. 01本地验证后推送更改
  2. 02分支更新后刷新拉取请求
  3. 03处理分支落后导致的推送拒绝

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/odysseus0/symphony --skill push

安装后在 Claude Code 中输入/push确认已加载。

详细介绍

推送

前置条件

  • 已安装 gh CLI,并且可在 PATH 中找到。
  • 对此仓库执行 GitHub 操作时,gh auth status 会成功。

目标

  • 安全地将当前分支的更改推送到 origin。
  • 如果此分支没有 PR,则创建一个;否则更新现有 PR。
  • 远程分支有更新时,保持分支历史整洁。

相关技能

  • pull:推送被拒绝或同步状态不干净时使用(非快进、存在合并冲突风险或分支已过时)。

步骤

  1. 确认当前分支并检查远程状态。

  2. 推送前运行本地验证(make -C elixir all)。

  3. 将分支推送到 origin;如有需要,设置上游跟踪,并使用已配置的远程 URL。

  4. 如果推送状态不干净或被拒绝:

    • 如果失败是非快进或同步问题,运行 pull 技能以合并 origin/main、解决冲突并重新运行验证。
    • 再次推送;仅在重写历史后使用 --force-with-lease。
    • 如果失败是由于已配置远程上的身份验证、权限或工作流限制,停止并原样报告确切错误,不要通过重写远程配置或切换协议来绕过问题。
  5. 确保此分支存在 PR:

    • 如果不存在 PR,则创建一个。
    • 如果存在 PR 且处于打开状态,则更新它。
    • 如果此分支关联的是已关闭或已合并的 PR,则创建新分支和 PR。
    • 撰写恰当的 PR 标题,清楚说明更改结果。
    • 更新分支时,明确重新评估当前 PR 标题是否仍符合最新范围;如果不符合,则更新标题。
  6. 使用 .github/pull_request_template.md 明确撰写或更新 PR 正文:

    • 为所有章节填写与此次更改相关的具体内容。
    • 替换所有占位注释(``)。
    • 模板要求的项目符号和复选框必须保留。
    • 如果 PR 已存在,则刷新正文,使其反映分支上 PR 的全部范围(所有计划内的工作),而不仅仅是最新提交;包括新增或移除的工作,以及方案的变更。
    • 不要复用早期迭代中已经过时的描述文本。
  7. 运行 mix pr_body.check 验证 PR 正文,并修复报告的所有问题。

  8. 回复 gh pr view 返回的 PR URL。

命令

# Identify branch
branch=$(git branch --show-current)

# Minimal validation gate
make -C elixir all

# Initial push: respect the current origin remote.
git push -u origin HEAD

# If that failed because the remote moved, use the pull skill. After
# pull-skill resolution and re-validation, retry the normal push:
git push -u origin HEAD

# If the configured remote rejects the push for auth, permissions, or workflow
# restrictions, stop and surface the exact error.

# Only if history was rewritten locally:
git push --force-with-lease origin HEAD

# Ensure a PR exists (create only if missing)
pr_state=$(gh pr view --json state -q .state 2>/dev/null || true)
if [ "$pr_state" = "MERGED" ] || [ "$pr_state" = "CLOSED" ]; then
  echo "Current branch is tied to a closed PR; create a new branch + PR." >&2
  exit 1
fi

# Write a clear, human-friendly title that summarizes the shipped change.
pr_title="<clear PR title written for this change>"
if [ -z "$pr_state" ]; then
  gh pr create --title "$pr_title"
else
  # Reconsider title on every branch update; edit if scope shifted.
  gh pr edit --title "$pr_title"
fi

# Write/edit PR body to match .github/pull_request_template.md before validation.
# Example workflow:
# 1) open the template and draft body content for this PR
# 2) gh pr edit --body-file /tmp/pr_body.md
# 3) for branch updates, re-check that title/body still match current diff

tmp_pr_body=$(mktemp)
gh pr view --json body -q .body > "$tmp_pr_body"
(cd elixir && mix pr_body.check --file "$tmp_pr_body")
rm -f "$tmp_pr_body"

# Show PR URL for the reply
gh pr view --json url -q .url

备注

  • 不要使用 --force;仅在万不得已时使用 --force-with-lease。
  • 区分同步问题与远程身份验证或权限问题:
    • 非快进或分支过时问题使用 pull 技能。
    • 直接报告身份验证、权限或工作流限制问题,不要更改远程配置或协议。

评论

支持 Markdown