Skip to content

Commit

Permalink
feat!: add ability to skip breaking changes and issues questions
Browse files Browse the repository at this point in the history
closes #78
  • Loading branch information
its-danny committed Nov 23, 2023
1 parent 3ad9f87 commit 8cc6b30
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 137 deletions.
101 changes: 14 additions & 87 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ path = "src/lib/lib.rs"

[dependencies]
anyhow = "1.0"
clap = { version = "4.3", features = ["derive"] }
clap = { version = "4.4", features = ["derive"] }
cocogitto = { version = "5.3", default-features = false }
conventional_commit_parser = "0.9"
dirs = "5.0"
Expand Down
3 changes: 3 additions & 0 deletions meta/config/default.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
breaking_changes = true
issues = true

[[commit_types]]
name = "feat"
emoji = ""
Expand Down
61 changes: 36 additions & 25 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,59 @@ use koji::config::Config;
use koji::questions::create_prompt;

#[derive(Parser, Debug)]
#[clap(
#[command(
about = "🦊 An interactive CLI for creating conventional commits.",
version,
author
)]
struct Args {
#[clap(
#[arg(
short,
long,
help = "Path to a config file containing custom commit types"
help = "Enables autocomplete for scope prompt via scanning commit history"
)]
config: Option<String>,
autocomplete: Option<bool>,

#[arg(short, long, help = "Enables breaking change prompt")]
breaking_changes: Option<bool>,

#[clap(
#[arg(
short,
long,
help = "Prepend the commit summary with relevant emoji based on commit type"
help = "Path to a config file containing custom commit types"
)]
emoji: bool,

#[clap(long, help = "Bypass the emoji flag")]
no_emoji: bool,
config: Option<String>,

#[clap(
#[arg(
short,
long,
help = "Enables auto-complete for scope prompt via scanning commit history"
help = "Prepend the commit summary with relevant emoji based on commit type"
)]
autocomplete: bool,

#[clap(long, help = "Bypass the autocopmlete flag")]
no_autocomplete: bool,
emoji: Option<bool>,

#[clap(
#[arg(
long,
help = "Run as a git hook, writing the commit message to COMMIT_EDITMSG instead of committing"
)]
hook: bool,

#[arg(
short,
long,
help = "Enables issue prompt, which will append a reference to an issue in the commit body"
)]
issues: Option<bool>,
}

fn main() -> Result<()> {
// Get CLI args
let Args {
autocomplete,
breaking_changes,
config,
emoji,
no_emoji,
autocomplete,
no_autocomplete,
hook,
issues,
} = Args::parse();

// Find repo
Expand All @@ -82,19 +86,26 @@ fn main() -> Result<()> {
// Load config
let config = Config::new(config)?;

// Use emoji if set in config, or passed in via `-e`, and `--no-emoji` wasn't passed in
let emoji = config.emoji.unwrap_or(emoji) && !no_emoji || emoji;
// Use value of `autocomplete` if passed in, otherwise use value from config
let autocomplete = autocomplete.unwrap_or(config.autocomplete.unwrap_or(false));

// Use value of `breaking_changes` if passed in, otherwise use value from config
let breaking_changes = breaking_changes.unwrap_or(config.breaking_changes.unwrap_or(true));

// Use value of `emoji` if passed in, otherwise use value from config
let emoji = emoji.unwrap_or(config.emoji.unwrap_or(false));

// Use autocomplete if set in config, or passed in via `-a`, and `--no-autocomplete` wasn't passed in
let autocomplete =
config.autocomplete.unwrap_or(autocomplete) && !no_autocomplete || autocomplete;
// Use value of `issues` if passed in, otherwise use value from config
let issues = issues.unwrap_or(config.issues.unwrap_or(true));

// Get answers from interactive prompt
let answers = create_prompt(
&repo,
commit_message,
emoji,
autocomplete,
breaking_changes,
issues,
&config.commit_types,
)?;

Expand Down
16 changes: 11 additions & 5 deletions src/lib/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@ use std::{env::current_dir, fs::read_to_string, path::Path};

pub struct Config {
pub autocomplete: Option<bool>,
pub emoji: Option<bool>,
pub breaking_changes: Option<bool>,
pub commit_types: IndexMap<String, CommitType>,
pub emoji: Option<bool>,
pub issues: Option<bool>,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
pub struct CommitType {
pub name: String,
pub emoji: Option<String>,
pub description: String,
pub emoji: Option<String>,
pub name: String,
}

#[derive(Clone, Deserialize)]
struct ConfigTOML {
pub autocomplete: Option<bool>,
pub emoji: Option<bool>,
pub breaking_changes: Option<bool>,
#[serde(default)]
commit_types: Vec<CommitType>,
pub emoji: Option<bool>,
pub issues: Option<bool>,
}

impl Config {
Expand Down Expand Up @@ -78,8 +82,10 @@ impl Config {

Ok(Config {
autocomplete: config.autocomplete,
emoji: config.emoji,
breaking_changes: config.breaking_changes,
commit_types,
emoji: config.emoji,
issues: config.issues,
})
}
}
Expand Down
Loading

0 comments on commit 8cc6b30

Please sign in to comment.