Skip to content

feat(settings): configurable branch name prefix#2708

Open
KarloAldrete wants to merge 2 commits into
PostHog:mainfrom
KarloAldrete:feat/configurable-branch-prefix
Open

feat(settings): configurable branch name prefix#2708
KarloAldrete wants to merge 2 commits into
PostHog:mainfrom
KarloAldrete:feat/configurable-branch-prefix

Conversation

@KarloAldrete

Copy link
Copy Markdown

Problem

The branch name PostHog Code generates for a task is hardcoded with the posthog-code/ prefix. Some users want a different prefix — or none — to match their team's branch conventions.

Closes #1632

Changes

  • New "Branch name prefix" setting under Settings → Worktrees (branchPrefix), defaulting to the current posthog-code/ so existing behavior is unchanged.
  • deriveBranchName / suggestBranchName take an optional prefix argument (default BRANCH_PREFIX); existing callers are unaffected.
  • getSuggestedBranchName reads the setting, so the generated branch name honors it wherever the app suggests one (Create PR, "Branch here").
  • The prefix is validated before it's saved (validateBranchPrefix): rejects names git would reject and a leading -; empty = no prefix. Invalid input shows an inline error and isn't persisted.

Branch name prefix setting under Settings -> Worktrees

How did you test this?

  • pnpm --filter @posthog/core --filter @posthog/ui typecheck — clean.
  • biome lint packages/core/src/git-interaction + Biome check on all changed files — clean, no noRestrictedImports.
  • vitest run on branchName.test.ts + deriveBranchName.test.ts — 38 passing (added: custom prefix, empty prefix, task-ID fallback with prefix, validateBranchPrefix).
  • Manually (by the contributor): set a custom prefix in Settings → Worktrees; "Create branch" on a worktree task used the configured prefix; an empty prefix dropped it; invalid values showed the inline error.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

The branch name for new tasks was hardcoded with the `posthog-code/`
prefix. This adds a "Branch name prefix" setting (Settings -> Worktrees)
so it can be changed or removed.

- New `branchPrefix` setting, defaulting to the existing `posthog-code/`.
- `deriveBranchName` / `suggestBranchName` take an optional `prefix`
  (default unchanged), so existing callers are unaffected.
- `getSuggestedBranchName` reads the setting, so both worktree and cloud
  branch suggestions honor it.
- The prefix is validated before saving (rejects invalid git names and a
  leading dash); empty means no prefix.

Closes PostHog#1632

Generated-By: PostHog Code
Task-Id: 8e9f327d-84b1-4608-9f48-c3038dbf87ca
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
packages/core/src/git-interaction/branchName.test.ts:114-150
**Prefer parameterised tests for `validateBranchPrefix`**

The five separate `it` blocks under `validateBranchPrefix` all call the same function with different inputs; this is exactly the pattern the team prefers to express as `it.each`. A failure in the current form only tells you "the test named 'rejects spaces' failed" rather than which input/expected pair broke — and it takes more prose to add a new case. The same applies to the three new `it` blocks in `deriveBranchName.test.ts` ("uses a custom prefix", "supports an empty prefix", "applies a custom prefix to the task-ID fallback"), and to the two-assertion `"supports a custom prefix"` test for `suggestBranchName` which packs two independent scenarios into one case.

Reviews (1): Last reviewed commit: "feat(settings): configurable branch name..." | Re-trigger Greptile

Comment on lines 114 to 150
).toBe("posthog-code/fix-bug-4");
});

it("supports a custom prefix", () => {
expect(suggestBranchName("Fix bug", "abc", [], "team/")).toBe(
"team/fix-bug",
);
expect(suggestBranchName("Fix bug", "abc", ["team/fix-bug"], "team/")).toBe(
"team/fix-bug-2",
);
});
});

describe("validateBranchPrefix", () => {
it("allows an empty prefix (no prefix)", () => {
expect(validateBranchPrefix("")).toBeNull();
});

it("allows normal prefixes", () => {
expect(validateBranchPrefix("team/")).toBeNull();
expect(validateBranchPrefix("posthog-code/")).toBeNull();
});

it("rejects a leading dash (flag-like)", () => {
expect(validateBranchPrefix("-x/")).toBe(
"Branch prefix cannot start with a dash.",
);
});

it("rejects spaces", () => {
expect(validateBranchPrefix("my team/")).not.toBeNull();
});

it('rejects ".."', () => {
expect(validateBranchPrefix("../")).not.toBeNull();
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Prefer parameterised tests for validateBranchPrefix

The five separate it blocks under validateBranchPrefix all call the same function with different inputs; this is exactly the pattern the team prefers to express as it.each. A failure in the current form only tells you "the test named 'rejects spaces' failed" rather than which input/expected pair broke — and it takes more prose to add a new case. The same applies to the three new it blocks in deriveBranchName.test.ts ("uses a custom prefix", "supports an empty prefix", "applies a custom prefix to the task-ID fallback"), and to the two-assertion "supports a custom prefix" test for suggestBranchName which packs two independent scenarios into one case.

Context Used: Do not attempt to comment on incorrect alphabetica... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/src/git-interaction/branchName.test.ts
Line: 114-150

Comment:
**Prefer parameterised tests for `validateBranchPrefix`**

The five separate `it` blocks under `validateBranchPrefix` all call the same function with different inputs; this is exactly the pattern the team prefers to express as `it.each`. A failure in the current form only tells you "the test named 'rejects spaces' failed" rather than which input/expected pair broke — and it takes more prose to add a new case. The same applies to the three new `it` blocks in `deriveBranchName.test.ts` ("uses a custom prefix", "supports an empty prefix", "applies a custom prefix to the task-ID fallback"), and to the two-assertion `"supports a custom prefix"` test for `suggestBranchName` which packs two independent scenarios into one case.

**Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Addresses review feedback: use it.each for validateBranchPrefix, the
deriveBranchName custom-prefix cases, and suggestBranchName, matching the
parameterised-test convention in AGENTS.md.

Generated-By: PostHog Code
Task-Id: 8e9f327d-84b1-4608-9f48-c3038dbf87ca
@KarloAldrete

Copy link
Copy Markdown
Author

Thanks for the review! Parameterised those tests with it.each in 2b29791validateBranchPrefix, the deriveBranchName custom-prefix cases, and suggestBranchName — matching the parameterised-test convention in AGENTS.md.

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.

Confirgurable default branch prefixes/names

1 participant