messageSubject() public method

public messageSubject ( ) : string
return string The first non-blank lines of the commit message
Beispiel #1
0
 public function testMessageSubject()
 {
     // This test is pretty much a "it compiles" test
     $this->gitRoot = $this->shmock('\\Bart\\Git\\GitRoot', function ($root) {
         $output = 'TOP-338 run unit tests when Nate or Zack commit code';
         $resultStub = new StubbedCommandResult([$output], 0);
         $root->getCommandResult("show -s --no-color --format='%%s' HEAD")->once()->return_value($resultStub);
     });
     $commit = new Commit($this->gitRoot, 'HEAD');
     // Assert all lines of log message are included
     $message = $commit->messageSubject();
     $this->assertStringStartsWith('TOP-338', $message, 'No escape args silliness with quotes');
     $this->assertEquals('TOP-338 run unit tests when Nate or Zack commit code', $message, 'line one and only line one');
 }
Beispiel #2
0
 /**
  * @param Commit $commit
  * @throws GitHookException
  * @throws GitException
  */
 public function run(Commit $commit)
 {
     if ($this->job->isHealthy()) {
         $this->logger->debug('Jenkins job is healthy.');
         return;
     }
     $this->logger->info('Jenkins job is not healthy...asserting that commit message contains {buildfix} hash');
     $messageSubject = $commit->messageSubject();
     $buildFixDirective = Directives::BUILD_FIX();
     // Check if commit has buildfix directive
     if (preg_match("/{$buildFixDirective->value()}/", $messageSubject) > 0) {
         $this->logger->info("Commit has {$buildFixDirective} directive. It attempts to fix build");
         return;
     }
     throw new GitHookException('Jenkins not healthy and commit does not fix it');
 }
Beispiel #3
0
 /**
  * @param Commit $commit
  * @return bool If the commit should be skipped by the hook
  */
 private function shouldSkip(Commit $commit, GitHookConfig $gitHookConfig)
 {
     $message = $commit->messageSubject();
     $isEmergency = preg_match('/^EMERGENCY/', $message) === 1;
     if ($isEmergency) {
         $to = $gitHookConfig->getEmergencyNotificationEmailAddress();
         $subject = $gitHookConfig->getEmergencyNotificationSubject();
         $body = $gitHookConfig->getEmergencyNotificationBody();
         if (!empty($to) && !empty($subject) && !empty($body)) {
             GlobalFunctions::mail($to, $subject, $body);
         } else {
             $this->logger->error("Invalid mail params. Notification email not sent.");
         }
     }
     return $isEmergency;
 }