Beispiel #1
0
 /**
  * Get result by external matching
  *
  * @param Message $message
  * @param array   $config
  * @return bool
  * @throws \PreCommit\Exception
  */
 protected function getInterpreterResult($message, array $config)
 {
     $result = null;
     if (!$message->verb) {
         $result = $this->getInterpreter($config)->interpret(array('message' => $message));
         /**
          * Set interpreted keys to message object
          */
         if (!empty($result['verb'])) {
             $message->verb = $result['verb'];
         }
         if (!empty($result['issue_key'])) {
             $message->issueKey = $result['issue_key'];
         }
         if (!empty($result['summary'])) {
             $message->summary = $result['summary'];
         }
     }
     if (!$message->issueKey) {
         //cannot recognize message format
         return false;
     }
     //Initialize issue adapter
     if (!$message->issue && $message->issueKey) {
         $message->issue = Issue::factory($message->issueKey);
     }
     /**
      * Check empty required keys from interpreted result
      *
      * At least issue key should be set after interpreting
      */
     if ($result) {
         foreach ($this->getRequiredKeys() as $name => $enabled) {
             if (!$enabled) {
                 continue;
             }
             if (!isset($result[$name]) || !$result[$name]) {
                 $this->addError('Commit Message', self::CODE_VERB_INCORRECT, $name);
                 return false;
             }
         }
     }
     /**
      * Check verb is allowed for issue type
      */
     if ($message->issue) {
         //find verb key
         $key = array_search($message->verb, $this->getVerbs());
         if (false === $key) {
             $this->addError('Commit Message', self::CODE_VERB_NOT_FOUND, $message->verb);
             return false;
         }
         //check allowed verb by issue type
         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;
 }
Beispiel #2
0
 /**
  * Initialize issue adapter
  *
  * @param string $issueKey
  * @return $this
  * @throws \PreCommit\Exception
  */
 protected function initIssue($issueKey)
 {
     $this->issue = Issue::factory($issueKey);
     return $this;
 }
Beispiel #3
0
 /**
  * Load issue
  *
  * @param string $key
  * @return Issue\AdapterInterface
  */
 protected function loadIssue($key)
 {
     $issue = Issue::factory($key);
     $issue->getStatus();
     return $issue;
 }