initial commit

This commit is contained in:
Brad Rydzewski 2015-11-10 17:44:23 -08:00
parent 790df28ae1
commit fa69400d6c
6 changed files with 101 additions and 7 deletions

1
.drone.sec Normal file
View file

@ -0,0 +1 @@
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.ivt1r_hG7xhdImbwXIKSnGTkja9yPox9EjA58WhNXEvi7YHdFKsHx5LNcyH_o1W9LrUZEg0ag7QSEklpz900YdNX9HP6lpQ0yZso7Igo6i39nmvEihKypuIGWq8T3Vg7-ZH6UqwYuirxTKFU6lXcym-MLx7c8SEXdpnvUVO-Iq1X2ZGDLHjpi3h81qfsl5cvDdJadq9C2gCrqcHzXiiGLFMNVcB0zeIu8Q0osAZvmzMo9RoWZ3aAz8MH7JNNwbrUkZpO5t9wH0MqaaYbEKACWT6JP1XAUsEWv48CHQ1G2rtdNcjYMtJQbN78joTNkvDK6RkmBC5ZuCqfgeD_7Mi8OA.3hffaFSq-yxJWWaK._Ld4LgMpg4rn02CsVTTxrHbCUwmR_Z-JSkgAJgZg-U3Qz-EStA1G5G6oiOzunWMGTMgUDql4r8kigpC41GVbvv1_XGbUxKaribC_5p1_SBPZ8nZQ03zeKBp9-opW_gsImQkaqbG0L0GhHKVIaibhAsovo_92bb_gLu_W6oZgrWtATt1qgN0Q-8uRcfo-tuIzI0nU5vlQ4bmmNqfnT7QxGMIV-WhKZy5Rj004izO6bJojuAwuWq_WugWIhQbz-qpVnu0LlLwBbEVBaj6RsSULRHf_1UYVe_K3mmHxbcEpuRkiOU7yRJvwxsprQc0Hqge95QGKgwehZGF6SXfQstm4QnuV17_8PH3--cVLkIgzoZZ7yKWOYNqznn_ZX5jAFZdF5nRqyA.Ea5tn0QTKCKsjGoGP3tHlQ

22
DOCS.md Normal file
View file

@ -0,0 +1,22 @@
Use the Email plugin to send an email to a recipient list when a build completes. The following parameters are used to configuration the email plugin:
* **from** - sends email from this address
* **host** - smtp server host
* **port** - smtp server port (defaults to `587`)
* **username** - smtp server username
* **password** - smtp server password
* **recipient** - list of email recipients (defaults to commit email)
Same email configuration:
```yaml
notify:
email:
from: noreply@github.com
host: smtp.mailgun.org
port: 587
username: octocat
password: 12345
recipients:
- octocat@github.com
```

9
Dockerfile Normal file
View file

@ -0,0 +1,9 @@
# Docker image for Drone's email notification plugin
#
# CGO_ENABLED=0 go build -a -tags netgo
# docker build --rm=true -t plugins/drone-email .
FROM gliderlabs/alpine:3.1
RUN apk-install ca-certificates
ADD drone-email /bin/
ENTRYPOINT ["/bin/drone-email"]

41
README.md Normal file
View file

@ -0,0 +1,41 @@
# drone-email
Drone plugin for sending email notifications.
## Overview
This plugin is responsible for sending build notifications via email:
```
./drone-email <<EOF
{
"repo" : {
"owner": "foo",
"name": "bar",
"full_name": "foo/bar"
},
"system": {
"link_url": "http://drone.mycompany.com"
},
"build" : {
"number": 22,
"status": "success",
"started_at": 1421029603,
"finished_at": 1421029813,
"commit": "64908ed2414b771554fda6508dd56a0c43766831",
"branch": "master",
"message": "Update the Readme",
"author": "johnsmith",
"author_email": "john.smith@gmail.com"
},
"vargs": {
"from": "noreply@foo.com",
"host": "smtp.mailgun.org",
"port": 587,
"username": "",
"password": "",
"recipients": ["octocat@github.com"]
}
}
EOF
```

32
main.go
View file

@ -1,6 +1,7 @@
package main
import (
"fmt"
"os"
"github.com/drone/drone-go/drone"
@ -11,7 +12,7 @@ type Email struct {
Recipients []string `json:"recipients"`
Host string `json:"host"`
Port string `json:"port"`
Port int `json:"port"`
From string `json:"from"`
Username string `json:"username"`
Password string `json:"password"`
@ -34,14 +35,33 @@ func main() {
plugin.Param("build", &build)
plugin.Param("repo", &repo)
plugin.Param("vargs", &email)
err := plugin.Parse()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err := Send(&Context{
Email: email,
Build: build,
Repo: repo,
// default to the commit email address
// if no email recipient list is provided
if len(email.Recipients) == 0 {
email.Recipients = []string{
build.Email,
}
}
// default smtp port
if email.Port == 0 {
email.Port = 587
}
err = Send(&Context{
Email: email,
Build: build,
Repo: repo,
System: system,
})
if err != nil {
println(err.Error())
fmt.Println(err)
os.Exit(1)
}
}

View file

@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/smtp"
"strconv"
"strings"
"github.com/drone/drone-go/drone"
@ -80,7 +81,7 @@ func send(subject, body string, c *Context) error {
}
var auth smtp.Auth
var addr = net.JoinHostPort(c.Email.Host, c.Email.Port)
var addr = net.JoinHostPort(c.Email.Host, strconv.Itoa(c.Email.Port))
// setup the authentication to the smtp server
// if the username and password are provided.