Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit 215176e

Browse files
committed
feat: Add an option to amend a TODO in the commit message if not all DoD checks are ticked
TODO: - [ ] Relevant documentation (code comments, READMEs, etc.) is updated.
1 parent 5826437 commit 215176e

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

src/main.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fs;
55
use anyhow::{Result, Context};
66
use clap::Parser;
77
use colored::Colorize;
8-
use dialoguer::{MultiSelect, theme::ColorfulTheme};
8+
use dialoguer::{MultiSelect, theme::ColorfulTheme, Confirm};
99

1010
#[derive(Debug, Deserialize)]
1111
struct DodConfig {
@@ -21,12 +21,22 @@ fn read_dod_config() -> Result<DodConfig> {
2121
Ok(config)
2222
}
2323

24-
fn run_checklist_interactive(checklist: &[String]) -> Result<bool> {
24+
fn run_checklist_interactive(checklist: &[String]) -> anyhow::Result<Vec<usize>> {
2525
let selections = MultiSelect::with_theme(&ColorfulTheme::default())
2626
.with_prompt("Please confirm each item before committing:")
27-
.items(&checklist)
27+
.items(checklist)
2828
.interact()?;
29-
Ok(selections.len() == checklist.len())
29+
Ok(selections)
30+
}
31+
32+
fn build_todo_footer(checklist: &[String], checked_indices: &[usize]) -> String {
33+
let mut footer = String::from("\nTODO:\n");
34+
for (i, item) in checklist.iter().enumerate() {
35+
if !checked_indices.contains(&i) {
36+
footer.push_str(&format!("- [ ] {}\n", item));
37+
}
38+
}
39+
footer
3040
}
3141

3242
fn main() -> anyhow::Result<()> {
@@ -44,19 +54,27 @@ fn main() -> anyhow::Result<()> {
4454
}
4555
cli::Commands::Commit { r#type, scope, message, no_verify} => {
4656
println!("--- Committing changes ---");
57+
let scope_part = scope.map_or("".to_string(), |s| format!("({})", s));
58+
let header = format!("{}{}: {}", r#type, scope_part, message);
59+
let mut commit_message = format!("{}", header);
60+
4761
if !no_verify {
62+
let checked = run_checklist_interactive(&config.checklist)?;
63+
if Confirm::with_theme(&ColorfulTheme::default())
64+
.with_prompt("Warning: Not all DoD items were checked. Proceed by adding a 'TODO' list to the commit message? (Y/n)")
65+
.interact()?
66+
{
67+
let todo_footer = build_todo_footer(&config.checklist, &checked);
68+
commit_message.push_str(&todo_footer);
69+
} else {
70+
println!("Commit aborted.");
71+
return Ok(());
72+
}
4873
if config.issue_reference_required.unwrap_or(false) {
4974
println!("{}", "Issue reference is required for commits.".red());
5075
return Err(anyhow::anyhow!("Issue reference required"));
5176
}
52-
if !run_checklist_interactive(&config.checklist)? {
53-
println!("Not all checklist items confirmed. Commit aborted.");
54-
return Ok(());
55-
}
5677
}
57-
let scope_part = scope.map_or("".to_string(), |s| format!("({})", s));
58-
let header = format!("{}{}: {}", r#type, scope_part, message);
59-
let commit_message = format!("{}", header);
6078

6179
println!("{}", format!("Commit message will be:\n---\n{}\n---", commit_message).blue());
6280
// Stage changes first, before any other operations.

0 commit comments

Comments
 (0)