Skip to content

Commit 751b994

Browse files
committed
feat!: adding Git parser mode
1 parent 458ed9a commit 751b994

File tree

16 files changed

+120
-54
lines changed

16 files changed

+120
-54
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conventional_commits_next_version/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "conventional_commits_next_version"
3-
version = "5.0.0"
3+
version = "6.0.0"
44
description = "A tooling and language agnostic utility to calculate the next semantic version based on the Conventional Commits since the prior version. Supports monorepos."
55
authors = ["C <[email protected]>"]
66
edition = "2021"
@@ -25,4 +25,4 @@ git2 = { version = "0.13.25", default-features = false, features=[] }
2525
# For Semantic Versioning parsing.
2626
semver = "1.0.5"
2727

28-
conventional_commits_next_version_lib = "0.2.0"
28+
conventional_commits_next_version_lib = "0.3.0"

conventional_commits_next_version/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ Additional command line flags can be passed to alter what and how the next Seman
129129

130130
| Flag | |
131131
|---------------------------|-|
132+
| --monorepo | The the next semantic version is calculated only from commits altering files which match any of these provided regexes, enabling usage within monorepos. |
133+
| --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. |
132134
| --calculation-mode | The mode of calculation to use on the range of Commits to calculate the next semantic version. |
133135
| --current-version | This Semantic Versioning is asserted to be equal or larger than the calculated Semantic Versioning. The calculated Semantic Versioning is not printed to standard out. If the assertion is not met then it exits with a non zero exit code. |
134-
| --monorepo | The the next semantic version is calculated only from commits altering files which match any of these provided regexes, enabling usage within monorepos. |
135136

136137

137138
### Usage - Git Environment Variables

conventional_commits_next_version/end-to-end-tests/features/consecutive-semantic-versioning.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ Feature: The increments are applied consecutively to calculate the next Semantic
1717
| https://github.com/yargs/yargs.git | b9409da199ebca515a848489c206b807fab2e65d | 6e4bc2aa0a6c5560928296f18e008a15b2aaf335 | 1.1.3 | 2.0.0 |
1818
| https://github.com/yargs/yargs.git | 0aaa68bf36d35c697426de4dfe2e4e12128c2dc0 | 927810c7615912fb77a160273b2d6a946e9737b8 | 9.4.0 | 10.0.0 |
1919
| https://github.com/yargs/yargs.git | 6014e39bca3a1e8445aa0fb2a435f6181e344c45 | 705384762919641fe9d4c0967452a292f5f52c6d | 1.2.0 | 1.4.0 |
20-
| https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.30 |
2120
| https://gitlab.com/dmfay/massive-js.git | 482c364acf5505b81c55245fac0472890d351662 | 3f20134864b19b11541287af440540c7ad0ed986 | 7.2.0 | 7.5.3 |

conventional_commits_next_version/end-to-end-tests/features/from-shortened-commit-hash.feature

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Feature: A shortened Git commit hash can be provided as an argument to indicate
3737
| repository | checkout_commit | from_commit_hash | from_version | expected_version | shortened_from_commit_hash |
3838
| https://github.com/yargs/yargs.git | 089417550ef5a5b8ce3578dd2a989191300b64cd | 262e796329f4a09083ca07e49f926ae43ac850e9 | 0.2.1 | 0.2.2 | 262e796 |
3939
| https://github.com/yargs/yargs.git | 6014e39bca3a1e8445aa0fb2a435f6181e344c45 | 705384762919641fe9d4c0967452a292f5f52c6d | 1.2.0 | 1.4.0 | 7053847 |
40-
| https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.30 | fe14480 |
4140
| https://gitlab.com/dmfay/massive-js.git | 482c364acf5505b81c55245fac0472890d351662 | 3f20134864b19b11541287af440540c7ad0ed986 | 7.2.0 | 7.5.3 | 3f20134 |
4241

4342

@@ -51,7 +50,6 @@ Feature: A shortened Git commit hash can be provided as an argument to indicate
5150
Examples:
5251
| repository | checkout_commit | from_shortened_commit_hash | from_version |
5352
| https://github.com/yargs/yargs.git | 089417550ef5a5b8ce3578dd2a989191300b64cd | 272a194 | 0.2.1 |
54-
| https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fd13487 | 1.2.2 |
5553
| https://gitlab.com/dmfay/massive-js.git | 482c364acf5505b81c55245fac0472890d351662 | 3f235ee | 7.2.0 |
5654

5755

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: All the parents of merge commit's are parsed for their Git commit messages.
2+
3+
4+
Scenario Outline:
5+
Given the repository "<repository>" is cloned and checked out at the commit "<checkout_commit>".
6+
When the argument --from-version is provided as "<from_version>".
7+
And the argument --from-commit-hash is provided as "<from_commit_hash>".
8+
And the argument --git-history-mode is provided as "AllParents".
9+
Then the returned version should be "<expected_version>".
10+
11+
12+
Examples:
13+
| repository | checkout_commit | from_commit_hash | from_version | expected_version |
14+
| https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.30 |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: Only the first parent of merge commit's are parsed for their Git commit messages.
2+
3+
4+
Scenario Outline:
5+
Given the repository "<repository>" is cloned and checked out at the commit "<checkout_commit>".
6+
When the argument --from-version is provided as "<from_version>".
7+
And the argument --from-commit-hash is provided as "<from_commit_hash>".
8+
Then the returned version should be "<expected_version>".
9+
10+
11+
Examples:
12+
| repository | checkout_commit | from_commit_hash | from_version | expected_version |
13+
| https://github.com/dcyou/resume.git | 9015044aba82dbe8aa0119bffd7ea73cad171dd0 | fe14480df04f76e6434d45c762ab087df41b8473 | 1.2.2 | 1.3.1 |

