diff --git a/DOCS.md b/DOCS.md index 991115d..fc61b3c 100644 --- a/DOCS.md +++ b/DOCS.md @@ -11,21 +11,22 @@ url: https://gitnet.fr/deblan/woodpecker-email ## Settings -| Settings Name | Required | Type | Description | Documentation | -| --------------- | -------- | ------------------ | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | -| dsn | yes | `string` | Mail transport configuration | [Documentation](https://symfony.com/doc/current/mailer.html#tls-peer-verification) | -| from.address | yes | `string` | Email address of the sender | | -| from.name | no | `string` | Name of the sender | | -| recipients | no | `string` or `list` | List of recipients to send this mail to (besides the commit author) | YAML list or comma separated list | -| recipients_only | no | `boolean` | Exclude the committer (default: `false`) | | -| content.subject | no | `string` | Define the email subject template | | -| content.body | no | `string` | Define the email body template | | -| attachments | no | `string` or `list` | List of files to attach | YAML list or comma separated list | -| debug | no | `boolean` | Debug mode (email are sent!, default: `false`) | | + | Settings Name | Required | Type | Description | Documentation | + | --------------- | -------- | ------------------ | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | + | dsn | yes | `string` | Mail transport configuration | [Documentation](https://symfony.com/doc/current/mailer.html#tls-peer-verification) | + | from.address | yes | `string` | Email address of the sender | | + | from.name | no | `string` | Name of the sender | | + | recipients | no | `string` or `list` | List of recipients to send this mail to (besides the commit author) | YAML list or comma separated list | + | recipients_only | no | `boolean` | Exclude the committer (default: `false`) | | + | content.subject | no | `string` | Define the email subject template | | + | content.body | no | `string` | Define the email body template | | + | attachments | no | `string` or `list` | List of files to attach | YAML list or comma separated list | + | debug | no | `boolean` | Debug mode (email are sent!, default: `false`) | | + | level | no | `string` | Define the level of the mail (default: `info`, values: `info`, `success`, `warning`, `failure`) | | -### Example +### Examples -``` +```yaml steps: mail: image: deblan/woodpecker-email @@ -34,10 +35,11 @@ steps: from: address: "woodpecker@example.com" name: "Woodpecker" - evaluate: "prev_pipeline.status == 'failure'" + evaluate: 'commit.branch == "master"' recipients: - dev1@example.com - dev2@example.com + level: success recipients_only: false content: subject: "[{{ pipeline.status }}] {{ repo.full_name }} ({{ commit.branch }} - {{ commit.sha[0:8] }}" @@ -49,6 +51,18 @@ steps: - log/* ``` +```yaml +steps: + mail: + image: deblan/woodpecker-email + settings: + level: failure + # ... + when: + status: + - failure +``` + ### Evaluation and content See the [Twig documentation](https://twig.symfony.com/doc/3.x/). diff --git a/bin/console b/bin/console index 77ef8b6..ae6914e 100755 --- a/bin/console +++ b/bin/console @@ -87,6 +87,7 @@ $config = EnvVarLoader::buildArray([ 'attachments' => 'PLUGIN_ATTACHMENTS', 'evaluate' => 'PLUGIN_EVALUATE', 'content' => 'PLUGIN_CONTENT', + 'level' => 'PLUGIN_LEVEL', 'is_debug' => 'PLUGIN_DEBUG', ], [ 'PLUGIN_RECIPIENTS_ONLY' => false, diff --git a/src/Factory/EmailFactory.php b/src/Factory/EmailFactory.php index 4f9614c..6e199e8 100644 --- a/src/Factory/EmailFactory.php +++ b/src/Factory/EmailFactory.php @@ -28,13 +28,17 @@ class EmailFactory { $from = json_decode($this->config['from'], true); $content = json_decode($this->config['content'], true); + $level = isset($this->config['level']) && is_string($this->config['level']) + ? $this->config['level'] + : 'info' + ; $subject = $this->twig->createTemplate( - $content['subject'] ?? '{{ repo.full_name }} ({{ commit.branch }} - {{ commit.sha[0:8] }})' + $content['subject'] ?? '[{{ level }}] {{ repo.full_name }} ({{ commit.branch }} - {{ commit.sha[0:8] }})' ); $email = (new Email()) - ->subject($subject->render($this->build)) + ->subject($subject->render(array_merge($this->build, ['level' => $level]))) ->from( new Address( $from['address'] ?? '', @@ -68,6 +72,7 @@ class EmailFactory $email->html($this->twig->render('build_status.html.twig', [ 'build' => $this->build, + 'level' => $level, 'body' => $content['body'] ?? null, ])); diff --git a/templates/_base.html.twig b/templates/_base.html.twig index 7f48112..fb803c5 100644 --- a/templates/_base.html.twig +++ b/templates/_base.html.twig @@ -11,6 +11,7 @@ box-sizing: border-box; font-size: 14px; } + body { -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; @@ -19,13 +20,16 @@ line-height: 1.6; background-color: #f6f6f6; } + table td { vertical-align: top; } + .body-wrap { background-color: #f6f6f6; width: 100%; } + .container { display: block !important; max-width: 600px !important; @@ -33,27 +37,33 @@ /* makes it centered */ clear: both !important; } + .content { max-width: 600px; margin: 0 auto; display: block; padding: 20px; } + .main { background: #fff; border: 1px solid #e9e9e9; border-radius: 3px; } + .content-wrap { padding: 20px; } + .content-block { padding: 0 0 20px; } + .header { width: 100%; margin-bottom: 20px; } + h1, h2, h3 { font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; color: #000; @@ -61,59 +71,74 @@ line-height: 1.2; font-weight: 400; } + h1 { font-size: 32px; font-weight: 500; } + h2 { font-size: 24px; } + h3 { font-size: 18px; } + hr { border: 1px solid #e9e9e9; margin: 20px 0; height: 1px; padding: 0; } + p, ul, ol { margin-bottom: 10px; font-weight: normal; } + p li, ul li, ol li { margin-left: 5px; list-style-position: inside; } + a { color: #348eda; text-decoration: underline; } + .last { margin-bottom: 0; } + .first { margin-top: 0; } + .padding { padding: 10px 0; } + .aligncenter { text-align: center; } + .alignright { text-align: right; } + .alignleft { text-align: left; } + .clear { clear: both; } + .alert { font-size: 16px; color: #fff; @@ -122,24 +147,30 @@ text-align: center; border-radius: 3px 3px 0 0; } + .alert a { color: #fff; text-decoration: none; font-weight: 500; font-size: 16px; } + .alert.alert-warning { background: #ff9f00; } - .alert.alert-bad { + + .alert.alert-failure { background: #d0021b; } - .alert.alert-good { + + .alert.alert-success { background: #68b90f; } + .alert.alert-info { background: #117eb9; } + @media only screen and (max-width: 640px) { h1, h2, @@ -147,18 +178,23 @@ font-weight: 600 !important; margin: 20px 0 5px !important; } + h1 { font-size: 22px !important; } + h2 { font-size: 18px !important; } + h3 { font-size: 16px !important; } + .container { width: 100% !important; } + .content, .content-wrapper { padding: 10px !important; diff --git a/templates/build_status.html.twig b/templates/build_status.html.twig index c7bf16e..8641eb4 100644 --- a/templates/build_status.html.twig +++ b/templates/build_status.html.twig @@ -8,28 +8,12 @@
- - - {# REGRESSION #} - {# - {% if build.pipeline.status == 'success' %} - - {% else %} - - {% endif %} - #}
+ + {{ level|capitalize }} - Pipeline #{{ build.pipeline.number }} - - Successful pipeline #{{ build.pipeline.number }} - - - - Failed pipeline #{{ build.pipeline.number }} - -