From 8ae187829b64846c61165a750e52f7bc95f40222 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 13 Oct 2023 10:50:15 +0900 Subject: [PATCH 1/3] set the sender email address and the name from the committer if they are blank --- plugin.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index 03c0079..96da4ce 100644 --- a/plugin.go +++ b/plugin.go @@ -220,7 +220,21 @@ func (p Plugin) Exec() error { if len(recipient) == 0 { continue } - message.SetAddressHeader("From", p.Config.FromAddress, p.Config.FromName) + + from_address := p.Config.FromAddress + from_name := p.Config.FromName + if from_address == "" { + from_address = p.Commit.Author.Email + if from_address == "" { + from_address = recipient + } + + if from_name == "" { // only if from_address is blank as well + from_name = p.Commit.Author.Name + } + } + + message.SetAddressHeader("From", from_address, from_name) message.SetAddressHeader("To", recipient, "") message.SetHeader("Subject", subject) message.AddAlternative("text/plain", plainBody) From 186fb78911b76c3fc20cd884281ffc86e153a430 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 13 Oct 2023 11:20:10 +0900 Subject: [PATCH 2/3] added the verbose/PLUGIN_VERBOSE option to emit some informational text --- main.go | 6 ++++++ plugin.go | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/main.go b/main.go index 9608eaa..7706e38 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,11 @@ func main() { app.Version = "2.0.2" app.Flags = []cli.Flag{ // Plugin environment + cli.BoolFlag{ + Name: "verbose", + Usage: "set verbosity", + EnvVar: "PLUGIN_VERBOSE", + }, cli.StringFlag{ Name: "from", Usage: "from address", @@ -405,6 +410,7 @@ func run(c *cli.Context) error { PullRequest: c.Int("pullRequest"), DeployTo: c.String("deployTo"), Config: Config{ + Verbose: c.Bool("verbose"), FromAddress: fromAddress, FromName: c.String("from.name"), Host: c.String("host"), diff --git a/plugin.go b/plugin.go index 96da4ce..3b7ecf3 100644 --- a/plugin.go +++ b/plugin.go @@ -81,6 +81,7 @@ type ( } Config struct { + Verbose bool FromAddress string FromName string Host string @@ -143,6 +144,10 @@ func (p Plugin) Exec() error { } } + if p.Config.Verbose { + log.Infof ("Host [%s], Port [%d], Username [%s] Password[%s]", p.Config.Host, p.Config.Port, p.Config.Username, p.Config.Password) + } + if p.Config.Username == "" && p.Config.Password == "" { dialer = &gomail.Dialer{Host: p.Config.Host, Port: p.Config.Port} } else { @@ -234,6 +239,10 @@ func (p Plugin) Exec() error { } } + if p.Config.Verbose { + log.Infof ("Recipient [%s] From [%s <%s>]", recipient, from_name, from_address) + } + message.SetAddressHeader("From", from_address, from_name) message.SetAddressHeader("To", recipient, "") message.SetHeader("Subject", subject) From 0b64cbd699d8d585acd20cf1c9958a08a18eb924 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 13 Oct 2023 13:29:52 +0900 Subject: [PATCH 3/3] removed Password from the debug output --- plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index 3b7ecf3..c54db3a 100644 --- a/plugin.go +++ b/plugin.go @@ -145,7 +145,7 @@ func (p Plugin) Exec() error { } if p.Config.Verbose { - log.Infof ("Host [%s], Port [%d], Username [%s] Password[%s]", p.Config.Host, p.Config.Port, p.Config.Username, p.Config.Password) + log.Infof ("Host [%s], Port [%d], Username [%s]", p.Config.Host, p.Config.Port, p.Config.Username); } if p.Config.Username == "" && p.Config.Password == "" {