Merge pull request #2600 from gsd-build/refine/consolidate-branch-patterns

refactor: consolidate branch name patterns into single module
This commit is contained in:
TÂCHES 2026-03-25 22:46:51 -06:00 committed by GitHub
commit bdb21c3c23
3 changed files with 22 additions and 14 deletions

View file

@ -0,0 +1,16 @@
/**
* GSD branch naming patterns single source of truth.
*
* gsd/<worktree>/<milestone>/<slice> SLICE_BRANCH_RE
* gsd/quick/<id>-<slug> QUICK_BRANCH_RE
* gsd/<workflow>/<...> WORKFLOW_BRANCH_RE (non-milestone gsd/ branches)
*/
/** Matches gsd/ slice branches: gsd/[worktree/]M001[-hash]/S01 */
export const SLICE_BRANCH_RE = /^gsd\/(?:([a-zA-Z0-9_-]+)\/)?(M\d+(?:-[a-z0-9]{6})?)\/(S\d+)$/;
/** Matches gsd/quick/ task branches */
export const QUICK_BRANCH_RE = /^gsd\/quick\//;
/** Matches gsd/ workflow branches (non-milestone, e.g. gsd/workflow-name/...) */
export const WORKFLOW_BRANCH_RE = /^gsd\/(?!M\d)[\w-]+\//;

View file

@ -18,8 +18,8 @@ import { loadEffectiveGSDPreferences } from "./preferences.js";
import {
detectWorktreeName,
SLICE_BRANCH_RE,
} from "./worktree.js";
import { SLICE_BRANCH_RE, QUICK_BRANCH_RE, WORKFLOW_BRANCH_RE } from "./branch-patterns.js";
import {
nativeGetCurrentBranch,
nativeDetectMainBranch,
@ -243,17 +243,8 @@ export function readIntegrationBranch(basePath: string, milestoneId: string): st
*
* The file is committed immediately so the metadata is persisted in git.
*/
/** Regex matching GSD quick-task branches: gsd/quick/<num>-<slug> */
export const QUICK_BRANCH_RE = /^gsd\/quick\//;
/**
* Matches all GSD workflow-template branches: gsd/<templateId>/<slug>.
*
* Template IDs are lowercase alphanumeric with hyphens (e.g. hotfix, bugfix,
* small-feature, dep-upgrade). The negative lookahead excludes milestone
* branches (gsd/M001/... or gsd/M001-abc123/...) which use SLICE_BRANCH_RE.
*/
export const WORKFLOW_BRANCH_RE = /^gsd\/(?!M\d)[\w-]+\//;
/** Re-export for backward compatibility — canonical definitions in branch-patterns.ts */
export { QUICK_BRANCH_RE, WORKFLOW_BRANCH_RE } from "./branch-patterns.js";
export function writeIntegrationBranch(
basePath: string,

View file

@ -235,8 +235,9 @@ export function getSliceBranchName(milestoneId: string, sliceId: string, worktre
return `gsd/${milestoneId}/${sliceId}`;
}
/** Regex that matches both plain and worktree-namespaced slice branches. */
export const SLICE_BRANCH_RE = /^gsd\/(?:([a-zA-Z0-9_-]+)\/)?(M\d+(?:-[a-z0-9]{6})?)\/(S\d+)$/;
/** Re-export for backward compatibility — canonical definition in branch-patterns.ts */
export { SLICE_BRANCH_RE } from "./branch-patterns.js";
import { SLICE_BRANCH_RE } from "./branch-patterns.js";
/**
* Parse a slice branch name into its components.