51 lines
1.6 KiB
Rust
51 lines
1.6 KiB
Rust
use regex::Regex;
|
|
use rust_util::util_term::{BOLD, UNDER, END};
|
|
use crate::template::CommitMsgCheck;
|
|
|
|
const DEFAULT_COMMIT_MSG_REGEXP: &str = "^(feat|fix|docs|style|refactor|test|chore)(\\([\\w\\-_.]+\\))?:\\s*.*";
|
|
|
|
pub struct CommitMsgCheckRegex {
|
|
regex: Regex,
|
|
hint: String,
|
|
}
|
|
|
|
impl CommitMsgCheck for CommitMsgCheckRegex {
|
|
fn check(&self, msg: &str) -> bool {
|
|
self.regex.is_match(msg)
|
|
}
|
|
|
|
fn print_hint(&self) {
|
|
println!("[USAGE] {}", self.hint);
|
|
}
|
|
}
|
|
|
|
impl CommitMsgCheckRegex {
|
|
pub fn new_default() -> Self {
|
|
Self {
|
|
regex: Regex::new(DEFAULT_COMMIT_MSG_REGEXP).unwrap(),
|
|
hint: format!(r#"Please follow the commit spec:
|
|
Format: {b}<type>{e}(<scope>){b}: <subject>{e}
|
|
<scope> is optional
|
|
|
|
{b}feat{e}: add hat wobble
|
|
^--^ ^------------^
|
|
| |
|
|
| +-> Summary in present tense.
|
|
|
|
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test.
|
|
|
|
{b}feat{e} : new feature for the user, not a new feature for build script
|
|
{b}fix{e} : bug fix for the user, not a fix to a build script
|
|
{b}docs{e} : changes to the documentation
|
|
{b}style{e} : formatting, missing semi colons, etc; no production code change
|
|
{b}refactor{e} : refactoring production code, eg. renaming a variable
|
|
{b}test{e} : adding missing tests, refactoring tests; no production code change
|
|
{b}chore{e} : updating grunt tasks etc; no production code change
|
|
|
|
Reference: {u}https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716{e}
|
|
or mirror: {u}https://hatter.ink/wiki/view_raw.action?__access_token=PUBLIC&id=42{e}
|
|
"#, b = BOLD, e = END, u = UNDER),
|
|
}
|
|
}
|
|
}
|