feat: add AutoGit idle and inactive checkpoints
This commit is contained in:
26
src/utils/automaticCommitMessage.test.ts
Normal file
26
src/utils/automaticCommitMessage.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { generateAutomaticCommitMessage } from './automaticCommitMessage'
|
||||
import type { ModifiedFile } from '../types'
|
||||
|
||||
function file(relativePath: string): ModifiedFile {
|
||||
return {
|
||||
path: `/vault/${relativePath}`,
|
||||
relativePath,
|
||||
status: 'modified',
|
||||
}
|
||||
}
|
||||
|
||||
describe('generateAutomaticCommitMessage', () => {
|
||||
it('returns an empty string when there is nothing to commit', () => {
|
||||
expect(generateAutomaticCommitMessage([])).toBe('')
|
||||
})
|
||||
|
||||
it('counts markdown files as notes', () => {
|
||||
expect(generateAutomaticCommitMessage([file('note-a.md')])).toBe('Updated 1 note')
|
||||
expect(generateAutomaticCommitMessage([file('note-a.md'), file('note-b.md')])).toBe('Updated 2 notes')
|
||||
})
|
||||
|
||||
it('falls back to files when any modified path is not markdown', () => {
|
||||
expect(generateAutomaticCommitMessage([file('note-a.md'), file('attachments/image.png')])).toBe('Updated 2 files')
|
||||
})
|
||||
})
|
||||
17
src/utils/automaticCommitMessage.ts
Normal file
17
src/utils/automaticCommitMessage.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { ModifiedFile } from '../types'
|
||||
|
||||
function pluralize(count: number, singular: string, plural: string): string {
|
||||
return count === 1 ? singular : plural
|
||||
}
|
||||
|
||||
function allFilesAreNotes(files: ModifiedFile[]): boolean {
|
||||
return files.every((file) => file.relativePath.toLowerCase().endsWith('.md'))
|
||||
}
|
||||
|
||||
export function generateAutomaticCommitMessage(files: ModifiedFile[]): string {
|
||||
if (files.length === 0) return ''
|
||||
const noun = allFilesAreNotes(files)
|
||||
? pluralize(files.length, 'note', 'notes')
|
||||
: pluralize(files.length, 'file', 'files')
|
||||
return `Updated ${files.length} ${noun}`
|
||||
}
|
||||
Reference in New Issue
Block a user