Skip to content

fix(branch): sanitize {{label}} in branch_name_template for git-safe names - #1498

Closed
syf2211 wants to merge 1 commit into
anthropics:mainfrom
syf2211:fix/sanitize-label-branch-template
Closed

fix(branch): sanitize {{label}} in branch_name_template for git-safe names#1498
syf2211 wants to merge 1 commit into
anthropics:mainfrom
syf2211:fix/sanitize-label-branch-template

Conversation

@syf2211

@syf2211 syf2211 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Sanitize GitHub label values before substituting them into branch_name_template, so scoped labels like area:permissions no longer produce branch names containing : that fail validateBranchName and abort the action run.

Motivation

Fixes #1491. Labels are free-form and often scoped with : or / (e.g. area:permissions, provider:bedrock). The {{description}} variable was already normalized to kebab-case, but {{label}} was substituted verbatim. A template like {{prefix}}{{label}}/{{entityNumber}} could crash the entire run with process.exit(1).

Changes

  • src/utils/branch-template.ts: add shared sanitizeBranchSegment() helper; route extractDescription() and new sanitizeLabel() through it
  • generateBranchName(): substitute sanitized label, falling back to entityType when sanitization yields empty
  • test/branch-template.test.ts: regression tests for scoped labels, colon-containing labels, and empty-sanitize fallback; assert validateBranchName passes

Tests

  • bun test test/branch-template.test.ts — pass (23/23)
  • bun test — pass (772/772)
  • bun run typecheck — pass
  • composer-2.5 review: COMMENT (addressed JSDoc + fallback test)

Notes

  • Intentionally scoped to {{label}} only; custom templates with literal punctuation in {{prefix}} are unchanged (pre-existing behavior).
  • Labels that sanitize to empty (e.g. :::) fall back to entityType, matching the documented fallback when no label is provided.

Fixes #1491

…names

Scoped GitHub labels like area:permissions were substituted verbatim into
branch_name_template, producing branch names with ':' that fail
validateBranchName and abort the action run.

Normalize labels into git-safe hyphenated segments (matching description
handling) and fall back to entityType when sanitization yields empty.

Fixes anthropics#1491
@ashwin-ant

Copy link
Copy Markdown
Collaborator

Thanks. #1492 fixes the same {{label}} sanitization issue and merged first, so closing this as a duplicate.

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.

Unsanitized {{label}} in branch_name_template can abort the run with an invalid branch name

2 participants