diff --git a/README.md b/README.md index 5a972e6..daaf2b7 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ A tooling and language agnostic utility to calculate the next semantic version b * [Usage](#usage) + [Usage - Consecutive Mode](#usage-consecutive-mode) + [Usage - Batch Mode](#usage-batch-mode) - + [Usage - Additional Arguments](#usage-additional-arguments) + [Usage - Git Environment Variables](#usage-git-environment-variables) + [Usage - Logging](#usage-logging) * [CICD Examples](#cicd-examples) @@ -122,18 +121,6 @@ The minor Semantic Versioning increment increases the initial semantic version f ``` -### Usage - Additional Arguments -Additional command line flags can be passed to alter what and how the next Semantic Versioning is calculated. - - -| Flag | | -|---------------------------|-| -| --monorepo | The the next semantic version is calculated only from commits altering files which match any of these provided regexes, enabling usage within monorepos. | -| --git-history-mode | The mode to use when transversing the Git commit history of the Git commit range, to collect the Git commit messages to use in calculating the next semantic version. | -| --calculation-mode | The mode of calculation to use on the range of Commits to calculate the next semantic version. | -| --current-version | This semantic version is asserted to be equal or larger than the calculated semantic version. The calculated semantic version is not printed to standard out. If the assertion is not met then it exits with a non zero exit code. | - - ### Usage - Git Environment Variables When looking for a repository the Git environment variables are respected. When `${GIT_DIR}` is set, it takes precedence and Conventional Commits Next Version begins searching for a repository in the directory specified in `${GIT_DIR}`. diff --git a/end-to-end-tests/features/git_history_all_parents_mode.feature b/end-to-end-tests/features/git_history_all_parents_mode.feature deleted file mode 100644 index f3daef8..0000000 --- a/end-to-end-tests/features/git_history_all_parents_mode.feature +++ /dev/null @@ -1,15 +0,0 @@ -Feature: All the parents of merge commit's are parsed for their Git commit messages. - - - Scenario Outline: - Given the repository "" is cloned and checked out at the commit "". - When the argument --from-commit-hash is provided as "". - And the argument --from-version is provided as "". - Then the returned version should be "". - When the argument --git-history-mode is provided as "AllParents". - Then the returned version should be "". - - - Examples: - | repository | checkout_commit | from_commit_hash | from_version | default_expected_version | all_parents_expected_version | - | https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.1 | 1.3.30 | diff --git a/end-to-end-tests/features/git_history_first_parent_mode.feature b/end-to-end-tests/features/git_history_first_parent_mode.feature deleted file mode 100644 index 8ef0364..0000000 --- a/end-to-end-tests/features/git_history_first_parent_mode.feature +++ /dev/null @@ -1,13 +0,0 @@ -Feature: Only the first parent of merge commit's are parsed for their Git commit messages. - - - Scenario Outline: - Given the repository "" is cloned and checked out at the commit "". - When the argument --from-commit-hash is provided as "". - And the argument --from-version is provided as "". - Then the returned version should be "". - - - Examples: - | repository | checkout_commit | from_commit_hash | from_version | expected_version | - | https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.1 | diff --git a/end-to-end-tests/features/history_mode.feature b/end-to-end-tests/features/history_mode.feature new file mode 100644 index 0000000..765436c --- /dev/null +++ b/end-to-end-tests/features/history_mode.feature @@ -0,0 +1,40 @@ +Feature: Specifies how commits are parsed, acceptable values are 'first' to parse only the first parent of merge commits, or 'all' to parse all parents. commit's are parsed for their Git commit messages. + + + Scenario Outline: All the parents of merge commit's are parsed for their Git commit messages. + Given the repository "" is cloned and checked out at the commit "". + When the argument --from-commit-hash is provided as "". + And the argument --from-version is provided as "". + Then the returned version should be "". + When the argument --history-mode is provided as "all". + Then the returned version should be "". + + + Examples: + | repository | checkout_commit | from_commit_hash | from_version | default_expected_version | all_parents_expected_version | + | https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.1 | 1.3.30 | + + + Scenario Outline: Only the first parent of merge commit's are parsed for their Git commit messages. + Given the repository "" is cloned and checked out at the commit "". + When the argument --from-commit-hash is provided as "". + And the argument --from-version is provided as "". + And the argument --history-mode is provided as "first". + Then the returned version should be "". + + + Examples: + | repository | checkout_commit | from_commit_hash | from_version | expected_version | + | https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.1 | + + + Scenario Outline: Only the first parent of merge commit's are parsed for their Git commit messages, by default. + Given the repository "" is cloned and checked out at the commit "". + When the argument --from-commit-hash is provided as "". + And the argument --from-version is provided as "". + Then the returned version should be "". + + + Examples: + | repository | checkout_commit | from_commit_hash | from_version | expected_version | + | https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.1 | diff --git a/end-to-end-tests/features/steps/when.py b/end-to-end-tests/features/steps/when.py index 2067049..7b3cc41 100644 --- a/end-to-end-tests/features/steps/when.py +++ b/end-to-end-tests/features/steps/when.py @@ -27,9 +27,9 @@ def set_monorepo(context, monorepo): context.arguments += f" --monorepo {monorepo} " -@when('the argument --git-history-mode is provided as "{git_history_mode}".') -def set_batch_commits_flag(context, git_history_mode): - context.arguments += f" --git-history-mode {git_history_mode} " +@when('the argument --history-mode is provided as "{history_mode}".') +def set_batch_commits_flag(context, history_mode): + context.arguments += f" --history-mode {history_mode} " @when('the argument --from-version is provided as "{from_version}".') diff --git a/src/cli/mod.rs b/src/cli/mod.rs index bd2e24f..7ce20d0 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -2,7 +2,7 @@ use clap::{ArgGroup, Parser}; use semver::{Error, Version}; pub use crate::calculation_mode::CalculationMode; -pub use crate::git_history_mode::GitHistoryMode; +pub use crate::history_mode::HistoryMode; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] @@ -40,10 +40,10 @@ pub(crate) struct Arguments { #[arg( long, - default_value = "FirstParent", - help = "The mode to use when transversing the Git commit history of the Git commit range, to collect the Git commit messages to use in calculating the next semantic version." + default_value = "first", + help = "Specifies how commits are parsed, acceptable values are 'first' to parse only the first parent of merge commits, or 'all' to parse all parents." )] - pub(crate) git_history_mode: GitHistoryMode, + pub(crate) history_mode: HistoryMode, #[arg( long, diff --git a/src/commits/mod.rs b/src/commits/mod.rs index 4be936b..15294ef 100644 --- a/src/commits/mod.rs +++ b/src/commits/mod.rs @@ -7,7 +7,7 @@ use semver::{BuildMetadata, Prerelease, Version}; use crate::calculation_mode::CalculationMode; use crate::commits::commit::Commit; use crate::commits::filters::Filters; -use crate::git_history_mode::GitHistoryMode; +use crate::history_mode::HistoryMode; mod commit; mod filters; @@ -27,20 +27,20 @@ impl Commits { repository: &Repository, reference: T, commit_filters: Vec, - git_history_mode: GitHistoryMode, + history_mode: HistoryMode, ) -> Result { let reference_oid = get_reference_oid(repository, reference.as_ref())?; - get_commits_till_head_from_oid(repository, reference_oid, commit_filters, git_history_mode) + get_commits_till_head_from_oid(repository, reference_oid, commit_filters, history_mode) } pub fn from_commit_hash>( repository: &Repository, commit_hash: T, commit_filters: Vec, - git_history_mode: GitHistoryMode, + history_mode: HistoryMode, ) -> Result { let commit_oid = parse_to_oid(repository, commit_hash.as_ref())?; - get_commits_till_head_from_oid(repository, commit_oid, commit_filters, git_history_mode) + get_commits_till_head_from_oid(repository, commit_oid, commit_filters, history_mode) } pub fn get_next_version( @@ -138,15 +138,15 @@ fn get_commits_till_head_from_oid( repository: &Repository, from_commit_hash: Oid, commit_filters: Vec, - git_history_mode: GitHistoryMode, + history_mode: HistoryMode, ) -> Result { fn get_revwalker( repository: &Repository, from_commit_hash: Oid, - git_history_mode: GitHistoryMode, + history_mode: HistoryMode, ) -> Result { let mut commits = repository.revwalk()?; - if git_history_mode == GitHistoryMode::FirstParent { + if history_mode == HistoryMode::First { commits.simplify_first_parent()?; } commits.push_head()?; @@ -158,7 +158,7 @@ fn get_commits_till_head_from_oid( Ok(commits) } - let revwalker = get_revwalker(repository, from_commit_hash, git_history_mode)?; + let revwalker = get_revwalker(repository, from_commit_hash, history_mode)?; let mut commits = VecDeque::new(); let filters = Filters::from(commit_filters); diff --git a/src/git_history_mode/mod.rs b/src/git_history_mode/mod.rs deleted file mode 100644 index 3157279..0000000 --- a/src/git_history_mode/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -use strum_macros::{Display, EnumString}; - -/// The mode to use when transversing the Git commit history of the Git commit range, to collect -/// the Git commit messages to use in calculating the next semantic version. -#[derive(Debug, PartialEq, Eq, Clone, Copy, Display, EnumString)] -pub enum GitHistoryMode { - /// In FirstParent mode only the first parent of merge commit's are parsed for their Git commit - /// messages. - FirstParent, - /// In AllParents mode all the parents of merge commit's are parsed for their Git commit - /// messages. - AllParents, -} diff --git a/src/history_mode.rs b/src/history_mode.rs new file mode 100644 index 0000000..dc9986a --- /dev/null +++ b/src/history_mode.rs @@ -0,0 +1,12 @@ +use strum_macros::{Display, EnumString}; + +/// The mode to use when transversing the Git commit history of the Git commit range, to collect +/// the Git commit messages to use in calculating the next semantic version. +#[derive(Debug, PartialEq, Eq, Clone, Copy, Display, EnumString)] +#[strum(ascii_case_insensitive)] +pub enum HistoryMode { + /// only the first parent of merge commit's are parsed + First, + /// all the parents of merge commit's are parsed + All, +} diff --git a/src/main.rs b/src/main.rs index de3a0e2..ce8b75a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use crate::commits::Commits; mod calculation_mode; mod cli; mod commits; -mod git_history_mode; +mod history_mode; const ERROR_EXIT_CODE: i32 = 1; @@ -50,7 +50,7 @@ fn run(arguments: Arguments) -> Result<()> { &repository, from_commit_hash, arguments.monorepo, - arguments.git_history_mode, + arguments.history_mode, ) } (false, None, Some(from_reference)) => { @@ -59,7 +59,7 @@ fn run(arguments: Arguments) -> Result<()> { &repository, from_reference, arguments.monorepo, - arguments.git_history_mode, + arguments.history_mode, ) } (_, _, _) => {