public function testMessageBody() { $this->gitRoot = $this->shmock('\\Bart\\Git\\GitRoot', function ($root) { $output = 'TOP-338 run unit tests when Nate or Zack commit code Change-Id: Iecb840ccccf70a79ae622c583761107aa1a1b7b9'; $resultStub = new StubbedCommandResult([$output], 0); $root->getCommandResult('show -s --pretty=%s --no-color %s', 'format:%B', 'HEAD')->once()->return_value($resultStub); }); $commit = new Commit($this->gitRoot, 'HEAD'); // Assert all lines of log message are included $message = $commit->messageBody(); $this->assertStringStartsWith('TOP-338', $message, 'No escape args silliness with quotes'); $this->assertContains('TOP-338 run unit', $message, 'line one'); $this->assertContains('Iecb840ccccf70a79ae622c583761107aa1a1b7b9', $message, 'line two'); }
/** * @param Commit $commit * @return bool If the commit should be skipped by the hook */ private function shouldSkip(Commit $commit, GitHookConfig $gitHookConfig) { $message = $commit->messageBody(); $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; }