From 382e8516380c8613f7482440da487de0b13e04aa Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Sun, 17 Sep 2023 22:51:27 +0200 Subject: [PATCH 1/9] Writes commit message after verification failed --- src/Task/Git/CommitMessage.php | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Task/Git/CommitMessage.php b/src/Task/Git/CommitMessage.php index 2d263d5a..309f7133 100644 --- a/src/Task/Git/CommitMessage.php +++ b/src/Task/Git/CommitMessage.php @@ -20,7 +20,7 @@ class CommitMessage implements TaskInterface { - const MERGE_COMMIT_REGEX = + public const MERGE_COMMIT_REGEX = '(Merge branch|tag \'.+\'(?:\s.+)?|Merge remote-tracking branch \'.+\'|Merge pull request #\d+\s.+)'; /** @@ -93,6 +93,18 @@ public function canRunInContext(ContextInterface $context): bool return $context instanceof GitCommitMsgContext; } + private static function withCommitMessage(string $errorMessage, string $commitMessage): string + { + return sprintf( + "%s%sOriginal commit message: %s%s", + $errorMessage, + PHP_EOL, + PHP_EOL, + $commitMessage + ); + } + + public function run(ContextInterface $context): TaskResultInterface { assert($context instanceof GitCommitMsgContext); @@ -110,7 +122,7 @@ public function run(ContextInterface $context): TaskResultInterface return TaskResult::createFailed( $this, $context, - 'Commit message should not be empty.' + self::withCommitMessage('Commit message should not be empty.', $commitMessage), ); } @@ -118,7 +130,7 @@ public function run(ContextInterface $context): TaskResultInterface return TaskResult::createFailed( $this, $context, - 'Subject should start with a capital letter.' + self::withCommitMessage('Subject should start with a capital letter.', $commitMessage) ); } @@ -126,7 +138,7 @@ public function run(ContextInterface $context): TaskResultInterface return TaskResult::createFailed( $this, $context, - 'Subject should be one line and followed by a blank line.' + self::withCommitMessage('Subject should be one line and followed by a blank line.', $commitMessage) ); } @@ -134,7 +146,7 @@ public function run(ContextInterface $context): TaskResultInterface return TaskResult::createFailed( $this, $context, - 'Please omit all punctuations from commit message subject.' + self::withCommitMessage('Please omit all punctuations from commit message subject.', $commitMessage) ); } @@ -142,7 +154,7 @@ public function run(ContextInterface $context): TaskResultInterface return TaskResult::createFailed( $this, $context, - 'Please omit trailing period from commit message subject.' + self::withCommitMessage('Please omit trailing period from commit message subject.', $commitMessage) ); } @@ -166,11 +178,7 @@ public function run(ContextInterface $context): TaskResultInterface return TaskResult::createFailed( $this, $context, - implode(PHP_EOL, $exceptions).PHP_EOL.sprintf( - 'Original commit message: %s%s', - PHP_EOL, - $commitMessage - ) + self::withCommitMessage(implode(PHP_EOL, $exceptions), $commitMessage) ); } @@ -211,7 +219,11 @@ private function enforceTextWidth(GitCommitMsgContext $context): TaskResult } if (\count($errors)) { - return TaskResult::createFailed($this, $context, implode(PHP_EOL, $errors)); + return TaskResult::createFailed( + $this, + $context, + self::withCommitMessage(implode(PHP_EOL, $errors), $commitMessage) + ); } return TaskResult::createPassed($this, $context); From 9b68c69941a0fdafa1c388955bf3187d5a9353d3 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 11:16:48 +0200 Subject: [PATCH 2/9] Fixes spaces issues --- src/Task/Git/CommitMessage.php | 2 +- test/Unit/Task/Git/CommitMessageTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Task/Git/CommitMessage.php b/src/Task/Git/CommitMessage.php index 309f7133..3b9047ec 100644 --- a/src/Task/Git/CommitMessage.php +++ b/src/Task/Git/CommitMessage.php @@ -96,7 +96,7 @@ public function canRunInContext(ContextInterface $context): bool private static function withCommitMessage(string $errorMessage, string $commitMessage): string { return sprintf( - "%s%sOriginal commit message: %s%s", + "%s%sOriginal commit message:%s%s", $errorMessage, PHP_EOL, PHP_EOL, diff --git a/test/Unit/Task/Git/CommitMessageTest.php b/test/Unit/Task/Git/CommitMessageTest.php index ef50077b..e4b62fd1 100644 --- a/test/Unit/Task/Git/CommitMessageTest.php +++ b/test/Unit/Task/Git/CommitMessageTest.php @@ -309,7 +309,7 @@ function () { 'Rule not matched: "4" /(.*)st$/', 'Rule not matched: "5" /t(e|a)st/', 'Rule not matched: "6" TEST', - 'Original commit message: ', + 'Original commit message:', 'invalid' ) ]; @@ -327,7 +327,7 @@ function () { $this->buildMultiLineString( 'Rule not matched: "full" test', 'Rule not matched: "partial" *es*', - 'Original commit message: ', + 'Original commit message:', 'invalid' ) ]; @@ -342,7 +342,7 @@ function () { }, $this->buildMultiLineString( 'Rule not matched: "0" /TEST/', - 'Original commit message: ', + 'Original commit message:', 'test' ) ]; From 34853a4fa7e99b0057ce980f31fd694905fb4668 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 11:17:04 +0200 Subject: [PATCH 3/9] Adds tests to the feature 1108 This feature is "prints commit message after its validation failed" --- test/Unit/Task/Git/CommitMessageTest.php | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/Unit/Task/Git/CommitMessageTest.php b/test/Unit/Task/Git/CommitMessageTest.php index e4b62fd1..ea15f745 100644 --- a/test/Unit/Task/Git/CommitMessageTest.php +++ b/test/Unit/Task/Git/CommitMessageTest.php @@ -110,6 +110,19 @@ function () { }, 'Subject should start with a capital letter.' ]; + yield 'enforce_capitalized_subject_gives_back_message' => [ + [ + 'enforce_capitalized_subject' => true, + ], + $this->mockCommitMsgContext($this->buildMessage('no capital subject')), + function () { + }, + $this->buildMultiLineString( + 'Subject should start with a capital letter.', + 'Original commit message:', + 'no capital subject' + ) + ]; yield 'enforce_capitalized_subject_punctuation' => [ [ 'enforce_capitalized_subject' => true, @@ -206,6 +219,32 @@ function () { 'Line 5 of commit message has > 10 characters.' ) ]; + yield 'enforce_text_with_regular_gives_back_message' => [ + [ + 'enforce_single_lined_subject' => false, + 'max_subject_width' => 10, + 'max_body_width' => 10, + ], + $this->mockCommitMsgContext($this->buildMessage( + 'Subject 1234567891011', + 'Body 1234567891011', + 'Body ok', + 'Body 1110987654321' + )), + function () { + }, + $this->buildMultiLineString( + 'Please keep the subject <= 10 characters.', + 'Line 3 of commit message has > 10 characters.', + 'Line 5 of commit message has > 10 characters.', + 'Original commit message:', + 'Subject 1234567891011', + '', + 'Body 1234567891011', + 'Body ok', + 'Body 1110987654321' + ) + ]; yield 'enforce_text_with_long_comments' => [ [ 'enforce_single_lined_subject' => false, From f4859cb57fcb905b581b014321aeb9126d9e14ff Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 11:52:18 +0200 Subject: [PATCH 4/9] Removes duplicate test --- test/Unit/Task/Git/CommitMessageTest.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/Unit/Task/Git/CommitMessageTest.php b/test/Unit/Task/Git/CommitMessageTest.php index ea15f745..92554cf3 100644 --- a/test/Unit/Task/Git/CommitMessageTest.php +++ b/test/Unit/Task/Git/CommitMessageTest.php @@ -110,19 +110,6 @@ function () { }, 'Subject should start with a capital letter.' ]; - yield 'enforce_capitalized_subject_gives_back_message' => [ - [ - 'enforce_capitalized_subject' => true, - ], - $this->mockCommitMsgContext($this->buildMessage('no capital subject')), - function () { - }, - $this->buildMultiLineString( - 'Subject should start with a capital letter.', - 'Original commit message:', - 'no capital subject' - ) - ]; yield 'enforce_capitalized_subject_punctuation' => [ [ 'enforce_capitalized_subject' => true, From 0664a92fc19bd9451d76fc886935b25c44a72a59 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 15:10:40 +0200 Subject: [PATCH 5/9] Added commit below all tests --- src/Test/Task/AbstractTaskTestCase.php | 5 +- test/Unit/Task/Git/CommitMessageTest.php | 138 ++++++++++++----------- 2 files changed, 74 insertions(+), 69 deletions(-) diff --git a/src/Test/Task/AbstractTaskTestCase.php b/src/Test/Task/AbstractTaskTestCase.php index 75d682f3..a3857c2d 100644 --- a/src/Test/Task/AbstractTaskTestCase.php +++ b/src/Test/Task/AbstractTaskTestCase.php @@ -58,6 +58,8 @@ public function it_contains_configurable_options(array $input, ?array $output): ); } + + /** * @test * @dataProvider provideRunContexts @@ -140,8 +142,7 @@ public function it_skips_on_stuff( array $config, ContextInterface $context, callable $configurator - ): void - { + ): void { $task = $this->configureTask($config); \Closure::bind($configurator, $this)($task->getConfig()->getOptions()); diff --git a/test/Unit/Task/Git/CommitMessageTest.php b/test/Unit/Task/Git/CommitMessageTest.php index 92554cf3..18e9d04c 100644 --- a/test/Unit/Task/Git/CommitMessageTest.php +++ b/test/Unit/Task/Git/CommitMessageTest.php @@ -36,6 +36,22 @@ protected function provideTask(): TaskInterface ); } + private function buildFailureMessage(array|string $lines, GitCommitMsgContext $commitMsg) + { + $message = ''; + // switch on type of $lines + if (is_array($lines)) { + foreach ($lines as $line) { + $message .= $line . PHP_EOL; + } + } else { + $message .= $lines . PHP_EOL; + } + + $message .= 'Original commit message:'. PHP_EOL. $commitMsg->getCommitMessage(); + return $message; + } + public function provideConfigurableOptions(): iterable { yield 'defaults' => [ @@ -105,86 +121,86 @@ function () { [ 'enforce_capitalized_subject' => true, ], - $this->mockCommitMsgContext($this->buildMessage('no capital subject')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('no capital subject')), function () { }, - 'Subject should start with a capital letter.' + $this->buildFailureMessage('Subject should start with a capital letter.', $commitMsg) ]; yield 'enforce_capitalized_subject_punctuation' => [ [ 'enforce_capitalized_subject' => true, ], - $this->mockCommitMsgContext($this->buildMessage('"no" capital subject')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('"no" capital subject')), function () { }, - 'Subject should start with a capital letter.' + $this->buildFailureMessage('Subject should start with a capital letter.', $commitMsg) ]; yield 'enforce_capitalized_subject_utf8' => [ [ 'enforce_capitalized_subject' => true, ], - $this->mockCommitMsgContext($this->buildMessage('"ärsgäng" capital subject')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('"ärsgäng" capital subject')), function () { }, - 'Subject should start with a capital letter.' + $this->buildFailureMessage('Subject should start with a capital letter.', $commitMsg) ]; yield 'enforce_no_subject_punctuations' => [ [ 'enforce_no_subject_punctuations' => true, ], - $this->mockCommitMsgContext($this->buildMessage('Some . punctiation')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('Some . punctiation')), function () { }, - 'Please omit all punctuations from commit message subject.' + $this->buildFailureMessage('Please omit all punctuations from commit message subject.', $commitMsg) ]; yield 'enforce_no_subject_punctuations_comma' => [ [ 'enforce_no_subject_punctuations' => true, ], - $this->mockCommitMsgContext($this->buildMessage('Some , punctiation')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('Some , punctiation')), function () { }, - 'Please omit all punctuations from commit message subject.' + $this->buildFailureMessage('Please omit all punctuations from commit message subject.', $commitMsg) ]; yield 'enforce_no_subject_punctuations_exclamation' => [ [ 'enforce_no_subject_punctuations' => true, ], - $this->mockCommitMsgContext($this->buildMessage('Some ! punctiation')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('Some ! punctiation')), function () { }, - 'Please omit all punctuations from commit message subject.' + $this->buildFailureMessage('Please omit all punctuations from commit message subject.', $commitMsg) ]; yield 'enforce_no_subject_punctuations_question' => [ [ 'enforce_no_subject_punctuations' => true, ], - $this->mockCommitMsgContext($this->buildMessage('Some ? punctiation')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('Some ? punctiation')), function () { }, - 'Please omit all punctuations from commit message subject.' + $this->buildFailureMessage('Please omit all punctuations from commit message subject.', $commitMsg) ]; yield 'enforce_no_subject_trailing_period' => [ [ 'enforce_no_subject_trailing_period' => true, ], - $this->mockCommitMsgContext($this->buildMessage('Subject ending with.')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('Subject ending with.')), function () { }, - 'Please omit trailing period from commit message subject.' + $this->buildFailureMessage('Please omit trailing period from commit message subject.', $commitMsg) ]; yield 'enforce_single_lined_subject-with_body' => [ [ 'enforce_single_lined_subject' => true, ], - $this->mockCommitMsgContext($this->buildMessage( + $commitMsg = $this->mockCommitMsgContext($this->buildMessage( $this->buildMultiLineString('Subject line', 'subject line 2'), 'comment line1', 'comment line2' )), function () { }, - 'Subject should be one line and followed by a blank line.' + $this->buildFailureMessage('Subject should be one line and followed by a blank line.', $commitMsg) ]; yield 'enforce_text_with_regular' => [ [ @@ -192,7 +208,7 @@ function () { 'max_subject_width' => 10, 'max_body_width' => 10, ], - $this->mockCommitMsgContext($this->buildMessage( + $commitMsg = $this->mockCommitMsgContext($this->buildMessage( 'Subject 1234567891011', 'Body 1234567891011', 'Body ok', @@ -200,11 +216,11 @@ function () { )), function () { }, - $this->buildMultiLineString( + $this->buildFailureMessage($this->buildMultiLineString( 'Please keep the subject <= 10 characters.', 'Line 3 of commit message has > 10 characters.', 'Line 5 of commit message has > 10 characters.' - ) + ), $commitMsg) ]; yield 'enforce_text_with_regular_gives_back_message' => [ [ @@ -212,7 +228,7 @@ function () { 'max_subject_width' => 10, 'max_body_width' => 10, ], - $this->mockCommitMsgContext($this->buildMessage( + $commitMsg = $this->mockCommitMsgContext($this->buildMessage( 'Subject 1234567891011', 'Body 1234567891011', 'Body ok', @@ -220,17 +236,11 @@ function () { )), function () { }, - $this->buildMultiLineString( + $this->buildFailureMessage($this->buildMultiLineString( 'Please keep the subject <= 10 characters.', 'Line 3 of commit message has > 10 characters.', 'Line 5 of commit message has > 10 characters.', - 'Original commit message:', - 'Subject 1234567891011', - '', - 'Body 1234567891011', - 'Body ok', - 'Body 1110987654321' - ) + ), $commitMsg) ]; yield 'enforce_text_with_long_comments' => [ [ @@ -238,7 +248,7 @@ function () { 'max_subject_width' => 10, 'max_body_width' => 10, ], - $this->mockCommitMsgContext($this->wrapComments( + $commitMsg = $this->mockCommitMsgContext($this->wrapComments( $this->buildMessage( 'Subject', 'Body 1234567891011', @@ -248,10 +258,10 @@ function () { )), function () { }, - $this->buildMultiLineString( + $this->buildFailureMessage($this->buildMultiLineString( 'Line 3 of commit message has > 10 characters.', 'Line 5 of commit message has > 10 characters.' - ) + ), $commitMsg) ]; yield 'enforce_text_with_ignore_below_comment' => [ [ @@ -259,7 +269,7 @@ function () { 'max_subject_width' => 10, 'max_body_width' => 10, ], - $this->mockCommitMsgContext($this->addIgnoreBelowComment( + $commitMsg = $this->mockCommitMsgContext($this->addIgnoreBelowComment( $this->buildMessage( 'Subject', 'Body 1234567891011', @@ -269,10 +279,10 @@ function () { )), function () { }, - $this->buildMultiLineString( + $this->buildFailureMessage($this->buildMultiLineString( 'Line 3 of commit message has > 10 characters.', 'Line 5 of commit message has > 10 characters.' - ) + ), $commitMsg) ]; yield 'type_scope_conventions_not_set_in_message' => [ [ @@ -283,10 +293,10 @@ function () { ] ], ], - $this->mockCommitMsgContext($this->buildMessage('doesnt match type scope convention')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('doesnt match type scope convention')), function () { }, - 'Rule not matched: "Invalid Type/Scope Format"' + $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) ]; yield 'type_scope_conventions_invalid_type' => [ [ @@ -297,10 +307,10 @@ function () { ] ], ], - $this->mockCommitMsgContext($this->buildMessage('bug: doesnt match type scope convention')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('bug: doesnt match type scope convention')), function () { }, - 'Rule not matched: "Invalid Type/Scope Format"' + $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) ]; yield 'type_scope_conventions_invalid_scope' => [ [ @@ -314,20 +324,20 @@ function () { ] ], ], - $this->mockCommitMsgContext($this->buildMessage('fix(api): doesnt match type scope convention')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('fix(api): doesnt match type scope convention')), function () { }, - 'Rule not matched: "Invalid Type/Scope Format"' + $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) ]; yield 'it_fails_on_matchers' => [ [ 'enforce_capitalized_subject' => false, 'matchers' => ['test', '*es*', 'te[s][t]', '/^te(.*)/', '/(.*)st$/', '/t(e|a)st/', 'TEST'], ], - $this->mockCommitMsgContext('invalid'), + $commitMsg = $this->mockCommitMsgContext('invalid'), function () { }, - $this->buildMultiLineString( + $this->buildFailureMessage($this->buildMultiLineString( 'Rule not matched: "0" test', 'Rule not matched: "1" *es*', 'Rule not matched: "2" te[s][t]', @@ -335,9 +345,7 @@ function () { 'Rule not matched: "4" /(.*)st$/', 'Rule not matched: "5" /t(e|a)st/', 'Rule not matched: "6" TEST', - 'Original commit message:', - 'invalid' - ) + ), $commitMsg) ]; yield 'it_fails_on_names_matchers' => [ [ @@ -347,15 +355,13 @@ function () { 'partial' => '*es*' ], ], - $this->mockCommitMsgContext('invalid'), + $commitMsg = $this->mockCommitMsgContext('invalid'), function () { }, - $this->buildMultiLineString( + $this->buildFailureMessage($this->buildMultiLineString( 'Rule not matched: "full" test', 'Rule not matched: "partial" *es*', - 'Original commit message:', - 'invalid' - ) + ), $commitMsg) ]; yield 'it_applies_matchers_with_case_sensitive' => [ [ @@ -363,14 +369,12 @@ function () { 'matchers' => ['/TEST/'], 'case_insensitive' => false, ], - $this->mockCommitMsgContext($this->buildMessage('test')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('test')), function () { }, - $this->buildMultiLineString( + $this->buildFailureMessage($this->buildMultiLineString( 'Rule not matched: "0" /TEST/', - 'Original commit message:', - 'test' - ) + ), $commitMsg) ]; yield 'it_applies_matchers_with_multiline' => [ [ @@ -378,10 +382,10 @@ function () { 'matchers' => ['/^hello/'], 'multiline' => true, ], - $this->mockCommitMsgContext($this->buildMessage('you', 'me', 'there')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('you', 'me', 'there')), function () { }, - 'Rule not matched: "0" /^hello/' + $this->buildFailureMessage('Rule not matched: "0" /^hello/', $commitMsg) ]; yield 'it_applies_matchers_without_multiline' => [ [ @@ -389,19 +393,19 @@ function () { 'matchers' => ['/^hello((.|[\n])*)bye$/'], 'multiline' => false, ], - $this->mockCommitMsgContext($this->buildMessage('hello there bye', 'bye good hello')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('hello there bye', 'bye good hello')), function () { }, - 'Rule not matched: "0" /^hello((.|[\n])*)bye$/' + $this->buildFailureMessage('Rule not matched: "0" /^hello((.|[\n])*)bye$/', $commitMsg) ]; yield 'dont-enforce_capitalized_subject_fixup_without_subject' => [ [ 'enforce_capitalized_subject' => true, ], - $this->mockCommitMsgContext($this->buildMessage('', 'only body')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('', 'only body')), function () { }, - 'Subject should start with a capital letter.' + $this->buildFailureMessage('Subject should start with a capital letter.', $commitMsg) ]; yield 'it_fails_on_subject_pattern_default' => [ [ @@ -410,10 +414,10 @@ function () { 'scopes' => null, ], ], - $this->mockCommitMsgContext($this->buildMessage('feat(feature): Это не сработает')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('feat(feature): Это не сработает')), function () { }, - 'Rule not matched: "Invalid Type/Scope Format"' + $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) ]; yield 'it_fails_on_subject_pattern' => [ [ @@ -422,10 +426,10 @@ function () { 'subject_pattern' => '([0-9]+)' ], ], - $this->mockCommitMsgContext($this->buildMessage('It fails')), + $commitMsg = $this->mockCommitMsgContext($this->buildMessage('It fails')), function () { }, - 'Rule not matched: "Invalid Type/Scope Format"' + $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) ]; } From b7cb4134c7addf318cfa046892c5d9c2b0fd9da8 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 15:15:09 +0200 Subject: [PATCH 6/9] Removes commit verification for the scope regex --- test/Unit/Task/Git/CommitMessageTest.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/Unit/Task/Git/CommitMessageTest.php b/test/Unit/Task/Git/CommitMessageTest.php index 18e9d04c..78463db2 100644 --- a/test/Unit/Task/Git/CommitMessageTest.php +++ b/test/Unit/Task/Git/CommitMessageTest.php @@ -38,18 +38,17 @@ protected function provideTask(): TaskInterface private function buildFailureMessage(array|string $lines, GitCommitMsgContext $commitMsg) { - $message = ''; // switch on type of $lines if (is_array($lines)) { + $message = ''; foreach ($lines as $line) { $message .= $line . PHP_EOL; } - } else { - $message .= $lines . PHP_EOL; + + return $message . 'Original commit message:' . PHP_EOL. $commitMsg->getCommitMessage(); } - $message .= 'Original commit message:'. PHP_EOL. $commitMsg->getCommitMessage(); - return $message; + return $lines . PHP_EOL . 'Original commit message:' . PHP_EOL . $commitMsg->getCommitMessage(); } public function provideConfigurableOptions(): iterable @@ -296,7 +295,7 @@ function () { $commitMsg = $this->mockCommitMsgContext($this->buildMessage('doesnt match type scope convention')), function () { }, - $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) + 'Rule not matched: "Invalid Type/Scope Format"' ]; yield 'type_scope_conventions_invalid_type' => [ [ @@ -310,7 +309,7 @@ function () { $commitMsg = $this->mockCommitMsgContext($this->buildMessage('bug: doesnt match type scope convention')), function () { }, - $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) + 'Rule not matched: "Invalid Type/Scope Format"' ]; yield 'type_scope_conventions_invalid_scope' => [ [ @@ -327,7 +326,7 @@ function () { $commitMsg = $this->mockCommitMsgContext($this->buildMessage('fix(api): doesnt match type scope convention')), function () { }, - $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) + 'Rule not matched: "Invalid Type/Scope Format"' ]; yield 'it_fails_on_matchers' => [ [ @@ -417,7 +416,7 @@ function () { $commitMsg = $this->mockCommitMsgContext($this->buildMessage('feat(feature): Это не сработает')), function () { }, - $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) + 'Rule not matched: "Invalid Type/Scope Format"' ]; yield 'it_fails_on_subject_pattern' => [ [ @@ -429,7 +428,7 @@ function () { $commitMsg = $this->mockCommitMsgContext($this->buildMessage('It fails')), function () { }, - $this->buildFailureMessage('Rule not matched: "Invalid Type/Scope Format"', $commitMsg) + 'Rule not matched: "Invalid Type/Scope Format"' ]; } From ce1281937049a2afd55654abdd83273f414e5c66 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 15:16:21 +0200 Subject: [PATCH 7/9] Does not use the array type `buildFailureMessage` function --- test/Unit/Task/Git/CommitMessageTest.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/Unit/Task/Git/CommitMessageTest.php b/test/Unit/Task/Git/CommitMessageTest.php index 78463db2..2d61f886 100644 --- a/test/Unit/Task/Git/CommitMessageTest.php +++ b/test/Unit/Task/Git/CommitMessageTest.php @@ -36,18 +36,8 @@ protected function provideTask(): TaskInterface ); } - private function buildFailureMessage(array|string $lines, GitCommitMsgContext $commitMsg) + private function buildFailureMessage(string $lines, GitCommitMsgContext $commitMsg) { - // switch on type of $lines - if (is_array($lines)) { - $message = ''; - foreach ($lines as $line) { - $message .= $line . PHP_EOL; - } - - return $message . 'Original commit message:' . PHP_EOL. $commitMsg->getCommitMessage(); - } - return $lines . PHP_EOL . 'Original commit message:' . PHP_EOL . $commitMsg->getCommitMessage(); } From 5cd4048f943a738d7b0684281cf0358f4930f244 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 15:18:16 +0200 Subject: [PATCH 8/9] Removes original commit message when it is empty --- src/Task/Git/CommitMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Task/Git/CommitMessage.php b/src/Task/Git/CommitMessage.php index 3b9047ec..6afc018d 100644 --- a/src/Task/Git/CommitMessage.php +++ b/src/Task/Git/CommitMessage.php @@ -122,7 +122,7 @@ public function run(ContextInterface $context): TaskResultInterface return TaskResult::createFailed( $this, $context, - self::withCommitMessage('Commit message should not be empty.', $commitMessage), + 'Commit message should not be empty.', ); } From 9610bc70eb5b2106b4aaa1bf6aca938e547eccdd Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 18 Sep 2023 15:19:43 +0200 Subject: [PATCH 9/9] Removes useless changes on AbstractTaskTestCase --- src/Test/Task/AbstractTaskTestCase.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Test/Task/AbstractTaskTestCase.php b/src/Test/Task/AbstractTaskTestCase.php index a3857c2d..75d682f3 100644 --- a/src/Test/Task/AbstractTaskTestCase.php +++ b/src/Test/Task/AbstractTaskTestCase.php @@ -58,8 +58,6 @@ public function it_contains_configurable_options(array $input, ?array $output): ); } - - /** * @test * @dataProvider provideRunContexts @@ -142,7 +140,8 @@ public function it_skips_on_stuff( array $config, ContextInterface $context, callable $configurator - ): void { + ): void + { $task = $this->configureTask($config); \Closure::bind($configurator, $this)($task->getConfig()->getOptions());