Skip to content

Commit

Permalink
- Fixed deadlock with not mapped issue type in validation flow.
Browse files Browse the repository at this point in the history
  • Loading branch information
andkirby committed Jul 31, 2015
1 parent 2dec471 commit 7595f82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions LibHooks/lib/PreCommit/Processor/CommitMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public function process()
$message = $this->_loadFilter('ShortCommitMsg')
->filter($message);

$this->_loadValidator('CommitMsg')
$this->_loadValidator('IssueType')
->validate($message, null);

$this->_loadValidator('IssueType')
$this->_loadValidator('CommitMsg')
->validate($message, null);

$this->_loadValidator('IssueStatus')
Expand Down
28 changes: 20 additions & 8 deletions LibHooks/lib/PreCommit/Validator/CommitMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CommitMsg extends AbstractValidator
*/
const CODE_BAD_COMMIT_MESSAGE = 'badCommitMessage';
const CODE_VERB_INCORRECT = 'badCommitVerb';
const CODE_ISSUE_TYPE_INCORRECT = 'badIssueType';
const CODE_VERB_NOT_FOUND = 'commitVerbNotFound';
const CODE_KEY_NOT_SET = 'commitKeyNotSet';
/**#@-*/
Expand All @@ -29,10 +30,11 @@ class CommitMsg extends AbstractValidator
* @var array
*/
protected $_errorMessages = array(
self::CODE_BAD_COMMIT_MESSAGE => 'Head of commit message "%value%" has improper form.',
self::CODE_VERB_INCORRECT => 'Commit verb "%value%" is not suitable for the issue.',
self::CODE_VERB_NOT_FOUND => 'Commit verb "%value%" not found.',
self::CODE_KEY_NOT_SET => 'Required commit key "%value%" is not set.',
self::CODE_BAD_COMMIT_MESSAGE => 'Head of commit message "%value%" has improper form.',
self::CODE_VERB_INCORRECT => 'Commit verb "%value%" is not suitable for the issue.',
self::CODE_ISSUE_TYPE_INCORRECT => 'Issue type "%value%" is not suitable to check verb properly. Please take a look your configuration.',
self::CODE_VERB_NOT_FOUND => 'Commit verb "%value%" not found.',
self::CODE_KEY_NOT_SET => 'Required commit key "%value%" is not set.',
);

/**
Expand Down Expand Up @@ -166,10 +168,19 @@ protected function _getInterpreterResult($message, array $config)
}

//check allowed verb by issue type
$allowed = $this->_getAllowedVerbs($message->issue->getType());
if ($message->issue && (!isset($allowed[$key]) || !$allowed[$key])) {
$this->_addError('Commit Message', self::CODE_VERB_INCORRECT, $message->verb);
return false;
if (!$this->_errorCollector->hasErrors()) {
if (!$message->issue->getType()) {
$this->_addError(
'Commit Message', self::CODE_ISSUE_TYPE_INCORRECT, $message->issue->getOriginalType()
);
return false;
}
//it's cannot be processed if issue type is not valid
$allowed = $this->_getAllowedVerbs($message->issue->getType());
if (!isset($allowed[$key]) || !$allowed[$key]) {
$this->_addError('Commit Message', self::CODE_VERB_INCORRECT, $message->verb);
return false;
}
}
}
return true;
Expand All @@ -180,6 +191,7 @@ protected function _getInterpreterResult($message, array $config)
*
* @param string $type
* @return array
* @throws \PreCommit\Exception
*/
protected function _getAllowedVerbs($type)
{
Expand Down

0 comments on commit 7595f82

Please sign in to comment.