conventional_commits_next_version/end-to-end-tests/features/steps/then.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ def then_ambiguous_shortened_commit_hash_error(context, shortened_commit_hash):
101101
def then_missing_from_argument_error(context):
102102
# Given
103103
missing_from_argument_error = "error: The following required arguments were not provided:\n" + \
104-
" <--from-stdin|--from-commit-hash <from-commit-hash>|--from-reference <from-reference>>\n" + \
104+
" <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
105105
"\n" + \
106106
"USAGE:\n" + \
107-
" conventional_commits_next_version --calculation-mode <calculation-mode> --from-version <from-version> <--from-stdin|--from-commit-hash <from-commit-hash>|--from-reference <from-reference>>\n" + \
107+
" conventional_commits_next_version --calculation-mode <calculation-mode> --from-version <from-version> --git-history-mode <git-history-mode> <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
108108
"\n" + \
109109
"For more information try --help\n"
110110

@@ -120,7 +120,7 @@ def then_conflicting_from_arguments_error(context):
120120
# Given
121121
conflicting_arguments_end = "\n" + \
122122
"USAGE:\n" + \
123-
" conventional_commits_next_version --calculation-mode <calculation-mode> --from-version <from-version> <--from-stdin|--from-commit-hash <from-commit-hash>|--from-reference <from-reference>>\n" + \
123+
" conventional_commits_next_version --calculation-mode <calculation-mode> --from-version <from-version> --git-history-mode <git-history-mode> <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
124124
"\n" + \
125125
"For more information try --help\n"
126126

conventional_commits_next_version/end-to-end-tests/features/steps/when.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@ def set_from_stdin(context, standard_input):
99
context.arguments += " --from-stdin "
1010

1111

12+
@when('the argument --from-reference is provided as "{from_reference}".')
13+
def set_from_reference(context, from_reference):
14+
context.arguments += " --from-reference " + from_reference + " "
15+
16+
1217
@when('the argument --from-commit-hash is provided as "{from_commit_hash}".')
1318
def set_from_commit_hash(context, from_commit_hash):
1419
context.arguments += " --from-commit-hash " + from_commit_hash + " "
1520

1621

22+
@when('the argument --monorepo is provided as "{monorepo}".')
23+
def set_monorepo(context, monorepo):
24+
context.arguments += " --monorepo " + monorepo + " "
25+
26+
27+
@when('the argument --git-history-mode is provided as "AllParents".')
28+
def set_batch_commits_flag(context):
29+
context.arguments += " --git-history-mode \"AllParents\" "
30+
31+
1732
@when('the argument --from-version is provided as "{from_version}".')
1833
def set_from_version(context, from_version):
1934
context.arguments += " --from-version " + from_version + " "
@@ -24,16 +39,6 @@ def set_batch_commits_flag(context):
2439
context.arguments += " --calculation-mode \"Batch\" "
2540

2641

27-
@when('the argument --monorepo is provided as "{monorepo}".')
28-
def set_monorepo(context, monorepo):
29-
context.arguments += " --monorepo " + monorepo + " "
30-
31-
3242
@when('the argument --current-version is provided as "{current_version}".')
3343
def set_current_version(context, current_version):
3444
context.arguments += " --current-version " + current_version + " "
35-
36-
37-
@when('the argument --from-reference is provided as "{from_reference}".')
38-
def set_from_reference(context, from_reference):
39-
context.arguments += " --from-reference " + from_reference + " "

conventional_commits_next_version/src/cli/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ pub(crate) struct Arguments {
1515
)]
1616
pub(crate) from_stdin: bool,
1717

18+
#[structopt(
19+
long,
20+
group = "from",
21+
help = "The Git reference from where to start taking the range of commits from till HEAD. The range is inclusive of HEAD and exclusive of the provided reference."
22+
)]
23+
pub(crate) from_reference: Option<String>,
24+
1825
#[structopt(
1926
long,
2027
group = "from",
@@ -24,10 +31,16 @@ pub(crate) struct Arguments {
2431

2532
#[structopt(
2633
long,
27-
group = "from",
28-
help = "The Git reference from where to start taking the range of commits from till HEAD. The range is inclusive of HEAD and exclusive of the provided reference."
34+
help = "The the next semantic version is calculated only from commits altering files which match any of these provided regexes, enabling usage within monorepos."
2935
)]
30-
pub(crate) from_reference: Option<String>,
36+
pub(crate) monorepo: Vec<String>,
37+
38+
#[structopt(
39+
long,
40+
default_value = "FirstParent",
41+
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."
42+
)]
43+
pub(crate) git_history_mode: conventional_commits_next_version_lib::GitHistoryMode,
3144

3245
#[structopt(
3346
long,
@@ -49,12 +62,6 @@ pub(crate) struct Arguments {
4962
help = "This Semantic Versioning is asserted to be equal or larger than the calculated Semantic Versioning. The calculated Semantic Versioning is not printed to standard out. If the assertion is not met then it exits with a non zero exit code."
5063
)]
5164
pub(crate) current_version: Option<Version>,
52-
53-
#[structopt(
54-
long,
55-
help = "The the next semantic version is calculated only from commits altering files which match any of these provided regexes, enabling usage within monorepos."
56-
)]
57-
pub(crate) monorepo: Vec<String>,
5865
}
5966

6067
fn parse_version(src: &str) -> Result<Version, Error> {

0 commit comments

Comments
 (0)