Skip to content

Commit

Permalink
fix: relaxed major footer regex
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperC286 committed Nov 29, 2020
1 parent e79c0d0 commit 39e9b06
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 99 deletions.
9 changes: 8 additions & 1 deletion src/increment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 2 additions & 8 deletions src/increment/regex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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{}:",
Expand Down
16 changes: 16 additions & 0 deletions src/increment/tests/major/body/mod.rs
Original file line number Diff line number Diff line change
@@ -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));
}
92 changes: 2 additions & 90 deletions src/increment/tests/major/mod.rs
Original file line number Diff line number Diff line change
@@ -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 [email protected] (#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 [email protected] (#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 [email protected] (#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;
80 changes: 80 additions & 0 deletions src/increment/tests/major/title/mod.rs
Original file line number Diff line number Diff line change
@@ -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 [email protected] (#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 [email protected] (#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 [email protected] (#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));
}

0 comments on commit 39e9b06

Please sign in to comment.