Compare commits
18 commits
Author | SHA1 | Date | |
---|---|---|---|
Simon Vieille | 7fe9f79d0e | ||
Simon Vieille | 99d94eb54d | ||
Simon Vieille | 961034266b | ||
Simon Vieille | 3b643ccd64 | ||
Simon Vieille | 0c342094b6 | ||
Simon Vieille | f53ebebeb2 | ||
Simon Vieille | e1700c42b0 | ||
Simon Vieille | b371b48625 | ||
Simon Vieille | 2ecafbe733 | ||
Simon Vieille | 82cd91641e | ||
Simon Vieille | be806166b4 | ||
Simon Vieille | a291a03d89 | ||
Simon Vieille | 84a6fa518f | ||
Simon Vieille | 3fe8426262 | ||
667aa7a576 | |||
Simon Vieille | 20daf68990 | ||
Simon Vieille | 04f4d8badc | ||
Simon Vieille | 0a58f767f9 |
|
@ -1,63 +1,27 @@
|
|||
steps:
|
||||
dep:
|
||||
image: deblan/php:8.2
|
||||
commands:
|
||||
- composer install
|
||||
when:
|
||||
event: [push]
|
||||
|
||||
build_push_latest_gitnet:
|
||||
image: plugins/docker
|
||||
secrets: [registry_user, registry_password]
|
||||
"Test docker build":
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
settings:
|
||||
registry: gitnet.fr
|
||||
repo: gitnet.fr/${CI_REPO}
|
||||
tags: latest
|
||||
username:
|
||||
from_secret: registry_user
|
||||
password:
|
||||
from_secret: registry_password
|
||||
when:
|
||||
branch: [master]
|
||||
event: [push]
|
||||
repo: gitnet.fr/deblan/woodpecker-email
|
||||
dry-run: true
|
||||
|
||||
build_push_tag_gitnet:
|
||||
image: plugins/docker
|
||||
secrets: [registry_user, registry_password]
|
||||
"Docker build and push":
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
settings:
|
||||
registry: gitnet.fr
|
||||
repo: gitnet.fr/${CI_REPO}
|
||||
tags: ${CI_COMMIT_TAG}
|
||||
username:
|
||||
from_secret: registry_user
|
||||
password:
|
||||
from_secret: registry_password
|
||||
repo: gitnet.fr/deblan/woodpecker-email,deblan/woodpecker-email
|
||||
tags: ${CI_COMMIT_TAG=latest}
|
||||
logins:
|
||||
- registry: https://gitnet.fr
|
||||
username:
|
||||
from_secret: registry_user
|
||||
password:
|
||||
from_secret: registry_password
|
||||
- registry: https://index.docker.io/v1/
|
||||
username:
|
||||
from_secret: registry_user
|
||||
password:
|
||||
from_secret: registry_docker_password
|
||||
when:
|
||||
event: [tag]
|
||||
|
||||
build_push_latest_dhub:
|
||||
image: plugins/docker
|
||||
secrets: [registry_user, registry_docker_password]
|
||||
settings:
|
||||
repo: ${CI_REPO}
|
||||
tags: latest
|
||||
username:
|
||||
from_secret: registry_user
|
||||
password:
|
||||
from_secret: registry_docker_password
|
||||
when:
|
||||
branch: [master]
|
||||
event: [push]
|
||||
|
||||
build_push_tag_dhub:
|
||||
image: plugins/docker
|
||||
secrets: [registry_user, registry_docker_password]
|
||||
settings:
|
||||
repo: ${CI_REPO}
|
||||
tags: ${CI_COMMIT_TAG}
|
||||
username:
|
||||
from_secret: registry_user
|
||||
password:
|
||||
from_secret: registry_docker_password
|
||||
when:
|
||||
event: [tag]
|
||||
- branch: [master]
|
||||
event: [push]
|
||||
- event: [tag]
|
||||
|
|
15
DOCS.md
15
DOCS.md
|
@ -12,25 +12,23 @@ 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 | `0string` | Name 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 | |
|
||||
| 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!) | |
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```
|
||||
steps:
|
||||
mail:
|
||||
image: deblan/woodpecker-email-php
|
||||
image: deblan/woodpecker-email
|
||||
settings:
|
||||
dsn: "smtp://username:password@mail.example.com:587?verify_peer=1"
|
||||
from:
|
||||
|
@ -51,14 +49,12 @@ steps:
|
|||
- log/*
|
||||
```
|
||||
|
||||
|
||||
### Evaluation and content
|
||||
|
||||
See the [Twig documentation](https://twig.symfony.com/doc/3.x/).
|
||||
|
||||
|
||||
| Variable | Value |
|
||||
| --- | --- |
|
||||
| ----------------------------- | -------------------------------- |
|
||||
| `workspace` | `CI_WORKSPACE` |
|
||||
| `repo.full_name` | `CI_REPO` |
|
||||
| `repo.owner` | `CI_REPO_OWNER` |
|
||||
|
@ -76,6 +72,7 @@ See the [Twig documentation](https://twig.symfony.com/doc/3.x/).
|
|||
| `commit.author` | `CI_COMMIT_AUTHOR` |
|
||||
| `commit.author_email` | `CI_COMMIT_AUTHOR_EMAIL` |
|
||||
| `commit.author_avatar` | `CI_COMMIT_AUTHOR_AVATAR` |
|
||||
| `commit.prerelease` | `CI_COMMIT_PRERELEASE` |
|
||||
| `prev_commit.sha` | `CI_PREV_COMMIT_SHA` |
|
||||
| `prev_commit.ref` | `CI_PREV_COMMIT_REF` |
|
||||
| `prev_commit.branch` | `CI_PREV_COMMIT_BRANCH` |
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM deblan/php:8.2
|
||||
FROM deblan/php:8.3
|
||||
|
||||
WORKDIR /opt/app
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# woodpecker-email-php
|
||||
# woodpecker-email
|
||||
|
||||
Woodpecker plugin to send build status notifications via Email. For the usage information and a listing of the available options please take a look at [the docs](DOCS.md).
|
||||
|
|
33
bin/console
33
bin/console
|
@ -9,6 +9,7 @@ use Plugin\Loader\EnvVarLoader;
|
|||
use Plugin\Pipeline\Evaluation;
|
||||
use Symfony\Component\Mailer\Exception\TransportException;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Symfony\Component\Mime\Exception\RfcComplianceException;
|
||||
|
||||
$build = EnvVarLoader::buildArray([
|
||||
'workspace' => 'CI_WORKSPACE',
|
||||
|
@ -32,6 +33,7 @@ $build = EnvVarLoader::buildArray([
|
|||
'author' => 'CI_COMMIT_AUTHOR',
|
||||
'author_email' => 'CI_COMMIT_AUTHOR_EMAIL',
|
||||
'author_avatar' => 'CI_COMMIT_AUTHOR_AVATAR',
|
||||
'prerelease' => 'CI_COMMIT_PRERELEASE',
|
||||
],
|
||||
'prev_commit' => [
|
||||
'sha' => 'CI_PREV_COMMIT_SHA',
|
||||
|
@ -88,8 +90,10 @@ $config = EnvVarLoader::buildArray([
|
|||
'attachments' => 'PLUGIN_ATTACHMENTS',
|
||||
'evaluate' => 'PLUGIN_EVALUATE',
|
||||
'content' => 'PLUGIN_CONTENT',
|
||||
'is_debug' => 'PLUGIN_DEBUG',
|
||||
], [
|
||||
'PLUGIN_RECIPIENTS_ONLY' => true,
|
||||
'PLUGIN_DEBUG' => false,
|
||||
]);
|
||||
|
||||
function writeln(...$values)
|
||||
|
@ -99,16 +103,35 @@ function writeln(...$values)
|
|||
}
|
||||
}
|
||||
|
||||
function handleError($section, Exception $e)
|
||||
function handleError($section, Exception $e, bool $debug)
|
||||
{
|
||||
writeln(
|
||||
sprintf('ERROR - %s', $section),
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
if ($debug) {
|
||||
writeln(
|
||||
"",
|
||||
"Trace",
|
||||
"=====",
|
||||
json_encode($e->getTrace(), JSON_PRETTY_PRINT),
|
||||
"=====",
|
||||
);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ($config['is_debug']) {
|
||||
writeln(
|
||||
'Debug',
|
||||
'=====',
|
||||
json_encode(['config' => $config, 'environment' => $_SERVER], JSON_PRETTY_PRINT),
|
||||
'=====',
|
||||
);
|
||||
}
|
||||
|
||||
$twig = (new TwigFactory())->create();
|
||||
$emailFactory = new EmailFactory($twig, $config, $build);
|
||||
$evaluation = new Evaluation($twig);
|
||||
|
@ -125,9 +148,11 @@ try {
|
|||
writeln('Email sent!');
|
||||
}
|
||||
} catch (SyntaxError $e) {
|
||||
handleError('Syntax error', $e);
|
||||
handleError('Syntax error', $e, $config['is_debug']);
|
||||
} catch (TransportException $e) {
|
||||
handleError('Transport error', $e);
|
||||
handleError('Transport error', $e, $config['is_debug']);
|
||||
} catch (RfcComplianceException $e) {
|
||||
handleError('RFC compliance error', $e, $config['is_debug']);
|
||||
} catch (\Exception $e) {
|
||||
handleError('Generic error', $e);
|
||||
handleError('Generic error', $e, $config['is_debug']);
|
||||
}
|
||||
|
|
3
renovate.json
Normal file
3
renovate.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
|
@ -21,7 +21,7 @@ class EmailFactory
|
|||
|
||||
public function createMailer(): Mailer
|
||||
{
|
||||
return new Mailer(Transport::fromDsn($this->config['dsn']));
|
||||
return new Mailer(Transport::fromDsn((string) $this->config['dsn']));
|
||||
}
|
||||
|
||||
public function createEmail(): Email
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
namespace Plugin\Factory;
|
||||
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
use Twig\Extension\StringLoaderExtension;
|
||||
use Twig\Extension\DebugExtension;
|
||||
use Twig\Extension\StringLoaderExtension;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
|
||||
class TwigFactory
|
||||
{
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Plugin\Helper;
|
||||
|
||||
function loadEnVars(array $map, array $defaults = [])
|
||||
{
|
||||
$container = [];
|
||||
|
||||
foreach ($map as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$container[$key] = loadEnVars($value);
|
||||
} else {
|
||||
$data = getenv($value);
|
||||
|
||||
if ($data === false) {
|
||||
$data = $defaults[$value] ?? null;
|
||||
}
|
||||
|
||||
if (str_ends_with($key, '_at') && ctype_digit($data)) {
|
||||
$date = new \DateTime();
|
||||
$date->setTimestamp((int) $data);
|
||||
$data = $date;
|
||||
} elseif (str_starts_with($key, 'is_')) {
|
||||
if (in_array(strtolower($data), ['1', 'true', 'yes'])) {
|
||||
$data = true;
|
||||
} elseif (in_array(strtolower($data), ['0', 'false', 'no'])) {
|
||||
$data = false;
|
||||
} else {
|
||||
$data = $defaults[$value] ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
$container[$key] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="content-wrap">
|
||||
{% if body is defined %}
|
||||
{% if body is defined and body|length > 0 %}
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td>{{ include(template_from_string(body), build) }}</td>
|
||||
|
|
Loading…
Reference in a new issue