Skip to content

Commit

Permalink
Merge pull request #1103 from malcomio/extensions
Browse files Browse the repository at this point in the history
add extensions argument - fixes #1098
  • Loading branch information
veewee authored and EwenQuim committed Sep 14, 2023
2 parents 7f007bc + 5313baa commit 1bd9906
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
36 changes: 24 additions & 12 deletions src/Task/Git/CommitMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.+)';

/**
Expand Down Expand Up @@ -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);
Expand All @@ -110,39 +122,39 @@ 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),
);
}

if ((bool) $config['enforce_capitalized_subject'] && !$this->subjectIsCapitalized($context)) {
return TaskResult::createFailed(
$this,
$context,
'Subject should start with a capital letter.'
self::withCommitMessage('Subject should start with a capital letter.', $commitMessage)
);
}

if ((bool) $config['enforce_single_lined_subject'] && !$this->subjectIsSingleLined($context)) {
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)
);
}

if ((bool) $config['enforce_no_subject_punctuations'] && $this->subjectHasPunctuations($context)) {
return TaskResult::createFailed(
$this,
$context,
'Please omit all punctuations from commit message subject.'
self::withCommitMessage('Please omit all punctuations from commit message subject.', $commitMessage)
);
}

if ((bool) $config['enforce_no_subject_trailing_period'] && $this->subjectHasTrailingPeriod($context)) {
return TaskResult::createFailed(
$this,
$context,
'Please omit trailing period from commit message subject.'
self::withCommitMessage('Please omit trailing period from commit message subject.', $commitMessage)
);
}

Expand All @@ -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)
);
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Task/PhpMd.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public function run(ContextInterface $context): TaskResultInterface
$arguments->addOptionalArgument('--exclude', !empty($config['exclude']));
$arguments->addOptionalCommaSeparatedArgument('%s', $config['exclude']);

$arguments->addOptionalArgument('--suffixes', !empty($extensions));
$arguments->addOptionalCommaSeparatedArgument('%s', $extensions);

$process = $this->processBuilder->buildProcess($arguments);
$process->run();

Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Task/Git/CommitMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
8 changes: 8 additions & 0 deletions test/Unit/Task/PhpMdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public function provideExternalTaskRuns(): iterable
'hello.php,hello2.php',
'text',
'cleancode,codesize,naming',
'--suffixes',
'php',
]
];

Expand All @@ -129,6 +131,8 @@ public function provideExternalTaskRuns(): iterable
'cleancode,codesize,naming',
'--exclude',
'hello.php,hello2.php',
'--suffixes',
'php',
]
];

Expand All @@ -142,6 +146,8 @@ public function provideExternalTaskRuns(): iterable
'hello.php,hello2.php',
'text',
'cleancode',
'--suffixes',
'php',
]
];

Expand All @@ -155,6 +161,8 @@ public function provideExternalTaskRuns(): iterable
'hello.php,hello2.php',
'ansi',
'cleancode,codesize,naming',
'--suffixes',
'php',
]
];
}
Expand Down

0 comments on commit 1bd9906

Please sign in to comment.