Skip to content

Commit

Permalink
docs(README.md): Update commit message format options
Browse files Browse the repository at this point in the history
- Add new commit format options: `repo` and `custom`
- Explain the `--learn` and `--author` flags for learning repository and author-specific commit styles
- Clarify that learned styles will be used for future commits unless overridden with `--format`

BREAKING CHANGE: The `--learn` flag now supports both repository-wide and author-specific commit style learning. The learned styles will be used as the default format going forward.
  • Loading branch information
sidedwards committed Oct 24, 2024
1 parent 8badb3f commit 3c717d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,20 @@ The tool supports several commit message formats:
Signed-off-by: John Doe <john@example.com>
```

5. **Repository or Author-Specific**: Learn from repository history or specific author's style
5. **Repository-Specific** (`--learn`): Learn and use the commit style from your repository's history
```
# Learn commit style from repository history
# Learn and use repository-wide commit style
auto-commit --learn
```

# Learn commit style from specific author
6. **Author-Specific** (`--learn --author`): Learn and use a specific author's commit style
```
# Learn and use commit style from specific author
auto-commit --learn --author="user@example.com"
```

The learned styles (both repository and author-specific) are saved and will be used for future commits unless overridden with the `--format` flag.

## Requirements

- Git
Expand Down
50 changes: 28 additions & 22 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export enum CommitFormat {
CONVENTIONAL = 'conventional',
SEMANTIC = 'semantic',
ANGULAR = 'angular',
KERNEL = 'kernel'
KERNEL = 'kernel',
REPO = 'repo',
CUSTOM = 'custom',
}

// Then define all other functions and constants
Expand Down Expand Up @@ -463,6 +465,8 @@ async function main(): Promise<void> {
alias: { h: "help" },
});

let selectedFormat = CommitFormat.CONVENTIONAL; // Add this line here

// Handle --help flag
if (flags.help) {
console.log(`
Expand Down Expand Up @@ -544,34 +548,40 @@ For more information, visit: https://github.com/sidedwards/auto-commit

// Handle format selection
if (flags.learn) {
// Learning mode - analyze and store the style
const commits = await getCommitHistory(flags.author);
const styleGuide = await analyzeCommitStyle(commits, apiKey);

// Store as both author-specific (if specified) and default style
if (flags.author) {
await storeCommitStyle(styleGuide, flags.author);
try {
const commits = await getCommitHistory(flags.author);
const styleGuide = await analyzeCommitStyle(commits, apiKey);

if (flags.author) {
await storeCommitStyle(styleGuide, flags.author);
await storeDefaultFormat(CommitFormat.CUSTOM);
selectedFormat = CommitFormat.CUSTOM;
console.log(`\nLearned and saved commit style for ${flags.author}`);
console.log(`Using commit format: custom (${flags.author})`);
} else {
// Store repository style and use 'repo' as format
await storeCommitStyle(styleGuide);
await storeDefaultFormat(CommitFormat.REPO);
selectedFormat = CommitFormat.REPO;
console.log("\nLearned and saved commit style from repository");
console.log("Using commit format: repo");
}
} catch (error) {
console.error("Failed to learn commit style:", error);
console.log("Falling back to default commit style...");
}
await storeCommitStyle(styleGuide); // Store as default

// Remove this line - don't force Conventional format
// await storeDefaultFormat(CommitFormat.CONVENTIONAL);

console.log(`\nLearned and saved commit style${flags.author ? ` for ${flags.author}` : ''}`);
} else if (flags.format) {
// Explicit format specified
// Explicit format specified - store both format and its template
const formatInput = flags.format.toLowerCase();
let selectedFormat = CommitFormat.CONVENTIONAL;

// Handle common typos and variations
// Handle format selection as before
if (formatInput.includes('kern')) {
selectedFormat = CommitFormat.KERNEL;
} else if (formatInput.includes('sem')) {
selectedFormat = CommitFormat.SEMANTIC;
} else if (formatInput.includes('ang')) {
selectedFormat = CommitFormat.ANGULAR;
} else if (formatInput.includes('con')) {
selectedFormat = CommitFormat.CONVENTIONAL;
}

const template =
Expand All @@ -581,12 +591,10 @@ For more information, visit: https://github.com/sidedwards/auto-commit
CONVENTIONAL_FORMAT;

await storeCommitStyle(template);
// Store the format as default
await storeDefaultFormat(selectedFormat);
}

// Use format flag if provided
let selectedFormat = CommitFormat.CONVENTIONAL; // default
if (typeof flags.format === 'string') { // Type check the flag
const formatInput = flags.format.toLowerCase();
// Handle common typos and variations
Expand All @@ -603,8 +611,6 @@ For more information, visit: https://github.com/sidedwards/auto-commit
selectedFormat = await getDefaultFormat() || CommitFormat.CONVENTIONAL;
}

console.log(`Using commit format: ${selectedFormat}`);

if (flags.learn) {
try {
const commits = await getCommitHistory(flags.author);
Expand Down

0 comments on commit 3c717d0

Please sign in to comment.