mirror of
https://github.com/harness-community/drone-email.git
synced 2026-06-16 14:50:28 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 00423fe0b9 | |||
| e56738efed | |||
| f2a9f41fff | |||
| f3a970f6ac | |||
| b4c2e8afc0 | |||
| 8a78136b01 | |||
| c5c6593e14 |
@@ -0,0 +1,8 @@
|
|||||||
|
export GOPATH=""
|
||||||
|
# disable cgo
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# windows
|
||||||
|
GOOS=windows go build -o release/windows/amd64/drone-email.exe
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.14-alpine as builder
|
FROM golang:1.22.1-alpine as builder
|
||||||
|
|
||||||
WORKDIR /go/src/drone-email
|
WORKDIR /go/src/drone-email
|
||||||
COPY . .
|
COPY . .
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.15-alpine as builder
|
FROM golang:1.22.1-alpine as builder
|
||||||
|
|
||||||
WORKDIR /go/src/drone-email
|
WORKDIR /go/src/drone-email
|
||||||
COPY . .
|
COPY . .
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
FROM plugins/base:windows-ltsc2022-amd64
|
||||||
|
|
||||||
|
USER ContainerAdministrator
|
||||||
|
|
||||||
|
ENV GODEBUG=netdns=go
|
||||||
|
|
||||||
|
ADD release/windows/amd64/drone-email.exe C:/drone-email.exe
|
||||||
|
|
||||||
|
ENTRYPOINT ["C:\\drone-email.exe"]
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
image: plugins/email:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||||
|
{{#if build.tags}}
|
||||||
|
tags:
|
||||||
|
{{#each build.tags}}
|
||||||
|
- {{this}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
manifests:
|
||||||
|
-
|
||||||
|
image: plugins/email:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||||
|
platform:
|
||||||
|
architecture: amd64
|
||||||
|
os: linux
|
||||||
|
-
|
||||||
|
image: plugins/email:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
||||||
|
platform:
|
||||||
|
variant: v8
|
||||||
|
architecture: arm64
|
||||||
|
os: linux
|
||||||
|
-
|
||||||
|
image: plugins/email:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-amd64
|
||||||
|
platform:
|
||||||
|
architecture: amd64
|
||||||
|
os: windows
|
||||||
|
version: ltsc2022
|
||||||
|
|
||||||
@@ -118,31 +118,46 @@ type (
|
|||||||
func (p Plugin) Exec() error {
|
func (p Plugin) Exec() error {
|
||||||
var dialer *gomail.Dialer
|
var dialer *gomail.Dialer
|
||||||
|
|
||||||
if !p.Config.RecipientsOnly {
|
recipientsMap := make(map[string]struct{})
|
||||||
exists := false
|
|
||||||
for _, recipient := range p.Config.Recipients {
|
|
||||||
if recipient == p.Commit.Author.Email {
|
|
||||||
exists = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !exists {
|
// Add recipients from the config
|
||||||
p.Config.Recipients = append(p.Config.Recipients, p.Commit.Author.Email)
|
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 != "" {
|
if p.Config.RecipientsFile != "" {
|
||||||
f, err := os.Open(p.Config.RecipientsFile)
|
f, err := os.Open(p.Config.RecipientsFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
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 {
|
} else {
|
||||||
log.Errorf("Could not open RecipientsFile %s: %v", p.Config.RecipientsFile, err)
|
log.Errorf("Could not open RecipientsFile %s: %v", p.Config.RecipientsFile, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("Recipients: %v", recipientsMap)
|
||||||
|
|
||||||
if p.Config.Username == "" && p.Config.Password == "" {
|
if p.Config.Username == "" && p.Config.Password == "" {
|
||||||
dialer = &gomail.Dialer{Host: p.Config.Host, Port: p.Config.Port}
|
dialer = &gomail.Dialer{Host: p.Config.Host, Port: p.Config.Port}
|
||||||
} else {
|
} else {
|
||||||
@@ -216,10 +231,7 @@ func (p Plugin) Exec() error {
|
|||||||
|
|
||||||
// Send emails
|
// Send emails
|
||||||
message := gomail.NewMessage()
|
message := gomail.NewMessage()
|
||||||
for _, recipient := range p.Config.Recipients {
|
for recipient := range recipientsMap {
|
||||||
if len(recipient) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
message.SetAddressHeader("From", p.Config.FromAddress, p.Config.FromName)
|
message.SetAddressHeader("From", p.Config.FromAddress, p.Config.FromName)
|
||||||
message.SetAddressHeader("To", recipient, "")
|
message.SetAddressHeader("To", recipient, "")
|
||||||
message.SetHeader("Subject", subject)
|
message.SetHeader("Subject", subject)
|
||||||
|
|||||||
Reference in New Issue
Block a user