Skip to content

Commit 902265f

Browse files
committed
fix(commit): improve conventional commits structure
Automatically disable gitmoji when using conventional commits preset to ensure strict compliance with the conventional commits specification. - Modify prompt creation to detect conventional preset and disable gitmoji - Update service to prevent gitmoji usage with conventional preset - Expand conventional preset instructions with comprehensive specification - Add explicit emoji field nullification for conventional commits - Include scope usage guidelines and valid type definitions - Provide clear examples of correct and incorrect commit formats
1 parent bb4c7c5 commit 902265f

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

src/commit/prompt.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ pub fn create_system_prompt(config: &Config) -> anyhow::Result<String> {
4848

4949
prompt.push_str(get_combined_instructions(config).as_str());
5050

51-
if config.use_gitmoji {
51+
// Check if using conventional commits preset - if so, explicitly disable gitmoji
52+
let is_conventional = config.instruction_preset == "conventional";
53+
54+
if config.use_gitmoji && !is_conventional {
5255
prompt.push_str(
5356
"\n\nUse a single gitmoji at the start of the commit message. \
5457
Choose the most relevant emoji from the following list:\n\n",
5558
);
5659
prompt.push_str(&get_gitmoji_list());
60+
} else if is_conventional {
61+
prompt.push_str(
62+
"\n\nIMPORTANT: This is using Conventional Commits format. \
63+
DO NOT include any emojis in the commit message. \
64+
Set the emoji field to null in your response.",
65+
);
5766
}
5867

5968
prompt.push_str("

src/commit/service.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ impl IrisCommitService {
236236
let mut config_clone = self.config.clone();
237237

238238
// Check if the preset exists and is valid for commits
239-
if preset.is_empty() {
239+
let effective_preset = if preset.is_empty() {
240240
config_clone.instruction_preset = "default".to_string();
241+
"default"
241242
} else {
242243
let library = get_instruction_preset_library();
243244
if let Some(preset_info) = library.get_preset(preset) {
@@ -248,11 +249,13 @@ impl IrisCommitService {
248249
);
249250
}
250251
config_clone.instruction_preset = preset.to_string();
252+
preset
251253
} else {
252254
log_debug!("Preset '{}' not found, using default", preset);
253255
config_clone.instruction_preset = "default".to_string();
256+
"default"
254257
}
255-
}
258+
};
256259

257260
config_clone.instructions = instructions.to_string();
258261

@@ -273,8 +276,9 @@ impl IrisCommitService {
273276
)
274277
.await?;
275278

276-
// Apply gitmoji setting
277-
if !self.use_gitmoji {
279+
// Apply gitmoji setting - automatically disable for conventional commits
280+
let should_use_gitmoji = self.use_gitmoji && effective_preset != "conventional";
281+
if !should_use_gitmoji {
278282
generated_message.emoji = None;
279283
}
280284

src/instruction_presets.rs

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,61 @@ impl InstructionPresetLibrary {
253253
InstructionPreset {
254254
name: "Conventional Commits".to_string(),
255255
description: "Follow the Conventional Commits specification".to_string(),
256-
instructions: "Use the Conventional Commits format: <type>[optional scope]: <description>\n\
257-
Valid types are: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert\n\
258-
Use the imperative mood in the subject line\n\
259-
Limit the subject line to 50 characters if possible, never exceed 72\n\
260-
Separate subject from body with a blank line\n\
261-
Use the body to explain what and why, wrapping at 72 characters".to_string(),
256+
instructions: "STRICT CONVENTIONAL COMMITS SPECIFICATION - FOLLOW EXACTLY:\n\n\
257+
FORMAT: <type>[optional scope]: <description>\n\n\
258+
MANDATORY RULES:\n\
259+
1. NO EMOJIS - Conventional commits never use emojis\n\
260+
2. NO CAPITALIZATION of type or scope\n\
261+
3. Subject line MUST be 50 characters or less\n\
262+
4. Description MUST be in imperative mood (add, fix, update - NOT added, fixed, updated)\n\
263+
5. NO period at end of subject line\n\
264+
6. USE SCOPES when files relate to specific components/modules\n\n\
265+
SCOPE USAGE - STRONGLY PREFERRED:\n\
266+
- For API changes: feat(api): add user endpoint\n\
267+
- For UI changes: feat(ui): add login form\n\
268+
- For auth: fix(auth): handle expired tokens\n\
269+
- For database: feat(db): add user table migration\n\
270+
- For tests: test(auth): add login validation tests\n\
271+
- For config: chore(config): update database settings\n\
272+
- For docs: docs(readme): update installation steps\n\
273+
- For CLI: feat(cli): add new command option\n\
274+
- For build: build(deps): update dependency versions\n\
275+
- Analyze the changed files and pick the most relevant component\n\n\
276+
VALID TYPES (use ONLY these):\n\
277+
- feat: new feature for the user\n\
278+
- fix: bug fix for the user\n\
279+
- docs: changes to documentation\n\
280+
- style: formatting, missing semicolons, etc (no code change)\n\
281+
- refactor: code change that neither fixes bug nor adds feature\n\
282+
- perf: code change that improves performance\n\
283+
- test: adding missing tests or correcting existing tests\n\
284+
- build: changes that affect build system or external dependencies\n\
285+
- ci: changes to CI configuration files and scripts\n\
286+
- chore: other changes that don't modify src or test files\n\
287+
- revert: reverts a previous commit\n\n\
288+
SCOPE SELECTION RULES:\n\
289+
- Look at the file paths and identify the main component/module\n\
290+
- Use the most specific relevant scope (prefer 'auth' over 'api' if it's auth-specific)\n\
291+
- Common scopes: api, ui, auth, db, cli, config, deps, core, utils, tests\n\
292+
- If multiple unrelated components, omit scope or use broader one\n\n\
293+
BODY (optional):\n\
294+
- Separate from subject with blank line\n\
295+
- Wrap at 72 characters\n\
296+
- Explain what and why, not how\n\
297+
- Use imperative mood\n\n\
298+
BREAKING CHANGES:\n\
299+
- Add '!' after type/scope: feat(api)!: remove deprecated endpoints\n\
300+
- OR include 'BREAKING CHANGE:' in footer\n\n\
301+
EXAMPLES:\n\
302+
✓ feat(auth): add OAuth login\n\
303+
✓ fix(api): resolve timeout issue\n\
304+
✓ docs(readme): update contributing guidelines\n\
305+
✓ feat(ui)!: remove deprecated button component\n\
306+
✓ refactor(core): extract validation logic\n\
307+
✗ Add user authentication (missing type and scope)\n\
308+
✗ feat: Add user authentication (missing scope when relevant)\n\
309+
✗ feat: adds user authentication (wrong mood)\n\
310+
✗ 🎉 feat(auth): add authentication (has emoji)".to_string(),
262311
emoji: "📏".to_string(),
263312
preset_type: PresetType::Both,
264313
},

0 commit comments

Comments
 (0)