mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 10:07:21 +02:00
removed duplicate /deploy /notify /publish directories in /pkg/build/script
This commit is contained in:
parent
0c36b42f69
commit
a26b9c1658
@ -1,12 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type AppFog struct {
|
||||
}
|
||||
|
||||
func (a *AppFog) Write(f *buildfile.Buildfile) {
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type CloudControl struct {
|
||||
}
|
||||
|
||||
func (c *CloudControl) Write(f *buildfile.Buildfile) {
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type CloudFoundry struct {
|
||||
}
|
||||
|
||||
func (c *CloudFoundry) Write(f *buildfile.Buildfile) {
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
// Deploy stores the configuration details
|
||||
// for deploying build artifacts when
|
||||
// a Build has succeeded
|
||||
type Deploy struct {
|
||||
AppFog *AppFog `yaml:"appfog,omitempty"`
|
||||
CloudControl *CloudControl `yaml:"cloudcontrol,omitempty"`
|
||||
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
|
||||
EngineYard *EngineYard `yaml:"engineyard,omitempty"`
|
||||
Heroku *Heroku `yaml:"heroku,omitempty"`
|
||||
Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"`
|
||||
Openshift *Openshift `yaml:"openshift,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Deploy) Write(f *buildfile.Buildfile) {
|
||||
if d.AppFog != nil {
|
||||
d.AppFog.Write(f)
|
||||
}
|
||||
if d.CloudControl != nil {
|
||||
d.CloudControl.Write(f)
|
||||
}
|
||||
if d.CloudFoundry != nil {
|
||||
d.CloudFoundry.Write(f)
|
||||
}
|
||||
if d.EngineYard != nil {
|
||||
d.EngineYard.Write(f)
|
||||
}
|
||||
if d.Heroku != nil {
|
||||
d.Heroku.Write(f)
|
||||
}
|
||||
if d.Nodejitsu != nil {
|
||||
d.Nodejitsu.Write(f)
|
||||
}
|
||||
if d.Openshift != nil {
|
||||
d.Openshift.Write(f)
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type EngineYard struct {
|
||||
}
|
||||
|
||||
func (e *EngineYard) Write(f *buildfile.Buildfile) {
|
||||
|
||||
}
|
@ -1 +0,0 @@
|
||||
package deployment
|
@ -1,38 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type Heroku struct {
|
||||
App string `yaml:"app,omitempty"`
|
||||
Force bool `yaml:"force,omitempty"`
|
||||
Branch string `yaml:"branch,omitempty"`
|
||||
}
|
||||
|
||||
func (h *Heroku) Write(f *buildfile.Buildfile) {
|
||||
// get the current commit hash
|
||||
f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)")
|
||||
|
||||
// set the git user and email based on the individual
|
||||
// that made the commit.
|
||||
f.WriteCmdSilent("git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')")
|
||||
f.WriteCmdSilent("git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')")
|
||||
|
||||
// add heroku as a git remote
|
||||
f.WriteCmd(fmt.Sprintf("git remote add heroku git@heroku.com:%s.git", h.App))
|
||||
|
||||
switch h.Force {
|
||||
case true:
|
||||
// this is useful when the there are artifacts generated
|
||||
// by the build script, such as less files converted to css,
|
||||
// that need to be deployed to Heroku.
|
||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||
f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'"))
|
||||
f.WriteCmd(fmt.Sprintf("git push heroku $COMMIT:master --force"))
|
||||
case false:
|
||||
// otherwise we just do a standard git push
|
||||
f.WriteCmd(fmt.Sprintf("git push heroku $COMMIT:master"))
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type Nodejitsu struct {
|
||||
}
|
||||
|
||||
func (n *Nodejitsu) Write(f *buildfile.Buildfile) {
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type Openshift struct {
|
||||
}
|
||||
|
||||
func (o *Openshift) Write(f *buildfile.Buildfile) {
|
||||
|
||||
}
|
@ -1 +0,0 @@
|
||||
package deployment
|
@ -1,85 +0,0 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
)
|
||||
|
||||
type Email struct {
|
||||
Recipients []string `yaml:"recipients,omitempty"`
|
||||
Success string `yaml:"on_success"`
|
||||
Failure string `yaml:"on_failure"`
|
||||
|
||||
host string // smtp host address
|
||||
port string // smtp host port
|
||||
user string // smtp username for authentication
|
||||
pass string // smtp password for authentication
|
||||
from string // smtp email address. send from this address
|
||||
}
|
||||
|
||||
// SetServer is a function that will set the SMTP
|
||||
// server location and credentials
|
||||
func (e *Email) SetServer(host, port, user, pass, from string) {
|
||||
e.host = host
|
||||
e.port = port
|
||||
e.user = user
|
||||
e.pass = pass
|
||||
e.from = from
|
||||
}
|
||||
|
||||
// Send will send an email, either success or failure,
|
||||
// based on the Commit Status.
|
||||
func (e *Email) Send(context *Context) error {
|
||||
switch {
|
||||
case context.Commit.Status == "Success" && e.Success != "never":
|
||||
return e.sendSuccess(context)
|
||||
case context.Commit.Status == "Failure" && e.Failure != "never":
|
||||
return e.sendFailure(context)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// sendFailure sends email notifications to the list of
|
||||
// recipients indicating the build failed.
|
||||
func (e *Email) sendFailure(context *Context) error {
|
||||
// loop through and email recipients
|
||||
/*for _, email := range e.Recipients {
|
||||
if err := mail.SendFailure(context.Repo.Slug, email, context); err != nil {
|
||||
return err
|
||||
}
|
||||
}*/
|
||||
return nil
|
||||
}
|
||||
|
||||
// sendSuccess sends email notifications to the list of
|
||||
// recipients indicating the build was a success.
|
||||
func (e *Email) sendSuccess(context *Context) error {
|
||||
// loop through and email recipients
|
||||
/*for _, email := range e.Recipients {
|
||||
if err := mail.SendSuccess(context.Repo.Slug, email, context); err != nil {
|
||||
return err
|
||||
}
|
||||
}*/
|
||||
return nil
|
||||
}
|
||||
|
||||
// send is a simple helper function to format and
|
||||
// send an email message.
|
||||
func (e *Email) send(to, subject, body string) error {
|
||||
// Format the raw email message body
|
||||
raw := fmt.Sprintf(emailTemplate, e.from, to, subject, body)
|
||||
auth := smtp.PlainAuth("", e.user, e.pass, e.host)
|
||||
addr := fmt.Sprintf("%s:%s", e.host, e.port)
|
||||
|
||||
return smtp.SendMail(addr, auth, e.from, []string{to}, []byte(raw))
|
||||
}
|
||||
|
||||
// text-template used to generate a raw Email message
|
||||
var emailTemplate = `From: %s
|
||||
To: %s
|
||||
Subject: %s
|
||||
MIME-version: 1.0
|
||||
Content-Type: text/html; charset="UTF-8"
|
||||
|
||||
%s`
|
@ -1,64 +0,0 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/andybons/hipchat"
|
||||
)
|
||||
|
||||
const (
|
||||
startedMessage = "Building %s, commit %s, author %s"
|
||||
successMessage = "<b>Success</b> %s, commit %s, author %s"
|
||||
failureMessage = "<b>Failed</b> %s, commit %s, author %s"
|
||||
)
|
||||
|
||||
type Hipchat struct {
|
||||
Room string `yaml:"room,omitempty"`
|
||||
Token string `yaml:"token,omitempty"`
|
||||
Started bool `yaml:"on_started,omitempty"`
|
||||
Success bool `yaml:"on_success,omitempty"`
|
||||
Failure bool `yaml:"on_failure,omitempty"`
|
||||
}
|
||||
|
||||
func (h *Hipchat) Send(context *Context) error {
|
||||
switch {
|
||||
case context.Commit.Status == "Started" && h.Started:
|
||||
return h.sendStarted(context)
|
||||
case context.Commit.Status == "Success" && h.Success:
|
||||
return h.sendSuccess(context)
|
||||
case context.Commit.Status == "Failure" && h.Failure:
|
||||
return h.sendFailure(context)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Hipchat) sendStarted(context *Context) error {
|
||||
msg := fmt.Sprintf(startedMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
|
||||
return h.send(hipchat.ColorYellow, hipchat.FormatHTML, msg)
|
||||
}
|
||||
|
||||
func (h *Hipchat) sendFailure(context *Context) error {
|
||||
msg := fmt.Sprintf(failureMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
|
||||
return h.send(hipchat.ColorRed, hipchat.FormatHTML, msg)
|
||||
}
|
||||
|
||||
func (h *Hipchat) sendSuccess(context *Context) error {
|
||||
msg := fmt.Sprintf(successMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
|
||||
return h.send(hipchat.ColorGreen, hipchat.FormatHTML, msg)
|
||||
}
|
||||
|
||||
// helper function to send Hipchat requests
|
||||
func (h *Hipchat) send(color, format, message string) error {
|
||||
c := hipchat.Client{AuthToken: h.Token}
|
||||
req := hipchat.MessageRequest{
|
||||
RoomId: h.Room,
|
||||
From: "Drone",
|
||||
Message: message,
|
||||
Color: color,
|
||||
MessageFormat: format,
|
||||
Notify: true,
|
||||
}
|
||||
|
||||
return c.PostMessage(req)
|
||||
}
|
@ -1 +0,0 @@
|
||||
package notification
|
@ -1,53 +0,0 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/model"
|
||||
)
|
||||
|
||||
// Context represents the context of an
|
||||
// in-progress build request.
|
||||
type Context struct {
|
||||
// Global settings
|
||||
Host string
|
||||
|
||||
// User that owns the repository
|
||||
User *model.User
|
||||
|
||||
// Repository being built.
|
||||
Repo *model.Repo
|
||||
|
||||
// Commit being built
|
||||
Commit *model.Commit
|
||||
}
|
||||
|
||||
type Sender interface {
|
||||
Send(context *Context) error
|
||||
}
|
||||
|
||||
// Notification stores the configuration details
|
||||
// for notifying a user, or group of users,
|
||||
// when their Build has completed.
|
||||
type Notification struct {
|
||||
Email *Email `yaml:"email,omitempty"`
|
||||
Webhook *Webhook `yaml:"webhook,omitempty"`
|
||||
Hipchat *Hipchat `yaml:"hipchat,omitempty"`
|
||||
}
|
||||
|
||||
func (n *Notification) Send(context *Context) error {
|
||||
// send email notifications
|
||||
//if n.Email != nil && n.Email.Enabled {
|
||||
// n.Email.Send(context)
|
||||
//}
|
||||
|
||||
// send email notifications
|
||||
if n.Webhook != nil {
|
||||
n.Webhook.Send(context)
|
||||
}
|
||||
|
||||
// send email notifications
|
||||
if n.Hipchat != nil {
|
||||
n.Hipchat.Send(context)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone/pkg/model"
|
||||
)
|
||||
|
||||
type Webhook struct {
|
||||
URL []string `yaml:"urls,omitempty"`
|
||||
Success bool `yaml:"on_success,omitempty"`
|
||||
Failure bool `yaml:"on_failure,omitempty"`
|
||||
}
|
||||
|
||||
func (w *Webhook) Send(context *Context) error {
|
||||
switch {
|
||||
case context.Commit.Status == "Success" && w.Success:
|
||||
return w.send(context)
|
||||
case context.Commit.Status == "Failure" && w.Failure:
|
||||
return w.send(context)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// helper function to send HTTP requests
|
||||
func (w *Webhook) send(context *Context) error {
|
||||
// data will get posted in this format
|
||||
data := struct {
|
||||
Owner *model.User `json:"owner"`
|
||||
Repo *model.Repo `json:"repository"`
|
||||
Commit *model.Commit `json:"commit"`
|
||||
}{context.User, context.Repo, context.Commit}
|
||||
|
||||
// data json encoded
|
||||
payload, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// loop through and email recipients
|
||||
for _, url := range w.URL {
|
||||
go sendJson(url, payload)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// helper fuction to sent HTTP Post requests
|
||||
// with JSON data as the payload.
|
||||
func sendJson(url string, payload []byte) {
|
||||
buf := bytes.NewBuffer(payload)
|
||||
resp, err := http.Post(url, "application/json", buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
@ -1 +0,0 @@
|
||||
package notification
|
@ -1 +0,0 @@
|
||||
package publish
|
@ -1 +0,0 @@
|
||||
package publish
|
@ -1 +0,0 @@
|
||||
package publish
|
@ -1 +0,0 @@
|
||||
package publish
|
@ -1 +0,0 @@
|
||||
package publish
|
@ -1 +0,0 @@
|
||||
package publish
|
@ -1,18 +0,0 @@
|
||||
package publish
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
// Publish stores the configuration details
|
||||
// for publishing build artifacts when
|
||||
// a Build has succeeded
|
||||
type Publish struct {
|
||||
S3 *S3 `yaml:"s3,omitempty"`
|
||||
}
|
||||
|
||||
func (p *Publish) Write(f *buildfile.Buildfile) {
|
||||
if p.S3 != nil {
|
||||
p.S3.Write(f)
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
package publish
|
||||
|
@ -1,85 +0,0 @@
|
||||
package publish
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type S3 struct {
|
||||
Key string `yaml:"access_key,omitempty"`
|
||||
Secret string `yaml:"secret_key,omitempty"`
|
||||
Bucket string `yaml:"bucket,omitempty"`
|
||||
|
||||
// us-east-1
|
||||
// us-west-1
|
||||
// us-west-2
|
||||
// eu-west-1
|
||||
// ap-southeast-1
|
||||
// ap-southeast-2
|
||||
// ap-northeast-1
|
||||
// sa-east-1
|
||||
Region string `yaml:"region,omitempty"`
|
||||
|
||||
// Indicates the files ACL, which should be one
|
||||
// of the following:
|
||||
// private
|
||||
// public-read
|
||||
// public-read-write
|
||||
// authenticated-read
|
||||
// bucket-owner-read
|
||||
// bucket-owner-full-control
|
||||
Access string `yaml:"acl,omitempty"`
|
||||
|
||||
// Copies the files from the specified directory.
|
||||
// Regexp matching will apply to match multiple
|
||||
// files
|
||||
//
|
||||
// Examples:
|
||||
// /path/to/file
|
||||
// /path/to/*.txt
|
||||
// /path/to/*/*.txt
|
||||
// /path/to/**
|
||||
Source string `yaml:"source,omitempty"`
|
||||
Target string `yaml:"target,omitempty"`
|
||||
|
||||
// Recursive uploads
|
||||
Recursive bool `yaml:"recursive"`
|
||||
|
||||
Branch string `yaml:"branch,omitempty"`
|
||||
}
|
||||
|
||||
func (s *S3) Write(f *buildfile.Buildfile) {
|
||||
// install the AWS cli using PIP
|
||||
f.WriteCmdSilent("[ -f /usr/bin/sudo ] || pip install awscli 1> /dev/null 2> /dev/null")
|
||||
f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo pip install awscli 1> /dev/null 2> /dev/null")
|
||||
|
||||
f.WriteEnv("AWS_ACCESS_KEY_ID", s.Key)
|
||||
f.WriteEnv("AWS_SECRET_ACCESS_KEY", s.Secret)
|
||||
|
||||
// make sure a default region is set
|
||||
if len(s.Region) == 0 {
|
||||
s.Region = "us-east-1"
|
||||
}
|
||||
|
||||
// make sure a default access is set
|
||||
// let's be conservative and assume private
|
||||
if len(s.Access) == 0 {
|
||||
s.Access = "private"
|
||||
}
|
||||
|
||||
// if the target starts with a "/" we need
|
||||
// to remove it, otherwise we might adding
|
||||
// a 3rd slash to s3://
|
||||
if strings.HasPrefix(s.Target, "/") {
|
||||
s.Target = s.Target[1:]
|
||||
}
|
||||
|
||||
switch s.Recursive {
|
||||
case true:
|
||||
f.WriteCmd(fmt.Sprintf(`aws s3 cp %s s3://%s/%s --recursive --acl %s --region %s`, s.Source, s.Bucket, s.Target, s.Access, s.Region))
|
||||
case false:
|
||||
f.WriteCmd(fmt.Sprintf(`aws s3 cp %s s3://%s/%s --acl %s --region %s`, s.Source, s.Bucket, s.Target, s.Access, s.Region))
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
cobertura.go
|
||||
coveralls.go
|
||||
gocov.go
|
||||
junit.go
|
||||
phpunit.go
|
@ -7,9 +7,9 @@ import (
|
||||
"launchpad.net/goyaml"
|
||||
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
"github.com/drone/drone/pkg/build/script/deployment"
|
||||
"github.com/drone/drone/pkg/build/script/notification"
|
||||
"github.com/drone/drone/pkg/build/script/publish"
|
||||
"github.com/drone/drone/pkg/plugin/deploy"
|
||||
"github.com/drone/drone/pkg/plugin/notify"
|
||||
"github.com/drone/drone/pkg/plugin/publish"
|
||||
)
|
||||
|
||||
func ParseBuild(data []byte) (*Build, error) {
|
||||
@ -51,9 +51,9 @@ type Build struct {
|
||||
// linked to the build environment.
|
||||
Services []string
|
||||
|
||||
Deploy *deployment.Deploy `yaml:"deploy,omitempty"`
|
||||
Publish *publish.Publish `yaml:"publish,omitempty"`
|
||||
Notifications *notification.Notification `yaml:"notify,omitempty"`
|
||||
Deploy *deploy.Deploy `yaml:"deploy,omitempty"`
|
||||
Publish *publish.Publish `yaml:"publish,omitempty"`
|
||||
Notifications *notify.Notification `yaml:"notify,omitempty"`
|
||||
}
|
||||
|
||||
// Write adds all the steps to the build script, including
|
||||
|
@ -1,30 +1,11 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
)
|
||||
import "github.com/drone/drone/pkg/mail"
|
||||
|
||||
type Email struct {
|
||||
Recipients []string `yaml:"recipients,omitempty"`
|
||||
Success string `yaml:"on_success"`
|
||||
Failure string `yaml:"on_failure"`
|
||||
|
||||
host string // smtp host address
|
||||
port string // smtp host port
|
||||
user string // smtp username for authentication
|
||||
pass string // smtp password for authentication
|
||||
from string // smtp email address. send from this address
|
||||
}
|
||||
|
||||
// SetServer is a function that will set the SMTP
|
||||
// server location and credentials
|
||||
func (e *Email) SetServer(host, port, user, pass, from string) {
|
||||
e.host = host
|
||||
e.port = port
|
||||
e.user = user
|
||||
e.pass = pass
|
||||
e.from = from
|
||||
}
|
||||
|
||||
// Send will send an email, either success or failure,
|
||||
@ -44,11 +25,11 @@ func (e *Email) Send(context *Context) error {
|
||||
// recipients indicating the build failed.
|
||||
func (e *Email) sendFailure(context *Context) error {
|
||||
// loop through and email recipients
|
||||
/*for _, email := range e.Recipients {
|
||||
if err := mail.SendFailure(context.Repo.Slug, email, context); err != nil {
|
||||
for _, email := range e.Recipients {
|
||||
if err := mail.SendFailure(context.Repo.Name, email, context); err != nil {
|
||||
return err
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -56,30 +37,10 @@ func (e *Email) sendFailure(context *Context) error {
|
||||
// recipients indicating the build was a success.
|
||||
func (e *Email) sendSuccess(context *Context) error {
|
||||
// loop through and email recipients
|
||||
/*for _, email := range e.Recipients {
|
||||
if err := mail.SendSuccess(context.Repo.Slug, email, context); err != nil {
|
||||
for _, email := range e.Recipients {
|
||||
if err := mail.SendSuccess(context.Repo.Name, email, context); err != nil {
|
||||
return err
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// send is a simple helper function to format and
|
||||
// send an email message.
|
||||
func (e *Email) send(to, subject, body string) error {
|
||||
// Format the raw email message body
|
||||
raw := fmt.Sprintf(emailTemplate, e.from, to, subject, body)
|
||||
auth := smtp.PlainAuth("", e.user, e.pass, e.host)
|
||||
addr := fmt.Sprintf("%s:%s", e.host, e.port)
|
||||
|
||||
return smtp.SendMail(addr, auth, e.from, []string{to}, []byte(raw))
|
||||
}
|
||||
|
||||
// text-template used to generate a raw Email message
|
||||
var emailTemplate = `From: %s
|
||||
To: %s
|
||||
Subject: %s
|
||||
MIME-version: 1.0
|
||||
Content-Type: text/html; charset="UTF-8"
|
||||
|
||||
%s`
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
// in-progress build request.
|
||||
type Context struct {
|
||||
// Global settings
|
||||
Settings *model.Settings
|
||||
Host string
|
||||
|
||||
// User that owns the repository
|
||||
User *model.User
|
||||
@ -35,9 +35,9 @@ type Notification struct {
|
||||
|
||||
func (n *Notification) Send(context *Context) error {
|
||||
// send email notifications
|
||||
//if n.Email != nil && n.Email.Enabled {
|
||||
// n.Email.Send(context)
|
||||
//}
|
||||
if n.Email != nil {
|
||||
n.Email.Send(context)
|
||||
}
|
||||
|
||||
// send email notifications
|
||||
if n.Webhook != nil {
|
||||
|
@ -6,11 +6,10 @@ import (
|
||||
bldr "github.com/drone/drone/pkg/build"
|
||||
r "github.com/drone/drone/pkg/build/repo"
|
||||
"github.com/drone/drone/pkg/build/script"
|
||||
"github.com/drone/drone/pkg/build/script/notification"
|
||||
"github.com/drone/drone/pkg/channel"
|
||||
"github.com/drone/drone/pkg/database"
|
||||
"github.com/drone/drone/pkg/mail"
|
||||
. "github.com/drone/drone/pkg/model"
|
||||
"github.com/drone/drone/pkg/plugin/notify"
|
||||
"github.com/drone/go-github/github"
|
||||
"log"
|
||||
"path/filepath"
|
||||
@ -94,7 +93,7 @@ func (b *BuildTask) execute() error {
|
||||
settings, _ := database.GetSettings()
|
||||
|
||||
// notification context
|
||||
context := ¬ification.Context{
|
||||
context := ¬ify.Context{
|
||||
Repo: b.Repo,
|
||||
Commit: b.Commit,
|
||||
Host: settings.URL().String(),
|
||||
@ -184,15 +183,8 @@ func (b *BuildTask) execute() error {
|
||||
channel.SendJSON(commitslug, b.Build)
|
||||
channel.Close(consoleslug)
|
||||
|
||||
// add the smtp address to the notificaitons
|
||||
//if b.Script.Notifications != nil && b.Script.Notifications.Email != nil {
|
||||
// b.Script.Notifications.Email.SetServer(settings.SmtpServer, settings.SmtpPort,
|
||||
// settings.SmtpUsername, settings.SmtpPassword, settings.SmtpAddress)
|
||||
//}
|
||||
|
||||
// send all "finished" notifications
|
||||
if b.Script.Notifications != nil {
|
||||
b.sendEmail(context) // send email from queue, not from inside /build/script package
|
||||
b.Script.Notifications.Send(context)
|
||||
}
|
||||
|
||||
@ -235,50 +227,6 @@ func updateGitHubStatus(repo *Repo, commit *Commit) error {
|
||||
return client.Repos.CreateStatus(repo.Owner, repo.Name, status, settings.URL().String(), message, commit.Hash)
|
||||
}
|
||||
|
||||
func (t *BuildTask) sendEmail(c *notification.Context) error {
|
||||
// make sure a notifications object exists
|
||||
if t.Script.Notifications == nil && t.Script.Notifications.Email != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case t.Commit.Status == "Success" && t.Script.Notifications.Email.Success != "never":
|
||||
return t.sendSuccessEmail(c)
|
||||
case t.Commit.Status == "Failure" && t.Script.Notifications.Email.Failure != "never":
|
||||
return t.sendFailureEmail(c)
|
||||
default:
|
||||
println("sending nothing")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// sendFailure sends email notifications to the list of
|
||||
// recipients indicating the build failed.
|
||||
func (t *BuildTask) sendFailureEmail(c *notification.Context) error {
|
||||
|
||||
// loop through and email recipients
|
||||
for _, email := range t.Script.Notifications.Email.Recipients {
|
||||
if err := mail.SendFailure(t.Repo.Name, email, c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// sendSuccess sends email notifications to the list of
|
||||
// recipients indicating the build was a success.
|
||||
func (t *BuildTask) sendSuccessEmail(c *notification.Context) error {
|
||||
|
||||
// loop through and email recipients
|
||||
for _, email := range t.Script.Notifications.Email.Recipients {
|
||||
if err := mail.SendSuccess(t.Repo.Name, email, c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type bufferWrapper struct {
|
||||
buf bytes.Buffer
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user