Support multiple attachments (#29)

* Support multiple attachments
* Support single attachment syntax in addition to multiple
* Re-add import Goland removed while optimizing imports for me.
This commit is contained in:
Michael Schlies 2019-08-23 11:06:45 -05:00 committed by Michael de Wit
parent 20edd9c7e3
commit 17393400a4
2 changed files with 11 additions and 0 deletions

View file

@ -79,6 +79,11 @@ func main() {
Usage: "attachment filename",
EnvVar: "PLUGIN_ATTACHMENT",
},
cli.StringSliceFlag{
Name: "attachments",
Usage: "attachment filename(s)",
EnvVar: "PLUGIN_ATTACHMENTS",
},
// Drone environment
// Repo
@ -375,6 +380,7 @@ func run(c *cli.Context) error {
Subject: c.String("template.subject"),
Body: c.String("template.body"),
Attachment: c.String("attachment"),
Attachments: c.StringSlice("attachments"),
},
}

View file

@ -89,6 +89,7 @@ type (
Subject string
Body string
Attachment string
Attachments []string
}
Plugin struct {
@ -203,6 +204,10 @@ func (p Plugin) Exec() error {
message.Attach(p.Config.Attachment)
}
for _, attachment := range p.Config.Attachments {
message.Attach(attachment)
}
if err := gomail.Send(closer, message); err != nil {
log.Errorf("Could not send email to %q: %v", recipient, err)
return err