Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make every configuration field optional and use default if not passed #48

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ anyhow = "1.0.75"

[dev-dependencies]
assert_fs = "1.0.13"
serial_test = "2.0.0"

[package.metadata.deb]
name = "commit"
Expand Down
43 changes: 0 additions & 43 deletions commit-default.json

This file was deleted.

39 changes: 0 additions & 39 deletions commit.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
{
"config": {
"subject_separator": ": ",
"scope_prefix": "(",
"scope_suffix": ")",
"pre_commit": "./pre-commit.sh"
},
"commit_types": [
{ "name": "feat", "description": "A new feature" },
{ "name": "fix", "description": "A bug fix" },
{ "name": "docs", "description": "Documentation only changes" },
{
"name": "style",
"description": "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)"
},
{
"name": "refactor",
"description": "A code change that neither fixes a bug nor adds a feature"
},
{
"name": "perf",
"description": "A code change that improves performance"
},
{
"name": "test",
"description": "Adding missing tests or correcting existing tests"
},
{
"name": "chore",
"description": "Other changes that don't modify src or test files"
}
],
"commit_scopes": [
{ "name": "custom", "description": "Custom scope" },
{ "name": "none", "description": "No scope" }
],
"msg": {
"commit_type": "What type of commit you will made?",
"commit_scope": "What scope of commit you will made? (Optional)",
"commit_description": "Write a SHORT, IMPERATIVE tense description of the change:",
"commit_body": "Provide a LONGER description of the change (Optional):",
"commit_footer": "List any ISSUES CLOSED by this change E.g.: #31, #34 (Optional):"
}
}
2 changes: 1 addition & 1 deletion src/commit_message/message_build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]
mod tests;

use crate::config::Config;
use crate::commit_pattern::Config;

pub struct MessageBuilder {
config: Config,
Expand Down
2 changes: 1 addition & 1 deletion src/commit_message/message_build/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::commit_message::message_build::MessageBuilder;
use crate::config::Config;
use crate::commit_pattern::Config;

fn message_with_config(config: Config) -> String {
let mut builder = MessageBuilder::new(config);
Expand Down
4 changes: 2 additions & 2 deletions src/commit_message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ mod message_build;
mod prompt;

use anyhow::{anyhow, Result};

use crate::config::CommitPattern;
use message_build::MessageBuilder;
use prompt::Prompt;

use crate::commit_pattern::CommitPattern;

pub fn make_message_commit(pattern: CommitPattern) -> Result<String> {
let mut message_inquirer = MessageInquirer::new(pattern.clone());
let skip_commit = pattern.skip_commit;
Expand Down
2 changes: 1 addition & 1 deletion src/commit_message/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::Type;
use crate::commit_pattern::Type;

use inquire::{
required,
Expand Down
39 changes: 39 additions & 0 deletions src/commit_pattern/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use serde::Deserialize;

#[derive(Deserialize, Clone)]
pub struct Config {
pub type_prefix: Option<String>,
pub type_suffix: Option<String>,
#[serde(default = "Config::subject_separator")]
pub subject_separator: String,
#[serde(default = "Config::scope_prefix")]
pub scope_prefix: String,
#[serde(default = "Config::scope_suffix")]
pub scope_suffix: String,
pub pre_commit: Option<String>,
}

impl Config {
fn subject_separator() -> String {
": ".to_owned()
}
fn scope_prefix() -> String {
"(".to_owned()
}
fn scope_suffix() -> String {
")".to_owned()
}
}

impl Default for Config {
fn default() -> Self {
Self {
type_prefix: None,
type_suffix: None,
subject_separator: Self::subject_separator(),
scope_prefix: Self::scope_prefix(),
scope_suffix: Self::scope_suffix(),
pre_commit: None,
}
}
}
Loading
Loading