diff --git a/PHPCI/Plugin/Email.php b/PHPCI/Plugin/Email.php index 8414451f..c2638860 100644 --- a/PHPCI/Plugin/Email.php +++ b/PHPCI/Plugin/Email.php @@ -9,11 +9,13 @@ namespace PHPCI\Plugin; +use Exception; use b8\View; use PHPCI\Builder; use PHPCI\Helper\Lang; use PHPCI\Model\Build; use PHPCI\Helper\Email as EmailHelper; +use Psr\Log\LogLevel; /** * Email Plugin - Provides simple email capability to PHPCI. @@ -70,12 +72,25 @@ class Email implements \PHPCI\Plugin $buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build"; $projectName = $this->build->getProject()->getTitle(); - $mailTemplate = $this->build->isSuccessful() ? 'Email/success' : 'Email/failed'; - $view = new View($mailTemplate); + try { + $view = $this->getMailTemplate(); + } catch (Exception $e) { + $this->phpci->log( + sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']), + LogLevel::WARNING + ); + $view = $this->getDefaultMailTemplate(); + } + $view->build = $this->build; $view->project = $this->build->getProject(); - $body = $view->render(); + + $layout = new View('Email/layout'); + $layout->build = $this->build; + $layout->project = $this->build->getProject(); + $layout->content = $view->render(); + $body = $layout->render(); $sendFailures = $this->sendSeparateEmails( $addresses, @@ -97,7 +112,7 @@ class Email implements \PHPCI\Plugin * @param string $body Email body * @return array Array of failed addresses */ - public function sendEmail($toAddress, $ccList, $subject, $body) + protected function sendEmail($toAddress, $ccList, $subject, $body) { $email = new EmailHelper(); @@ -168,6 +183,7 @@ class Email implements \PHPCI\Plugin /** * Get the list of email addresses to CC. + * * @return array */ protected function getCcAddresses() @@ -182,4 +198,30 @@ class Email implements \PHPCI\Plugin return $ccAddresses; } + + /** + * Get the mail template used to sent the mail. + * + * @return View + */ + protected function getMailTemplate() + { + if (isset($this->options['template'])) { + return new View('Email/' . $this->options['template']); + } + + return $this->getDefaultMailTemplate(); + } + + /** + * Get the default mail template. + * + * @return View + */ + protected function getDefaultMailTemplate() + { + $template = $this->build->isSuccessful() ? 'short' : 'long'; + + return new View('Email/' . $template); + } } diff --git a/PHPCI/View/Email/failed.phtml b/PHPCI/View/Email/failed.phtml deleted file mode 100644 index 4391748f..00000000 --- a/PHPCI/View/Email/failed.phtml +++ /dev/null @@ -1,15 +0,0 @@ -
-
-
- getTitle(); ?> - Build #getId(); ?> -
- -
-

Your commit getCommitId(); ?> caused a failed build in project getTitle(); ?>.

- -

getCommitMessage(); ?>

- -

Please review your commit and the build log.

-
-
-
\ No newline at end of file diff --git a/PHPCI/View/Email/layout.phtml b/PHPCI/View/Email/layout.phtml new file mode 100644 index 00000000..878a9c9e --- /dev/null +++ b/PHPCI/View/Email/layout.phtml @@ -0,0 +1,28 @@ + + + + + +
+
+
getTitle(); ?> - Build #getId(); ?>
+
+

+ Your commit getCommitId(); ?> generated a + isSuccessful() ? 'successful' : 'failed'; ?> build in project + getTitle(); ?>. +

+ +
+ +
+
+ + diff --git a/PHPCI/View/Email/long.phtml b/PHPCI/View/Email/long.phtml new file mode 100644 index 00000000..35464504 --- /dev/null +++ b/PHPCI/View/Email/long.phtml @@ -0,0 +1,2 @@ +

getCommitMessage(); ?>

+
getLog()); ?>
diff --git a/PHPCI/View/Email/short.phtml b/PHPCI/View/Email/short.phtml new file mode 100644 index 00000000..75df4f83 --- /dev/null +++ b/PHPCI/View/Email/short.phtml @@ -0,0 +1 @@ +

getCommitMessage(); ?>

diff --git a/PHPCI/View/Email/success.phtml b/PHPCI/View/Email/success.phtml deleted file mode 100644 index 342e3483..00000000 --- a/PHPCI/View/Email/success.phtml +++ /dev/null @@ -1,17 +0,0 @@ - - -
-
-
- getTitle(); ?> - Build #getId(); ?> -
- -
-

Your commit getCommitId(); ?> genrate a successfull build in project getTitle(); ?>.

- -

getCommitMessage(); ?>

-
getLog()); ?>
-

You can review your commit and the build log.

-
-
-
diff --git a/Tests/PHPCI/Plugin/EmailTest.php b/Tests/PHPCI/Plugin/EmailTest.php index 18eaf948..bb039ca4 100644 --- a/Tests/PHPCI/Plugin/EmailTest.php +++ b/Tests/PHPCI/Plugin/EmailTest.php @@ -349,7 +349,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->testedEmailPlugin->execute(); $this->assertContains('Passing', $this->message['subject']); - $this->assertContains('successfull', $this->message['body']); + $this->assertContains('successful', $this->message['body']); } /**