diff --git a/pkg/build/script/deployment/appfog.go b/pkg/build/script/deployment/appfog.go deleted file mode 100644 index 367fd2709..000000000 --- a/pkg/build/script/deployment/appfog.go +++ /dev/null @@ -1,12 +0,0 @@ -package deployment - -import ( - "github.com/drone/drone/pkg/build/buildfile" -) - -type AppFog struct { -} - -func (a *AppFog) Write(f *buildfile.Buildfile) { - -} diff --git a/pkg/build/script/deployment/cloudcontrol.go b/pkg/build/script/deployment/cloudcontrol.go deleted file mode 100644 index 881410617..000000000 --- a/pkg/build/script/deployment/cloudcontrol.go +++ /dev/null @@ -1,12 +0,0 @@ -package deployment - -import ( - "github.com/drone/drone/pkg/build/buildfile" -) - -type CloudControl struct { -} - -func (c *CloudControl) Write(f *buildfile.Buildfile) { - -} diff --git a/pkg/build/script/deployment/cloudfoundry.go b/pkg/build/script/deployment/cloudfoundry.go deleted file mode 100644 index 1f4620818..000000000 --- a/pkg/build/script/deployment/cloudfoundry.go +++ /dev/null @@ -1,12 +0,0 @@ -package deployment - -import ( - "github.com/drone/drone/pkg/build/buildfile" -) - -type CloudFoundry struct { -} - -func (c *CloudFoundry) Write(f *buildfile.Buildfile) { - -} diff --git a/pkg/build/script/deployment/deployment.go b/pkg/build/script/deployment/deployment.go deleted file mode 100644 index eb26dbc2b..000000000 --- a/pkg/build/script/deployment/deployment.go +++ /dev/null @@ -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) - } -} diff --git a/pkg/build/script/deployment/engineyard.go b/pkg/build/script/deployment/engineyard.go deleted file mode 100644 index 8aefa93d1..000000000 --- a/pkg/build/script/deployment/engineyard.go +++ /dev/null @@ -1,12 +0,0 @@ -package deployment - -import ( - "github.com/drone/drone/pkg/build/buildfile" -) - -type EngineYard struct { -} - -func (e *EngineYard) Write(f *buildfile.Buildfile) { - -} diff --git a/pkg/build/script/deployment/git.go b/pkg/build/script/deployment/git.go deleted file mode 100644 index 3c65985a3..000000000 --- a/pkg/build/script/deployment/git.go +++ /dev/null @@ -1 +0,0 @@ -package deployment diff --git a/pkg/build/script/deployment/heroku.go b/pkg/build/script/deployment/heroku.go deleted file mode 100644 index 60dd2e371..000000000 --- a/pkg/build/script/deployment/heroku.go +++ /dev/null @@ -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")) - } -} diff --git a/pkg/build/script/deployment/nodejitsu.go b/pkg/build/script/deployment/nodejitsu.go deleted file mode 100644 index 6a0af8a3a..000000000 --- a/pkg/build/script/deployment/nodejitsu.go +++ /dev/null @@ -1,12 +0,0 @@ -package deployment - -import ( - "github.com/drone/drone/pkg/build/buildfile" -) - -type Nodejitsu struct { -} - -func (n *Nodejitsu) Write(f *buildfile.Buildfile) { - -} diff --git a/pkg/build/script/deployment/openshift.go b/pkg/build/script/deployment/openshift.go deleted file mode 100644 index dc325c742..000000000 --- a/pkg/build/script/deployment/openshift.go +++ /dev/null @@ -1,12 +0,0 @@ -package deployment - -import ( - "github.com/drone/drone/pkg/build/buildfile" -) - -type Openshift struct { -} - -func (o *Openshift) Write(f *buildfile.Buildfile) { - -} diff --git a/pkg/build/script/deployment/ssh.go b/pkg/build/script/deployment/ssh.go deleted file mode 100644 index 3c65985a3..000000000 --- a/pkg/build/script/deployment/ssh.go +++ /dev/null @@ -1 +0,0 @@ -package deployment diff --git a/pkg/build/script/notification/email.go b/pkg/build/script/notification/email.go deleted file mode 100644 index cdb39932b..000000000 --- a/pkg/build/script/notification/email.go +++ /dev/null @@ -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` diff --git a/pkg/build/script/notification/hipchat.go b/pkg/build/script/notification/hipchat.go deleted file mode 100644 index 5e8def651..000000000 --- a/pkg/build/script/notification/hipchat.go +++ /dev/null @@ -1,64 +0,0 @@ -package notification - -import ( - "fmt" - - "github.com/andybons/hipchat" -) - -const ( - startedMessage = "Building %s, commit %s, author %s" - successMessage = "Success %s, commit %s, author %s" - failureMessage = "Failed %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) -} diff --git a/pkg/build/script/notification/irc.go b/pkg/build/script/notification/irc.go deleted file mode 100644 index 4306c87f1..000000000 --- a/pkg/build/script/notification/irc.go +++ /dev/null @@ -1 +0,0 @@ -package notification diff --git a/pkg/build/script/notification/notification.go b/pkg/build/script/notification/notification.go deleted file mode 100644 index bea1b6e71..000000000 --- a/pkg/build/script/notification/notification.go +++ /dev/null @@ -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 -} diff --git a/pkg/build/script/notification/webhook.go b/pkg/build/script/notification/webhook.go deleted file mode 100644 index 649fbbe2c..000000000 --- a/pkg/build/script/notification/webhook.go +++ /dev/null @@ -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() -} diff --git a/pkg/build/script/notification/zapier.go b/pkg/build/script/notification/zapier.go deleted file mode 100644 index 4306c87f1..000000000 --- a/pkg/build/script/notification/zapier.go +++ /dev/null @@ -1 +0,0 @@ -package notification diff --git a/pkg/build/script/publish/bintray.go b/pkg/build/script/publish/bintray.go deleted file mode 100644 index 30b1a5b2a..000000000 --- a/pkg/build/script/publish/bintray.go +++ /dev/null @@ -1 +0,0 @@ -package publish diff --git a/pkg/build/script/publish/dropbox.go b/pkg/build/script/publish/dropbox.go deleted file mode 100644 index 30b1a5b2a..000000000 --- a/pkg/build/script/publish/dropbox.go +++ /dev/null @@ -1 +0,0 @@ -package publish diff --git a/pkg/build/script/publish/gems.go b/pkg/build/script/publish/gems.go deleted file mode 100644 index 30b1a5b2a..000000000 --- a/pkg/build/script/publish/gems.go +++ /dev/null @@ -1 +0,0 @@ -package publish diff --git a/pkg/build/script/publish/maven.go b/pkg/build/script/publish/maven.go deleted file mode 100644 index 30b1a5b2a..000000000 --- a/pkg/build/script/publish/maven.go +++ /dev/null @@ -1 +0,0 @@ -package publish diff --git a/pkg/build/script/publish/npm.go b/pkg/build/script/publish/npm.go deleted file mode 100644 index 30b1a5b2a..000000000 --- a/pkg/build/script/publish/npm.go +++ /dev/null @@ -1 +0,0 @@ -package publish diff --git a/pkg/build/script/publish/pub.go b/pkg/build/script/publish/pub.go deleted file mode 100644 index 30b1a5b2a..000000000 --- a/pkg/build/script/publish/pub.go +++ /dev/null @@ -1 +0,0 @@ -package publish diff --git a/pkg/build/script/publish/publish.go b/pkg/build/script/publish/publish.go deleted file mode 100644 index d31088f29..000000000 --- a/pkg/build/script/publish/publish.go +++ /dev/null @@ -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) - } -} diff --git a/pkg/build/script/publish/pypi.go b/pkg/build/script/publish/pypi.go deleted file mode 100644 index d46cd60ca..000000000 --- a/pkg/build/script/publish/pypi.go +++ /dev/null @@ -1,2 +0,0 @@ -package publish - diff --git a/pkg/build/script/publish/s3.go b/pkg/build/script/publish/s3.go deleted file mode 100644 index 029b0b5fc..000000000 --- a/pkg/build/script/publish/s3.go +++ /dev/null @@ -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)) - } -} diff --git a/pkg/build/script/report/README.md b/pkg/build/script/report/README.md deleted file mode 100644 index 03260a5b1..000000000 --- a/pkg/build/script/report/README.md +++ /dev/null @@ -1,5 +0,0 @@ -cobertura.go -coveralls.go -gocov.go -junit.go -phpunit.go \ No newline at end of file diff --git a/pkg/build/script/script.go b/pkg/build/script/script.go index 72af02a0f..afa8a922d 100644 --- a/pkg/build/script/script.go +++ b/pkg/build/script/script.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 diff --git a/pkg/plugin/notify/email.go b/pkg/plugin/notify/email.go index ed7b84759..3699a7c2a 100644 --- a/pkg/plugin/notify/email.go +++ b/pkg/plugin/notify/email.go @@ -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` diff --git a/pkg/plugin/notify/notification.go b/pkg/plugin/notify/notification.go index 0b80ae4d8..a4c6feabf 100644 --- a/pkg/plugin/notify/notification.go +++ b/pkg/plugin/notify/notification.go @@ -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 { diff --git a/pkg/queue/queue.go b/pkg/queue/queue.go index ae462ecbe..1677c3669 100644 --- a/pkg/queue/queue.go +++ b/pkg/queue/queue.go @@ -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