Skip to content

fix: repair a malformed title prefix instead of prepending a second one #3578

Closed

Description

@eleshar

Found by Qodo review of #3573 (merged as #3568's fix).

Problem

isAlreadyPrefixed() correctly requires whitespace after the colon — the Conventional Commits spec makes the terminal colon-and-space required, and both normalize-issue-pr-titles.cjs and .js now enforce it. But normalizeTitle() handles that rejection by prepending the prefix again, so a malformed title is mutated into a worse one:

decision:Adopt GraphQL   ->  decision: decision:Adopt GraphQL

That doubles the prefix instead of repairing it. The behaviour is pre-existing and asserted by normalize-titles.test.js (normalizeTitle("fix:Add something", "fix") === "fix: fix:Add something"), and the ecosystem norm is to detect and report a malformed header rather than silently rewrite it — commitlint fails with type-enum instead of editing.

Approach

Recognise a leading prefix independently of whether its spacing is canonical:

  • recognised prefix, canonical spacing -> leave the title alone
  • recognised prefix, missing space -> insert the single space, keeping one prefix
  • no recognised prefix -> prepend the inferred prefix as today

Apply to both .cjs and .js so they stay byte-identical, and update the assertion that currently encodes the doubling.

Acceptance

  • decision:Adopt GraphQL becomes decision: Adopt GraphQL, not decision: decision:Adopt GraphQL
  • Already-canonical titles are still left untouched
  • Unprefixed titles still gain a prefix
  • The CommonJS and JavaScript implementations stay byte-identical, with parity tests covering the new cases
  • No change to the canonical title grammar in docs/ISSUE_PR_TITLE_GOVERNANCE.md

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions