Skip to content

Custom prefix written twice#1075

Merged
Kitenite merged 4 commits intomainfrom
custom-prefix-written-twice
Jan 31, 2026
Merged

Custom prefix written twice#1075
Kitenite merged 4 commits intomainfrom
custom-prefix-written-twice

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Jan 31, 2026

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

  • New Features

    • Added an optional control to apply or skip automatic branch name prefixes when creating workspaces.
    • Workspace creation now sends the prefix preference so branch naming behavior matches the UI.
  • Improvements

    • Enhanced branch-name preview to show the final formatted name (prefix + slug) when applicable.
    • Improved generation flow separating user-edited names from automatically derived slugs for more predictable results.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 31, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds an optional boolean applyPrefix to workspace creation. Frontend separates slug generation from prefix application and sends applyPrefix; backend computes and conditionally applies a branch prefix and adjusts branch-name generation/collision logic accordingly.

Changes

Cohort / File(s) Summary
Backend Workspace Creation
apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts
Adds applyPrefix: z.boolean().optional().default(true) to create input; gates prefix computation/application behind applyPrefix; adds withPrefix helper; replaces rawAuthorPrefix/authorPrefix with sanitizedPrefix/branchPrefix in branch generation and collision checks.
Frontend Workspace Modal
apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx
Replaces generateBranchFromTitle with generateSlugFromTitle(title) to produce branchSlug; introduces applyPrefix = !branchNameEdited, branchPreview (resolvedPrefix + slug when applicable); sends `{ branchName: branchSlug

Sequence Diagram

sequenceDiagram
    actor User
    participant Modal as NewWorkspaceModal
    participant Frontend as Frontend Logic
    participant API as Renderer/API
    participant Backend as create.ts Handler

    User->>Modal: Enter title / optionally edit branch name
    Modal->>Frontend: generateSlugFromTitle(title)
    Frontend-->>Modal: branchSlug
    Modal->>Modal: applyPrefix = !branchNameEdited
    Modal->>Frontend: request resolvedPrefix (if applyPrefix)
    Frontend-->>Modal: resolvedPrefix
    Modal->>Modal: branchPreview = applyPrefix ? resolvedPrefix + branchSlug : branchSlug

    User->>Modal: Submit
    Modal->>API: Create { branchName: branchSlug, applyPrefix }
    API->>Backend: create mutation

    alt applyPrefix = true
        Backend->>Backend: compute branchPrefix from settings & existing branches
        Backend->>Backend: withPrefix(branchSlug) -> final branch name
    else applyPrefix = false
        Backend->>Backend: use branchSlug as-is
    end

    Backend-->>API: Created workspace
    API-->>Modal: Success
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibbled a slug from the title vine,
applyPrefix pondered, then chose to align,
Prefixes hop in, or quietly stay,
Modal and handler now dance in a way,
A tiny branch springs, neat and fine.

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is completely empty except for template placeholders. No actual description, related issues, type of change, testing details, or context were provided. Fill in all required sections: add a clear description of the changes, link related issues, specify the type of change (Bug fix appears most relevant), describe testing performed, and provide any additional context.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Custom prefix written twice' is vague and does not clearly indicate what the actual change is about. It lacks specificity about whether this is fixing a bug, addressing duplicate logic, or refactoring. Improve the title to be more descriptive, such as 'Fix duplicate prefix application in branch name generation' or 'Refactor branch prefix logic to apply conditionally'.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch custom-prefix-written-twice

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Kitenite Kitenite merged commit 51ee895 into main Jan 31, 2026
4 checks passed
@Kitenite Kitenite deleted the custom-prefix-written-twice branch January 31, 2026 01:08
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx`:
- Around line 133-142: The preview/prefix logic must match backend collision and
empty-edit behavior: compute branchSlug via sanitizeBranchName(branchName) or
generateSlugFromTitle(title) as you already do, then set applyPrefix to false
not only when branchNameEdited is true, but also when branchSlug is empty or
when the resolvedPrefix would be dropped by backend due to collision; i.e.
change applyPrefix to something like: !branchNameEdited && branchSlug !== '' &&
!isPrefixCollision(resolvedPrefix, branchSlug) (call an existing collision-check
util or small API/utility function that mirrors backend collision logic), and
use that applyPrefix for branchPreview generation so the UI matches backend
behavior (refer to branchNameEdited, sanitizeBranchName, generateSlugFromTitle,
resolvedPrefix, branchPreview).

