Skip to content

Commit b52927e

Browse files
committed
feat!: adding git history mode
1 parent a0af26c commit b52927e

File tree

13 files changed

+115
-35
lines changed

13 files changed

+115
-35
lines changed

Cargo.lock

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

conventional_commits_linter/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_linter"
3-
version = "0.10.0"
3+
version = "0.11.0"
44
description = "A tooling and language agnostic utility to lint Git commits against the Conventional Commits specification."
55
authors = ["C <DeveloperC@protonmail.com>"]
66
edition = "2021"
@@ -26,7 +26,7 @@ git2 = { version = "0.13.25", default-features = false, features=[] }
2626
strum = "0.23.0"
2727
strum_macros = "0.23.1"
2828

29-
conventional_commits_linter_lib = "0.2.0"
29+
conventional_commits_linter_lib = "0.3.0"
3030

3131

3232
[dev-dependencies]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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-commit-hash is provided as "<from_commit_hash>".
7+
And the argument --output is set as "JSON".
8+
Then their are "<default_number_of_commits>" commits failing linting.
9+
When the argument --git-history-mode is provided as "AllParents".
10+
Then their are "<all_parent_number_of_commits>" commits failing linting.
11+
12+
13+
Examples:
14+
| repository | checkout_commit | from_commit_hash | default_number_of_commits | all_parent_number_of_commits |
15+
| https://github.com/lambci/awslambda.nim | 0fa0f62bec56eb7e09d8fd3e2a4c31798baba89f | 9c9583952ce709fbc6af3b85200c78bf417e5a11 | 5 | 6 |
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-commit-hash is provided as "<from_commit_hash>".
7+
And the argument --output is set as "JSON".
8+
Then their are "<number_of_commits>" commits failing linting.
9+
10+
11+
Examples:
12+
| repository | checkout_commit | from_commit_hash | number_of_commits |
13+
| https://github.com/dcyou/resume | bbf42bd631b3ee85de650f46891619833c920bef | 0a74203f382e06b6f39f5143da1eee0be77d3acb | 4 |

conventional_commits_linter/end-to-end-tests/features/steps/then-violations.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
from then import then_linting_fails
66

77

8+
@then('their are "{number_of_commits}" commits failing linting.')
9+
def then_number_of_commits_failing_linting(context, number_of_commits):
10+
# When/Then
11+
then_linting_fails(context)
12+
13+
# Then
14+
assert is_json(context.stdout)
15+
output = json.loads(context.stdout)
16+
assert len(output) == int(number_of_commits)
17+
18+
819
@then('a preceding whitespace before the type violation is detected.')
920
def then_preceding_whitespace_before_type_violation(context):
1021
# When/Then

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def then_missing_from_argument_error(context):
5555
" <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
5656
"\n" + \
5757
"USAGE:\n" + \
58-
" conventional_commits_linter --output <output> <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
58+
" conventional_commits_linter --git-history-mode <git-history-mode> --output <output> <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
5959
"\n" + \
6060
"For more information try --help\n"
6161

@@ -71,7 +71,7 @@ def then_conflicting_from_arguments_error(context):
7171
# Given
7272
conflicting_arguments_end = "\n" + \
7373
"USAGE:\n" + \
74-
" conventional_commits_linter --output <output> <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
74+
" conventional_commits_linter --git-history-mode <git-history-mode> --output <output> <--from-stdin|--from-reference <from-reference>|--from-commit-hash <from-commit-hash>>\n" + \
7575
"\n" + \
7676
"For more information try --help\n"
7777

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
from behave import *
22

33

4-
@when('the argument --from-commit-hash is provided as "{from_commit_hash}".')
5-
def set_from_commit_hash(context, from_commit_hash):
6-
context.arguments += " --from-commit-hash " + from_commit_hash + " "
4+
@when(
5+
'the flag --from-stdin is set and the standard input is "{standard_input}".')
6+
def set_from_stdin(context, standard_input):
7+
context.standard_input = standard_input.strip()
8+
context.pre_command = "echo " + context.standard_input + " | "
9+
context.arguments += " --from-stdin "
710

811

912
@when('the argument --from-reference is provided as "{from_reference}".')
1013
def set_from_reference(context, from_reference):
1114
context.arguments += " --from-reference " + from_reference + " "
1215

1316

14-
@when(
15-
'the flag --from-stdin is set and the standard input is "{standard_input}".')
16-
def set_from_stdin(context, standard_input):
17-
context.standard_input = standard_input.strip()
18-
context.pre_command = "echo " + context.standard_input + " | "
19-
context.arguments += " --from-stdin "
17+
@when('the argument --from-commit-hash is provided as "{from_commit_hash}".')
18+
def set_from_commit_hash(context, from_commit_hash):
19+
context.arguments += " --from-commit-hash " + from_commit_hash + " "
20+
21+
22+
@when('the argument --git-history-mode is provided as "AllParents".')
23+
def set_batch_commits_flag(context):
24+
context.arguments += " --git-history-mode \"AllParents\" "
2025

2126

2227
@when('the flag --allow-angular-type-only is set.')

conventional_commits_linter/src/cli/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ pub(crate) struct Arguments {
2828
)]
2929
pub(crate) from_commit_hash: Option<String>,
3030

31+
#[structopt(
32+
long,
33+
default_value = "FirstParent",
34+
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."
35+
)]
36+
pub(crate) git_history_mode: conventional_commits_linter_lib::GitHistoryMode,
37+
3138
#[structopt(
3239
long,
3340
help = "Allow the Conventional Commits type to only be (`build`, `ci`, `docs`, `feat`, `fix`, `perf`, `refactor`, `style`, `test`, `revert`), otherwise linting for the commit will fail."

conventional_commits_linter/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ fn run(arguments: Arguments) -> Result<(), git2::Error> {
4141
Ok(Commits::from_commit_message(commit_message))
4242
}
4343
(false, Some(from_commit_hash), None) => {
44-
Commits::from_commit_hash(&repository, &from_commit_hash)
44+
Commits::from_commit_hash(&repository, &from_commit_hash, arguments.git_history_mode)
4545
}
4646
(false, None, Some(from_reference)) => {
47-
Commits::from_reference(&repository, &from_reference)
47+
Commits::from_reference(&repository, &from_reference, arguments.git_history_mode)
4848
}
4949
(_, _, _) => {
5050
unreachable!(

conventional_commits_linter_lib/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "conventional_commits_linter_lib"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
description = "A tooling and language agnostic library to lint Git commits against the Conventional Commits specification."
55
authors = ["C <DeveloperC@protonmail.com>"]
66
edition = "2021"
@@ -29,6 +29,10 @@ serde_json = "1.0.79"
2929
# For fancy output.
3030
ansi_term = "0.12.1"
3131

32+
# For enum from _str etc for CLI usage.
33+
strum = "0.23.0"
34+
strum_macros = "0.23.1"
35+
3236

3337
[dev-dependencies]
3438
# For parameterized testing.

0 commit comments

Comments
 (0)