agentleFS
chenson42chenson42/stackkeel/.claude/skills/merge-pr/SKILL.md

merge-pr

Skill1 starsChanged 53 days agoMITView on GitHub

Merge a PR safely — retargets any dependent PRs to main BEFORE deleting the base branch, so GitHub never auto-closes them

17 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use implement-issue, create-pr and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • GoogleSkill

    implement-issue

    Implement a Site Kit GitHub issue end-to-end from its implementation brief. Use when the user asks to implement, build, or work on a GitHub issue / feature by number (e.g. "implement issue #12345", "build the feature in issue 12345", "follow the implementation brief for #12345") in the google/site-kit-wp repo.

    Also in 3 projects that use this

  • SentrySkill

    create-pr

    Create pull requests following Sentry conventions. Use when opening PRs, writing PR descriptions, or preparing changes for review. Follows Sentry's code review guidelines.

    Also in 7 projects that use this

  • sahinSkill

    create-issue

    Also in 3 projects that use this

  • SentrySkill

    commit

    Create commit messages following Sentry conventions. Use when committing code changes, writing commit messages, or formatting git history. Follows conventional commits with Sentry-specific issue references.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When the user invokes /merge-pr <number>, merge that PR while protecting any open PRs whose base branch is about to disappear.

    line 9
  2. Very specific:

    If state is CLOSED or MERGED, stop.

    line 37
  3. Distinctive:

    If the list is empty, skip to Step 4 — no retargeting needed.

    line 45
  4. Distinctive:

    After all retargets, verify with a single re-query:

    line 57

“Common” is measured: kept by at least 6 in 10 of the 17 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Merge a PR Safely (auto-retargets downstream PRs)

When the user invokes /merge-pr <number>, merge that PR while protecting any open PRs whose base branch is about to disappear. Applies the same way regardless of which app or package the PR touches — this is a GitHub-mechanics skill.

The trap this avoids

gh pr merge N --delete-branch deletes the head branch after the merge commit lands on main. If any other open PR has that branch as its baseRefName, GitHub auto-closes those PRs — their base no longer exists. The recovery is a 5-step dance: push the deleted branch back, gh pr reopen, retarget to main, wait for mergeability, then merge.

This skill retargets dependents to main before the base branch is deleted, so nothing auto-closes.

When to use

  • Any PR you're about to merge with --delete-branch (which should be ~every PR).
  • Stacked PRs: invoke /merge-pr for each one bottom-up; each call retargets the next layer.

When NOT to use

  • The PR doesn't use --delete-branch (the trap doesn't apply if the head branch persists).
  • The PR has no dependents AND you don't care if the branch stays — plain gh pr merge is fine.

Procedure

Step 1 — Look up the PR's head branch

gh pr view <N> --json headRefName,baseRefName,state,mergeable

Confirm: state is OPEN, mergeable is MERGEABLE (or UNKNOWN — GitHub may still be computing). Note headRefName for Step 2.

If state is CLOSED or MERGED, stop. This skill prevents the trap; it does not recover from already-closed PRs.

Step 2 — Find dependent PRs

gh pr list --base "<headRefName from Step 1>" --state open --json number,title,baseRefName

If the list is empty, skip to Step 4 — no retargeting needed.

Step 3 — Retarget each dependent to main

For each dependent PR number M:

gh api repos/{owner}/{repo}/pulls/M -X PATCH -f base=main --silent

{owner} and {repo} are auto-substituted by gh from the current repository — no hardcoding.

After all retargets, verify with a single re-query:

gh pr list --base "<headRefName from Step 1>" --state open --json number

Result should be [].

Step 4 — Merge

gh pr merge <N> --merge --delete-branch

Defaults: --merge (matches the repo convention) and --delete-branch (the trap is now prevented). Swap --merge for --squash or --rebase only if the user explicitly asks.

Step 5 — Verify

gh pr view <N> --json state,mergedAt

Expect state: MERGED. For each retargeted PR M, confirm it's still OPEN and now targets main:

gh pr view M --json state,baseRefName

CI consideration

Retargeting changes a PR's base but does not push new commits, so CI configured on pull_request events may not re-trigger automatically. If CI must run before merge, push a --allow-empty commit on the head branch after the retarget, or escalate to the user.

Why this exists

Multiple downstream forks independently hit the auto-close trap while merging PR stacks (one stack of 8 PRs cost ~5 minutes of branch-restore + reopen + retarget per PR). The Workflow Rules point at this skill so it's discoverable from the rules layer.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.