Comment on lines +133 to +142
const branchSlug = branchNameEdited
? sanitizeBranchName(branchName)
: generatedBranchName;
: generateSlugFromTitle(title);

const applyPrefix = !branchNameEdited;

const branchPreview =
branchSlug && applyPrefix && resolvedPrefix
? `${resolvedPrefix}/${branchSlug}`
: branchSlug;
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.

⚠️ Potential issue | 🟡 Minor

Keep applyPrefix/preview aligned with backend collision logic and empty edits.

Right now applyPrefix depends only on branchNameEdited. If a user clears the branch field (without blur), applyPrefix becomes false and the backend will generate an unprefixed branch. Also, the backend drops the prefix when it collides with an existing branch, but the preview still shows it. Consider factoring in empty slug and prefix collisions to keep UI and backend consistent.

Proposed adjustment (frontend-only)
 	const branchSlug = branchNameEdited
 		? sanitizeBranchName(branchName)
 		: generateSlugFromTitle(title);

-	const applyPrefix = !branchNameEdited;
+	const prefixWouldCollide = useMemo(() => {
+		if (!resolvedPrefix || !branchData?.branches?.length) return false;
+		const existingSet = new Set(
+			branchData.branches.map((b) => b.name.toLowerCase()),
+		);
+		return existingSet.has(resolvedPrefix.toLowerCase());
+	}, [resolvedPrefix, branchData?.branches]);
+
+	const applyPrefix = (!branchNameEdited || !branchSlug) && !prefixWouldCollide;

 	const branchPreview =
 		branchSlug && applyPrefix && resolvedPrefix
 			? `${resolvedPrefix}/${branchSlug}`
 			: branchSlug;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const branchSlug = branchNameEdited
? sanitizeBranchName(branchName)
: generatedBranchName;
: generateSlugFromTitle(title);
const applyPrefix = !branchNameEdited;
const branchPreview =
branchSlug && applyPrefix && resolvedPrefix
? `${resolvedPrefix}/${branchSlug}`
: branchSlug;
const branchSlug = branchNameEdited
? sanitizeBranchName(branchName)
: generateSlugFromTitle(title);
const prefixWouldCollide = useMemo(() => {
if (!resolvedPrefix || !branchData?.branches?.length) return false;
const existingSet = new Set(
branchData.branches.map((b) => b.name.toLowerCase()),
);
return existingSet.has(resolvedPrefix.toLowerCase());
}, [resolvedPrefix, branchData?.branches]);
const applyPrefix = (!branchNameEdited || !branchSlug) && !prefixWouldCollide;
const branchPreview =
branchSlug && applyPrefix && resolvedPrefix
? `${resolvedPrefix}/${branchSlug}`
: branchSlug;
🤖 Prompt for AI Agents
In `@apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx`
around lines 133 - 142, The preview/prefix logic must match backend collision
and empty-edit behavior: compute branchSlug via sanitizeBranchName(branchName)
or generateSlugFromTitle(title) as you already do, then set applyPrefix to false
not only when branchNameEdited is true, but also when branchSlug is empty or
when the resolvedPrefix would be dropped by backend due to collision; i.e.
change applyPrefix to something like: !branchNameEdited && branchSlug !== '' &&
!isPrefixCollision(resolvedPrefix, branchSlug) (call an existing collision-check
util or small API/utility function that mirrors backend collision logic), and
use that applyPrefix for branchPreview generation so the UI matches backend
behavior (refer to branchNameEdited, sanitizeBranchName, generateSlugFromTitle,
resolvedPrefix, branchPreview).

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.

1 participant