From 39e9b064a38d4fb027ab2cc2cce0d41add5d3cef Mon Sep 17 00:00:00 2001 From: C Date: Sun, 29 Nov 2020 15:31:57 +0000 Subject: [PATCH] fix: relaxed major footer regex --- src/increment/mod.rs | 9 ++- src/increment/regex/mod.rs | 10 +-- src/increment/tests/major/body/mod.rs | 16 +++++ src/increment/tests/major/mod.rs | 92 +------------------------- src/increment/tests/major/title/mod.rs | 80 ++++++++++++++++++++++ 5 files changed, 108 insertions(+), 99 deletions(-) create mode 100644 src/increment/tests/major/body/mod.rs create mode 100644 src/increment/tests/major/title/mod.rs diff --git a/src/increment/mod.rs b/src/increment/mod.rs index 8e25c2c..0271350 100644 --- a/src/increment/mod.rs +++ b/src/increment/mod.rs @@ -115,8 +115,15 @@ fn log_patch_increment(commit_message: &str) { } fn is_major_increment(commit_message: &str) -> bool { + is_major_title_increment(commit_message) || is_major_footer_increment(commit_message) +} + +fn is_major_title_increment(commit_message: &str) -> bool { MAJOR_TITLE_INCREMENT_REGEX.is_match(commit_message) - || MAJOR_FOOTER_INCREMENT_REGEX.is_match(commit_message) +} + +fn is_major_footer_increment(commit_message: &str) -> bool { + MAJOR_FOOTER_INCREMENT_REGEX.is_match(commit_message) } fn is_minor_increment(commit_message: &str) -> bool { diff --git a/src/increment/regex/mod.rs b/src/increment/regex/mod.rs index fb379da..94c817e 100644 --- a/src/increment/regex/mod.rs +++ b/src/increment/regex/mod.rs @@ -16,14 +16,8 @@ lazy_static! { .as_str() ) .unwrap(); - pub(super) static ref MAJOR_FOOTER_INCREMENT_REGEX: Regex = Regex::new( - format!( - r"(?i)^({}){}:(.)*(\n)*BREAKING CHANGE:", - &*ANY_REGEX, &*OPTIONAL_SCOPE_REGEX - ) - .as_str() - ) - .unwrap(); + pub(super) static ref MAJOR_FOOTER_INCREMENT_REGEX: Regex = + Regex::new("(?i)\nBREAKING CHANGE:").unwrap(); pub(super) static ref PATCH_INCREMENT_REGEX: Regex = Regex::new( format!( r"(?i){}fix{}:", diff --git a/src/increment/tests/major/body/mod.rs b/src/increment/tests/major/body/mod.rs new file mode 100644 index 0000000..73dfc20 --- /dev/null +++ b/src/increment/tests/major/body/mod.rs @@ -0,0 +1,16 @@ +use rstest::rstest; + +use crate::increment::*; + +#[rstest( + commit_message, + case("refactor(ts)!: ship yargs.d.ts (#1671)\n\nBREAKING CHANGE: yargs now ships with its own types"), + case("chore: upgrade yargs-parser (#633)\n\n* chore: upgrade yargs-parser\r\nBREAKING CHANGE: coerce is now applied as a final step after other parsing is complete\r\n\r\n* add documentation for breaking changes in yargs-parser@4\r\n\r\n* fix: a few small editing nits\r\n\r\n* fix: bump yargs-parser again\r\n"), + case("fix!: calling parse multiple times now appropriately maintains state (#1137) (#1369)\n\nBREAKING CHANGE: previously to this fix methods like `yargs.getOptions()` contained the state of the last command to execute."), + case("fix(default): Remove undocumented alias of default() (#469)\n\nBREAKING CHANGE:\r\n\r\nremoved undocumented `defaults` alias for `default`.\r\n\r\n"), + case("feat: apply default builder to command() and apply fail() handlers globally (#583)\n\nBREAKING CHANGE: fail is now applied globally.\r\nBREAKING CHANGE: we now default to an empty builder function when command is executed with no builder."), + case("feat: tweaks to API surface based on user feedback (#1726)\n\nBREAKING CHANGE: tweaks to ESM/Deno API surface: now exports yargs function by default; getProcessArgvWithoutBin becomes hidBin; types now exported for Deno."), +)] +fn test_is_major_footer_increment(commit_message: &str) { + assert!(is_major_footer_increment(commit_message)); +} diff --git a/src/increment/tests/major/mod.rs b/src/increment/tests/major/mod.rs index aadef5c..e52a5bb 100644 --- a/src/increment/tests/major/mod.rs +++ b/src/increment/tests/major/mod.rs @@ -1,90 +1,2 @@ -use rstest::rstest; - -use crate::increment::*; - -#[rstest( - commit_message, - case("refactor!: drop support for Node 6"), - case("feat(deps)!: pull in yargs-parser@17.0.0 (#1553)\n\n") -)] -fn test_is_major_increment(commit_message: &str) { - assert_eq!(true, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case("build!(deps): updating build deps to latest versions") -)] -fn test_is_major_increment_invalid_preceding_exclamation(commit_message: &str) { - assert_eq!(true, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case("feat(yargs-parser)!: introduce single-digit boolean aliases (#1576)\n\n"), - case("feat(yargs parser)!: introduce single-digit boolean aliases (#1576)\n\n"), - case("feat(yargs_parser)!: introduce single-digit boolean aliases (#1576)\n\n") -)] -fn test_is_major_increment_invalid_scope(commit_message: &str) { - assert_eq!(true, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case("fix(default): Remove undocumented alias of default() (#469)\n\nBREAKING CHANGE:\r\n\r\nremoved undocumented `defaults` alias for `default`.\r\n\r\n"), - case("feat: apply default builder to command() and apply fail() handlers globally (#583)\n\nBREAKING CHANGE: fail is now applied globally.\r\nBREAKING CHANGE: we now default to an empty builder function when command is executed with no builder."), - case("feat: tweaks to API surface based on user feedback (#1726)\n\nBREAKING CHANGE: tweaks to ESM/Deno API surface: now exports yargs function by default; getProcessArgvWithoutBin becomes hidBin; types now exported for Deno."), -)] -fn test_is_major_increment_footer(commit_message: &str) { - assert_eq!(true, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case("build: switch to action for release-please (#1657)"), - case("chore(ts): tsify lib/middleware (#1636)\n\n"), - case("fix(i18n): Japanese translation phrasing (#1619)\n\n"), - case("feat: add usage for single-digit boolean aliases (#1580)\n\n") -)] -fn test_is_not_major_increment(commit_message: &str) { - assert_eq!(false, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case(" refactor!: drop support for Node 6"), - case("\tfeat(deps)!: pull in yargs-parser@17.0.0 (#1553)\n\n") -)] -fn test_is_major_increment_preceding_whitespace(commit_message: &str) { - assert_eq!(true, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case("\n\rbuild: switch to action for release-please (#1657)"), - case(" chore(ts): tsify lib/middleware (#1636)\n\n"), - case(" fix(i18n): Japanese translation phrasing (#1619)\n\n"), - case("\tfeat: add usage for single-digit boolean aliases (#1580)\n\n") -)] -fn test_is_not_major_increment_preceding_whitespace(commit_message: &str) { - assert_eq!(false, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case("refactor( )!: drop support for Node 6"), - case("feat()!: pull in yargs-parser@17.0.0 (#1553)\n\n") -)] -fn test_is_major_increment_empty_scope(commit_message: &str) { - assert_eq!(true, is_major_increment(commit_message)); -} - -#[rstest( - commit_message, - case("build( ): switch to action for release-please (#1657)"), - case("chore(): tsify lib/middleware (#1636)\n\n"), - case("fix( ): Japanese translation phrasing (#1619)\n\n") -)] -fn test_is_not_major_increment_empty_scope(commit_message: &str) { - assert_eq!(false, is_major_increment(commit_message)); -} +mod body; +mod title; diff --git a/src/increment/tests/major/title/mod.rs b/src/increment/tests/major/title/mod.rs new file mode 100644 index 0000000..07c57d3 --- /dev/null +++ b/src/increment/tests/major/title/mod.rs @@ -0,0 +1,80 @@ +use rstest::rstest; + +use crate::increment::*; + +#[rstest( + commit_message, + case("refactor!: drop support for Node 6"), + case("feat(deps)!: pull in yargs-parser@17.0.0 (#1553)\n\n") +)] +fn test_is_major_title_increment(commit_message: &str) { + assert!(is_major_title_increment(commit_message)); +} + +#[rstest( + commit_message, + case("build!(deps): updating build deps to latest versions") +)] +fn test_is_major_title_increment_invalid_preceding_exclamation(commit_message: &str) { + assert!(is_major_title_increment(commit_message)); +} + +#[rstest( + commit_message, + case("feat(yargs-parser)!: introduce single-digit boolean aliases (#1576)\n\n"), + case("feat(yargs parser)!: introduce single-digit boolean aliases (#1576)\n\n"), + case("feat(yargs_parser)!: introduce single-digit boolean aliases (#1576)\n\n") +)] +fn test_is_major_title_increment_invalid_scope(commit_message: &str) { + assert!(is_major_title_increment(commit_message)); +} + +#[rstest( + commit_message, + case(" refactor!: drop support for Node 6"), + case("\tfeat(deps)!: pull in yargs-parser@17.0.0 (#1553)\n\n") +)] +fn test_is_major_title_increment_preceding_whitespace(commit_message: &str) { + assert!(is_major_title_increment(commit_message)); +} + +#[rstest( + commit_message, + case("build: switch to action for release-please (#1657)"), + case("chore(ts): tsify lib/middleware (#1636)\n\n"), + case("fix(i18n): Japanese translation phrasing (#1619)\n\n"), + case("feat: add usage for single-digit boolean aliases (#1580)\n\n") +)] +fn test_is_not_major_title_increment(commit_message: &str) { + assert_eq!(false, is_major_title_increment(commit_message)); +} + +#[rstest( + commit_message, + case("\n\rbuild: switch to action for release-please (#1657)"), + case(" chore(ts): tsify lib/middleware (#1636)\n\n"), + case(" fix(i18n): Japanese translation phrasing (#1619)\n\n"), + case("\tfeat: add usage for single-digit boolean aliases (#1580)\n\n") +)] +fn test_is_not_major_title_increment_preceding_whitespace(commit_message: &str) { + assert_eq!(false, is_major_title_increment(commit_message)); +} + +#[rstest( + commit_message, + case("refactor( )!: drop support for Node 6"), + case("feat()!: pull in yargs-parser@17.0.0 (#1553)\n\n") +)] +fn test_is_major_title_increment_empty_scope(commit_message: &str) { + assert!(is_major_title_increment(commit_message)); +} + +#[rstest( + commit_message, + case("build( ): switch to action for release-please (#1657)"), + case("chore(): tsify lib/middleware (#1636)\n\n"), + case("fix( ): Japanese translation phrasing (#1619)\n\n") +)] +fn test_is_not_major_title_increment_empty_scope(commit_message: &str) { + assert_eq!(false, is_major_title_increment(commit_message)); +}