feat: pre-populate commit dialog with heuristic message from git diff

Generate a commit message from modified files (e.g. "Update winter-2026"
or "Update 12 notes") and pre-fill the CommitDialog textarea so users can
commit immediately or edit the suggestion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Test
2026-03-30 16:30:54 +02:00
parent 81f986a065
commit 6b0bb5173c
5 changed files with 139 additions and 4 deletions

View File

@@ -78,4 +78,30 @@ describe('CommitDialog', () => {
const { container } = render(<CommitDialog open={false} modifiedCount={3} onCommit={onCommit} onClose={onClose} />)
expect(container.querySelector('textarea')).toBeNull()
})
it('pre-populates message with suggestedMessage', () => {
render(<CommitDialog open={true} modifiedCount={3} suggestedMessage="Update alpha, beta" onCommit={onCommit} onClose={onClose} />)
const textarea = screen.getByPlaceholderText('Commit message...')
expect(textarea).toHaveValue('Update alpha, beta')
})
it('enables Commit button when suggestedMessage is provided', () => {
render(<CommitDialog open={true} modifiedCount={3} suggestedMessage="Update alpha" onCommit={onCommit} onClose={onClose} />)
expect(getCommitButton()).not.toBeDisabled()
})
it('submits suggestedMessage on Cmd+Enter without user edits', () => {
render(<CommitDialog open={true} modifiedCount={3} suggestedMessage="Update alpha" onCommit={onCommit} onClose={onClose} />)
const textarea = screen.getByPlaceholderText('Commit message...')
fireEvent.keyDown(textarea, { key: 'Enter', metaKey: true })
expect(onCommit).toHaveBeenCalledWith('Update alpha')
})
it('allows user to edit the suggested message', () => {
render(<CommitDialog open={true} modifiedCount={3} suggestedMessage="Update alpha" onCommit={onCommit} onClose={onClose} />)
const textarea = screen.getByPlaceholderText('Commit message...')
fireEvent.change(textarea, { target: { value: 'fix: corrected typo in alpha' } })
fireEvent.click(getCommitButton())
expect(onCommit).toHaveBeenCalledWith('fix: corrected typo in alpha')
})
})

View File

@@ -6,20 +6,21 @@ import { Badge } from '@/components/ui/badge'
interface CommitDialogProps {
open: boolean
modifiedCount: number
suggestedMessage?: string
onCommit: (message: string) => void
onClose: () => void
}
export function CommitDialog({ open, modifiedCount, onCommit, onClose }: CommitDialogProps) {
export function CommitDialog({ open, modifiedCount, suggestedMessage, onCommit, onClose }: CommitDialogProps) {
const [message, setMessage] = useState('')
const inputRef = useRef<HTMLTextAreaElement>(null)
useEffect(() => {
if (open) {
setMessage('') // eslint-disable-line react-hooks/set-state-in-effect -- reset on dialog open
setMessage(suggestedMessage ?? '') // eslint-disable-line react-hooks/set-state-in-effect -- reset on dialog open
setTimeout(() => inputRef.current?.focus(), 50)
}
}, [open])
}, [open]) // eslint-disable-line react-hooks/exhaustive-deps -- only reset when dialog opens
const handleSubmit = () => {
const trimmed = message.trim()