Skip to content

Commit

Permalink
refactor!: simplifying --git-history-mode naming/description (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperC286 authored Oct 21, 2024
1 parent 12413ab commit 6a9a603
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 73 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}`.
Expand Down
15 changes: 0 additions & 15 deletions end-to-end-tests/features/git_history_all_parents_mode.feature

This file was deleted.

13 changes: 0 additions & 13 deletions end-to-end-tests/features/git_history_first_parent_mode.feature

This file was deleted.

40 changes: 40 additions & 0 deletions end-to-end-tests/features/history_mode.feature
Original file line number Diff line number Diff line change
@@ -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 "<repository>" is cloned and checked out at the commit "<checkout_commit>".
When the argument --from-commit-hash is provided as "<from_commit_hash>".
And the argument --from-version is provided as "<from_version>".
Then the returned version should be "<default_expected_version>".
When the argument --history-mode is provided as "all".
Then the returned version should be "<all_parents_expected_version>".


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 "<repository>" is cloned and checked out at the commit "<checkout_commit>".
When the argument --from-commit-hash is provided as "<from_commit_hash>".
And the argument --from-version is provided as "<from_version>".
And the argument --history-mode is provided as "first".
Then the returned version should be "<expected_version>".


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 "<repository>" is cloned and checked out at the commit "<checkout_commit>".
When the argument --from-commit-hash is provided as "<from_commit_hash>".
And the argument --from-version is provided as "<from_version>".
Then the returned version should be "<expected_version>".


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 |
6 changes: 3 additions & 3 deletions end-to-end-tests/features/steps/when.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}".')
Expand Down
8 changes: 4 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions src/commits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,20 +27,20 @@ impl Commits {
repository: &Repository,
reference: T,
commit_filters: Vec<String>,
git_history_mode: GitHistoryMode,
history_mode: HistoryMode,
) -> Result<Commits> {
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<T: AsRef<str>>(
repository: &Repository,
commit_hash: T,
commit_filters: Vec<String>,
git_history_mode: GitHistoryMode,
history_mode: HistoryMode,
) -> Result<Commits> {
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(
Expand Down Expand Up @@ -138,15 +138,15 @@ fn get_commits_till_head_from_oid(
repository: &Repository,
from_commit_hash: Oid,
commit_filters: Vec<String>,
git_history_mode: GitHistoryMode,
history_mode: HistoryMode,
) -> Result<Commits> {
fn get_revwalker(
repository: &Repository,
from_commit_hash: Oid,
git_history_mode: GitHistoryMode,
history_mode: HistoryMode,
) -> Result<Revwalk> {
let mut commits = repository.revwalk()?;
if git_history_mode == GitHistoryMode::FirstParent {
if history_mode == HistoryMode::First {
commits.simplify_first_parent()?;
}
commits.push_head()?;
Expand All @@ -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);

Expand Down
13 changes: 0 additions & 13 deletions src/git_history_mode/mod.rs

This file was deleted.

12 changes: 12 additions & 0 deletions src/history_mode.rs
Original file line number Diff line number Diff line change
@@ -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,
}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)) => {
Expand All @@ -59,7 +59,7 @@ fn run(arguments: Arguments) -> Result<()> {
&repository,
from_reference,
arguments.monorepo,
arguments.git_history_mode,
arguments.history_mode,
)
}
(_, _, _) => {
Expand Down

0 comments on commit 6a9a603

Please sign in to comment.