diff --git a/src/Task/Git/CommitMessage.php b/src/Task/Git/CommitMessage.php index 2d263d5a..8930118b 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,12 @@ public function canRunInContext(ContextInterface $context): bool return $context instanceof GitCommitMsgContext; } + private static function withCommitMessage(string $errorMessage, string $commitMessage): string + { + return $errorMessage;//.PHP_EOL.'Original commit message:'.PHP_EOL.$commitMessage; + } + + public function run(ContextInterface $context): TaskResultInterface { assert($context instanceof GitCommitMsgContext); @@ -110,7 +116,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 +124,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 +132,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 +140,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 +148,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 +172,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 +213,7 @@ 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); diff --git a/test/Unit/Task/Git/CommitMessageTest.php b/test/Unit/Task/Git/CommitMessageTest.php index ef50077b..4a574adc 100644 --- a/test/Unit/Task/Git/CommitMessageTest.php +++ b/test/Unit/Task/Git/CommitMessageTest.php @@ -435,7 +435,7 @@ function () { yield 'allow_starts_with_custom_comment_char' => [ [ 'allow_empty_message' => false, - 'enforce_capitalized_subject' => true, + 'enforce_capitalized_subject' => true, 'enforce_no_subject_trailing_period' => false, 'enforce_single_lined_subject' => false, ],