From fdcc396f466f2550a7f8ab41a149c462f53892bb Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 23 Mar 2026 12:11:11 +0100 Subject: [PATCH 1/4] fix(skill): Detect stacked PR context from branch Update the create-java-pr skill to infer standalone vs stacked PR mode\nfrom git branch and existing PR relationships.\n\nWhen running on main/master, default to standalone PR mode and only\nenter stack mode when explicitly requested by the user.\n\nCo-Authored-By: Claude --- .claude/skills/create-java-pr/SKILL.md | 39 ++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/.claude/skills/create-java-pr/SKILL.md b/.claude/skills/create-java-pr/SKILL.md index 6d5bb34edb..a9337382db 100644 --- a/.claude/skills/create-java-pr/SKILL.md +++ b/.claude/skills/create-java-pr/SKILL.md @@ -9,15 +9,42 @@ Prepare local changes and create a pull request for the sentry-java repo. **Required reading:** Before proceeding, read `.cursor/rules/pr.mdc` for the full PR and stacked PR workflow details. That file is the source of truth for PR conventions, stack comment format, branch naming, and merge strategy. -## Step 0: Determine PR Type +## Step 0: Determine PR Type From Git Branch Context -Ask the user (or infer from context) whether this is: +Infer PR type from the current branch before asking the user. -- **Standalone PR** — a regular PR targeting `main`. Follow Steps 1–6 as written. -- **First PR of a new stack** — ask for a topic name (e.g. "Global Attributes"). Create a collection branch from `main`, then branch the first PR off it. The first PR targets the collection branch. -- **Next PR in an existing stack** — identify the previous stack branch and topic. This PR targets the previous stack branch. +1. Get current branch: -If the user mentions "stack", "stacked PR", or provides a topic name with a number (e.g. `[Topic 2]`), treat it as a stacked PR. See `.cursor/rules/pr.mdc` § "Stacked PRs" for full details. +```bash +git branch --show-current +``` + +2. Apply these rules: + +- **If branch is `main` or `master`**: default to a **standalone PR**. + - Do **not** assume stack mode from `main`. + - Only use stack mode if the user explicitly asks for a stacked PR. +- **If branch is not `main`/`master`**: + - Check whether that branch already has a PR and what its base is: + ```bash + gh pr list --head "$(git branch --show-current)" --json number,baseRefName,title --jq '.[0]' + ``` + - If that branch PR exists and `baseRefName` is **not** `main`/`master`, treat the work as a **stacked PR context**. + - If that branch PR exists and `baseRefName` **is** `main`/`master`, treat it as **standalone PR context**. + - If no PR exists for the current branch, check whether other PRs target it: + ```bash + gh pr list --base "$(git branch --show-current)" --json number,headRefName,title + ``` + If there are downstream PRs, treat this as a stack base context. + +3. If signals are mixed or ambiguous, ask one focused question to confirm. + +PR types: +- **Standalone PR** — regular PR targeting `main`. +- **First PR of a new stack** — create collection branch from `main`, then first PR off it. +- **Next PR in an existing stack** — target previous stack branch. + +If the user explicitly says "stack", "stacked PR", or provides numbered stack titles (e.g. `[Topic 2]`), honor that even if branch heuristics are inconclusive. ## Step 1: Ensure Feature Branch From f68f2058eff0c3edc203d427793e3aee435ff803 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 25 Mar 2026 06:38:36 +0100 Subject: [PATCH 2/4] fix(create-java-pr): Detect collection branches with downstream PRs Check for downstream PRs even when the current branch already has a PR targeting main/master. This prevents collection branches in a stacked PR flow from being misclassified as standalone PR context. Co-Authored-By: Claude --- .claude/skills/create-java-pr/SKILL.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.claude/skills/create-java-pr/SKILL.md b/.claude/skills/create-java-pr/SKILL.md index a9337382db..0a4912eb7b 100644 --- a/.claude/skills/create-java-pr/SKILL.md +++ b/.claude/skills/create-java-pr/SKILL.md @@ -30,7 +30,12 @@ git branch --show-current gh pr list --head "$(git branch --show-current)" --json number,baseRefName,title --jq '.[0]' ``` - If that branch PR exists and `baseRefName` is **not** `main`/`master`, treat the work as a **stacked PR context**. - - If that branch PR exists and `baseRefName` **is** `main`/`master`, treat it as **standalone PR context**. + - If that branch PR exists and `baseRefName` **is** `main`/`master`, also check whether other PRs target the current branch: + ```bash + gh pr list --base "$(git branch --show-current)" --json number,headRefName,title + ``` + - If there are downstream PRs, treat this as a **stack base context** (collection branch). + - If there are no downstream PRs, treat it as **standalone PR context**. - If no PR exists for the current branch, check whether other PRs target it: ```bash gh pr list --base "$(git branch --show-current)" --json number,headRefName,title From be930c11c6233623436ad14d3eebe95cc3f72b1e Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 25 Mar 2026 06:42:13 +0100 Subject: [PATCH 3/4] fix(create-java-pr): Map stack base detection to defined PR type When downstream PRs are found for a branch, classify the result as an existing stack flow instead of an undefined "stack base context". Clarify that the next PR in an existing stack can target either the previous stack PR branch or the collection branch, so all detection outcomes map to actionable PR types. Co-Authored-By: Claude --- .claude/skills/create-java-pr/SKILL.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.claude/skills/create-java-pr/SKILL.md b/.claude/skills/create-java-pr/SKILL.md index 0a4912eb7b..9b0d6afde1 100644 --- a/.claude/skills/create-java-pr/SKILL.md +++ b/.claude/skills/create-java-pr/SKILL.md @@ -34,20 +34,20 @@ git branch --show-current ```bash gh pr list --base "$(git branch --show-current)" --json number,headRefName,title ``` - - If there are downstream PRs, treat this as a **stack base context** (collection branch). + - If there are downstream PRs, treat this as **next PR in an existing stack** with the current branch as the stack base (collection branch). - If there are no downstream PRs, treat it as **standalone PR context**. - If no PR exists for the current branch, check whether other PRs target it: ```bash gh pr list --base "$(git branch --show-current)" --json number,headRefName,title ``` - If there are downstream PRs, treat this as a stack base context. + If there are downstream PRs, treat this as **next PR in an existing stack** with the current branch as the stack base (collection branch). 3. If signals are mixed or ambiguous, ask one focused question to confirm. PR types: - **Standalone PR** — regular PR targeting `main`. - **First PR of a new stack** — create collection branch from `main`, then first PR off it. -- **Next PR in an existing stack** — target previous stack branch. +- **Next PR in an existing stack** — target the current stack base branch (usually the previous stack PR branch, or the collection branch if creating the first follow-up PR from the collection branch). If the user explicitly says "stack", "stacked PR", or provides numbered stack titles (e.g. `[Topic 2]`), honor that even if branch heuristics are inconclusive. From f83515c840a38f26a5aeaeb7eb3b2919245c6276 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 27 Mar 2026 13:33:34 +0100 Subject: [PATCH 4/4] fix(skills): Add missing standalone PR fallback for fresh feature branches The decision tree in create-java-pr Step 0 had a gap: when a non-main branch has no existing PR and no downstream PRs target it, no outcome was specified. This is the most common case (fresh feature branch). Add explicit fallback to standalone PR context, matching the behavior of the parallel branch where a PR exists with base main and no downstream PRs. Co-Authored-By: Claude --- .claude/skills/create-java-pr/SKILL.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.claude/skills/create-java-pr/SKILL.md b/.claude/skills/create-java-pr/SKILL.md index 9b0d6afde1..e2a9b9bc78 100644 --- a/.claude/skills/create-java-pr/SKILL.md +++ b/.claude/skills/create-java-pr/SKILL.md @@ -40,7 +40,8 @@ git branch --show-current ```bash gh pr list --base "$(git branch --show-current)" --json number,headRefName,title ``` - If there are downstream PRs, treat this as **next PR in an existing stack** with the current branch as the stack base (collection branch). + - If there are downstream PRs, treat this as **next PR in an existing stack** with the current branch as the stack base (collection branch). + - If there are no downstream PRs either, treat it as **standalone PR context** (fresh feature branch). 3. If signals are mixed or ambiguous, ask one focused question to confirm.