mirror of
https://github.com/harness-community/drone-email.git
synced 2026-06-13 10:32:05 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cdc129e0b | |||
| 00423fe0b9 | |||
| e56738efed |
@@ -1,11 +1,11 @@
|
||||
FROM golang:1.22.1-alpine as builder
|
||||
FROM golang:1.22.7-alpine as builder
|
||||
|
||||
WORKDIR /go/src/drone-email
|
||||
COPY . .
|
||||
|
||||
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build
|
||||
|
||||
FROM alpine:3.14
|
||||
FROM alpine:3.20
|
||||
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
FROM golang:1.22.1-alpine as builder
|
||||
FROM golang:1.22.7-alpine as builder
|
||||
|
||||
WORKDIR /go/src/drone-email
|
||||
COPY . .
|
||||
|
||||
RUN GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 go build
|
||||
|
||||
FROM alpine:3.14
|
||||
FROM alpine:3.20
|
||||
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module github.com/drone-plugins/drone-email
|
||||
|
||||
go 1.22.1
|
||||
go 1.22.7
|
||||
|
||||
@@ -118,31 +118,46 @@ type (
|
||||
func (p Plugin) Exec() error {
|
||||
var dialer *gomail.Dialer
|
||||
|
||||
if !p.Config.RecipientsOnly {
|
||||
exists := false
|
||||
for _, recipient := range p.Config.Recipients {
|
||||
if recipient == p.Commit.Author.Email {
|
||||
exists = true
|
||||
}
|
||||
}
|
||||
recipientsMap := make(map[string]struct{})
|
||||
|
||||
if !exists {
|
||||
p.Config.Recipients = append(p.Config.Recipients, p.Commit.Author.Email)
|
||||
// Add recipients from the config
|
||||
for _, recipient := range p.Config.Recipients {
|
||||
if recipient == "" {
|
||||
log.Warnf("Skipping empty recipient from config")
|
||||
continue
|
||||
}
|
||||
recipientsMap[recipient] = struct{}{}
|
||||
}
|
||||
|
||||
// Add commit author's email if not already present and RecipientsOnly is false
|
||||
if !p.Config.RecipientsOnly {
|
||||
if p.Commit.Author.Email != "" {
|
||||
recipientsMap[p.Commit.Author.Email] = struct{}{}
|
||||
} else {
|
||||
log.Warn("Commit author email is empty")
|
||||
}
|
||||
}
|
||||
|
||||
// Add recipients from the recipients file
|
||||
if p.Config.RecipientsFile != "" {
|
||||
f, err := os.Open(p.Config.RecipientsFile)
|
||||
if err == nil {
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
p.Config.Recipients = append(p.Config.Recipients, scanner.Text())
|
||||
recipient := scanner.Text()
|
||||
if recipient == "" {
|
||||
log.Warnf("Skipping empty recipient from file %s", p.Config.RecipientsFile)
|
||||
continue
|
||||
}
|
||||
recipientsMap[recipient] = struct{}{}
|
||||
}
|
||||
} else {
|
||||
log.Errorf("Could not open RecipientsFile %s: %v", p.Config.RecipientsFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("Recipients: %v", recipientsMap)
|
||||
|
||||
if p.Config.Username == "" && p.Config.Password == "" {
|
||||
dialer = &gomail.Dialer{Host: p.Config.Host, Port: p.Config.Port}
|
||||
} else {
|
||||
@@ -216,10 +231,7 @@ func (p Plugin) Exec() error {
|
||||
|
||||
// Send emails
|
||||
message := gomail.NewMessage()
|
||||
for _, recipient := range p.Config.Recipients {
|
||||
if len(recipient) == 0 {
|
||||
continue
|
||||
}
|
||||
for recipient := range recipientsMap {
|
||||
message.SetAddressHeader("From", p.Config.FromAddress, p.Config.FromName)
|
||||
message.SetAddressHeader("To", recipient, "")
|
||||
message.SetHeader("Subject", subject)
|
||||
|
||||
Reference in New Issue
Block a user