Skip to content

fix(pr-title): don't duplicate the version prefix on bare-version PR titles#1887

Open
jbetala7 wants to merge 1 commit into
garrytan:mainfrom
jbetala7:oss/fix-pr-title-bare-version
Open

fix(pr-title): don't duplicate the version prefix on bare-version PR titles#1887
jbetala7 wants to merge 1 commit into
garrytan:mainfrom
jbetala7:oss/fix-pr-title-bare-version

Conversation

@jbetala7
Copy link
Copy Markdown
Contributor

@jbetala7 jbetala7 commented Jun 6, 2026

Problem

bin/gstack-pr-title-rewrite.sh duplicates the version prefix when a PR title is a bare version with no description:

v1.2.3.4 + "v1.2.3.4"  ->  "v1.2.3.4 v1.2.3.4"   (should be unchanged — case 1)
v1.2.3.4 + "v1.2.3"    ->  "v1.2.3.4 v1.2.3"      (stale prefix kept — should replace)

Root cause

Both the no-change case glob ("v$NEW_VERSION "*) and the strip sed (s/^v[0-9]+(\.[0-9]+)+ //) anchor on a trailing space. A title that is only a version (nothing after) matches neither, so it falls through to the prepend case and gets a second prefix. It also never self-heals — once it becomes v1.2.3.4 v1.2.3.4, the duplicated form matches case 1 and is returned as-is.

This is reachable in CI: .github/workflows/pr-title-sync.yml runs on every PR open/edit/synchronize, feeds the real title through this helper, and gh pr edits the result. A version-only PR title (the format ship/CHANGELOG uses for branch-ahead bumps) gets rewritten to the duplicated form and written back to the PR.

Fix

  • Match the bare "v$NEW_VERSION" form in the no-change case.
  • Strip an existing prefix at a space or end-of-string (( |$)).
  • Emit a bare new prefix when the title had no description, avoiding a trailing space.

All three documented cases (no-change / replace / prepend) now hold for both v1.2.3 <desc> and bare v1.2.3 titles. Titles with descriptions, the version 5 non-prefix guard, and the single-segment v1 guard are unchanged.

Testing

bun test test/pr-title-rewrite.test.ts — 12 pass (9 existing + 3 new).

The 3 new tests (bare-correct -> no change, bare-different -> replace, bare idempotency) were verified to fail on main before the fix:

bare correct  : Expected "v1.2.3.4"  Received "v1.2.3.4 v1.2.3.4"
bare different : Expected "v1.2.3.4"  Received "v1.2.3.4 v1.2.3"

bash -n clean, git diff --check clean, slop:diff adds no findings in the changed files.

Fixes #1886

gstack-pr-title-rewrite.sh anchored both its no-change case match
("v$NEW_VERSION "*) and its prefix-strip sed (/^v…+ /) on a trailing
space, so a title that is a bare version with no description fell through
to the prepend case and got a second prefix:

  v1.2.3.4 + "v1.2.3.4"  -> "v1.2.3.4 v1.2.3.4"   (should be no change)
  v1.2.3.4 + "v1.2.3"    -> "v1.2.3.4 v1.2.3"      (stale prefix kept)

This violated the helper's documented case 1 (no change) and case 2
(replace prefix) and its idempotency contract. It is reachable in CI:
.github/workflows/pr-title-sync.yml feeds the real PR title through the
helper and then `gh pr edit`s the result, so a version-only PR title (the
format ship/CHANGELOG uses for branch-ahead bumps) gets corrupted, and it
never self-heals (the duplicated form then matches case 1).

Match the bare "v$NEW_VERSION" form in the no-change case, strip an
existing prefix at a space OR end-of-string, and emit a bare new prefix
when the title had no description. Adds 3 regression tests (bare correct,
bare different, bare idempotency) that fail on main and pass with the fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented Jun 6, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@jbetala7 jbetala7 changed the title v1.56.1.0 fix(pr-title): don't duplicate the version prefix on bare-version PR titles fix(pr-title): don't duplicate the version prefix on bare-version PR titles Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gstack-pr-title-rewrite.sh duplicates the version prefix on a bare-version title (no description)

1 participant