Repository navigation
feat(desktop): add configurable branch name prefix - #1015
Conversation
Add settings to configure how branch names are prefixed when creating new workspaces. Supports five modes: GitHub username (default), git author name, static "feat" prefix, custom prefix, or no prefix. Settings available both globally (Features settings) and per-project (Project settings), with project settings overriding global defaults.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds configurable branch-prefixing: new DB columns and types, APIs to get/set branch-prefix and Git info, utilities to compute prefixes, workspace creation updated to apply prefixes, and frontend UI to configure and preview global/project branch-prefix modes. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI as Frontend UI
participant API as Backend API
participant DB as Database
participant Git as Git Utils
User->>UI: Configure branch prefix (global or project)
UI->>API: setBranchPrefix() / updateProject()
API->>DB: Persist branchPrefixMode & branchPrefixCustom
DB-->>API: Saved
API-->>UI: Success
Note over User,Git: Later — creating a workspace
User->>UI: Create workspace
UI->>API: createWorkspace mutation
API->>DB: Read project & global settings
DB-->>API: branch prefix config
API->>Git: getBranchPrefix(repoPath, mode, customPrefix)
Git-->>API: Computed prefix (or null)
API->>API: Generate/sanitize branch name with prefix
API->>DB: Create workspace record (branch name)
DB-->>API: Created
API-->>UI: Workspace ready
UI-->>User: Workspace created
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts`:
- Around line 305-313: The code currently mixes levels: it reads prefixMode from
project but still falls back to global customPrefix even when the project
explicitly set branchPrefixMode; change the logic so mode and customPrefix come
from the same source (project if project.branchPrefixMode is defined, otherwise
globalSettings) and only fallback to the default "github" when neither level
provides a mode. Specifically, replace the current assignments for prefixMode
and customPrefix (which use project.branchPrefixMode and
project.branchPrefixCustom) with a branch that (1) if project.branchPrefixMode
!== undefined/null then set prefixMode = project.branchPrefixMode and
customPrefix = project.branchPrefixCustom, (2) else set prefixMode =
globalSettings?.branchPrefixMode ?? "github" and customPrefix =
globalSettings?.branchPrefixCustom.
In
`@apps/desktop/src/renderer/routes/_authenticated/settings/behavior/components/BehaviorSettings/BehaviorSettings.tsx`:
- Around line 71-85: The onError handler for the setBranchPrefix mutation
(created via electronTrpc.settings.setBranchPrefix.useMutation) currently
swallows errors; update the onError callback to log the error with context
before restoring previous data: capture the incoming error parameter, then call
console.error with a prefixed message like "[settings/setBranchPrefix] Failed to
update branch prefix:" followed by the error and any relevant vars/context;
leave the existing restore logic using
utils.settings.getBranchPrefix.setData(...) intact so failures are both logged
and rolled back.
In
`@apps/desktop/src/renderer/routes/_authenticated/settings/project/`$projectId/components/ProjectSettings/ProjectSettings.tsx:
- Around line 37-72: The project patch mutations (used by updateProject and
triggered from handleBranchPrefixModeChange and handleCustomPrefixChange) need
optimistic cache updates so the controlled Input bound to
project.branchPrefixCustom reflects keystrokes immediately; implement an
onMutate handler on electronTrpc.projects.update.useMutation that snapshots the
current utils.projects.get.getData({ id: projectId }), applies the optimistic
patch via utils.projects.get.setData({ id: projectId }, updatedProject)
(updating branchPrefixMode and branchPrefixCustom per the patch), and then
rollback the snapshot in onError and call utils.projects.get.invalidate({ id:
projectId }) in onSettled; apply the same optimistic pattern to the other
mutation referenced in the comment (the mutation around lines 141-145).
🧹 Nitpick comments (1)
apps/desktop/src/renderer/routes/_authenticated/settings/behavior/components/BehaviorSettings/BehaviorSettings.tsx (1)
18-26: Consider centralizing BranchPrefixMode labels to prevent drift.This label map is duplicated in ProjectSettings and should stay aligned with backend modes; a shared constant/module would reduce maintenance risk.
Show a live preview of what branch names will look like based on the selected prefix mode. Uses the user's actual GitHub username or git author name when available.
Adds columns for configurable branch name prefix to projects and settings tables.
- Fix project override logic to use project's customPrefix when mode is set - Add error logging to branch prefix mutation handlers - Add optimistic updates to project settings mutation
Previously the prefix was only applied to auto-generated branch names. Now user-provided names also get the configured prefix.
- Import BranchPrefixMode from @superset/local-db instead of duplicating - Extract shared BRANCH_PREFIX_MODE_LABELS to utils/branch-prefix - Remove redundant "feat" prefix option (use custom instead) - Make branch prefix setting a single-row layout - Add trailing newline to migration file
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@apps/desktop/src/renderer/routes/_authenticated/settings/behavior/components/BehaviorSettings/BehaviorSettings.tsx`:
- Around line 85-90: handleBranchPrefixModeChange currently clears customPrefix
whenever mode !== "custom", causing the user's previous custom prefix to be
lost; change the behavior so setBranchPrefix.mutate always sends the last known
custom prefix (e.g., branchPrefix?.customPrefix or a component state like
lastCustomPrefix) and only set customPrefix to null when the user explicitly
clears the input. Update the handler (handleBranchPrefixModeChange) and ensure
the input's onChange updates lastCustomPrefix/branchPrefix so toggling modes
preserves the value.
🧹 Nitpick comments (1)
apps/desktop/src/renderer/routes/_authenticated/settings/behavior/components/BehaviorSettings/BehaviorSettings.tsx (1)
92-96: Avoid persisting on every keystroke.
onChangetriggers a mutation for each keypress, which can spam IPC/DB writes and hurt typing responsiveness. Consider buffering input locally and persisting on blur/Enter or with a debounce, while still using the local draft for the live preview.Also applies to: 181-188
- Change default branch prefix mode from "github" to "none" - Add sanitizePrefix function to trim/sanitize custom prefix on blur - Update both global settings and project settings
- Add resolveBranchPrefix function to shared/utils/branch.ts - Update NewWorkspaceModal to show correct branch preview with prefix - Remove duplicate switch logic from BehaviorSettings and ProjectSettings - Use sanitizeSegment from shared utils instead of local sanitizePrefix
Summary
Adds configurable branch name prefixes when creating workspaces.
Prefix modes:
kkjcheng/feature-namekevin-cheng/feature-namefeat/feature-nameyour-prefix/feature-namefeature-nameSettings can be configured globally (Behavior settings) or per-project (Project settings). Project-level settings override global defaults.
UI: Settings include a live preview showing the generated branch name format.
Note: Branch names are always sanitized (lowercased, spaces to dashes, special chars removed) regardless of prefix mode.
Summary by CodeRabbit
New Features
Enhancements
Chores
✏️ Tip: You can customize this high-level summary in your review settings.