Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Sep 2, 2022
1 parent 1ea122e commit 51bd5dd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 43 deletions.
26 changes: 13 additions & 13 deletions cmd/patch-release-notify/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"bytes"
"embed"
"errors"
"fmt"
"html/template"
"io"
Expand All @@ -29,7 +30,6 @@ import (
"strings"
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -159,26 +159,26 @@ func initLogging(*cobra.Command, []string) error {

func run(opts *options) error {
if err := opts.SetAndValidate(); err != nil {
return errors.Wrap(err, "validating schedule-path options")
return fmt.Errorf("validating schedule-path options: %w", err)
}

if opts.sendgridAPIKey == "" {
return errors.Errorf(
return fmt.Errorf(
"$%s is not set", sendgridAPIKeyEnvKey,
)
}

data, err := loadFileOrURL(opts.schedulePath)
if err != nil {
return errors.Wrap(err, "failed to read the file")
return fmt.Errorf("failed to read the file: %w", err)
}

patchSchedule := &model.PatchSchedule{}

logrus.Info("Parsing the schedule...")

if err := yaml.UnmarshalStrict(data, &patchSchedule); err != nil {
return errors.Wrap(err, "failed to decode the file")
return fmt.Errorf("failed to decode the file: %w", err)
}

output := &Template{}
Expand All @@ -188,7 +188,7 @@ func run(opts *options) error {
for _, patch := range patchSchedule.Schedules {
t, err := time.Parse(layout, patch.CherryPickDeadline)
if err != nil {
return errors.Wrap(err, "parsing schedule time")
return fmt.Errorf("parsing schedule time: %w", err)
}

currentTime := time.Now().UTC()
Expand All @@ -205,13 +205,13 @@ func run(opts *options) error {

tmpl, err := template.ParseFS(tpls, "templates/email.tmpl")
if err != nil {
return errors.Wrap(err, "parsing template")
return fmt.Errorf("parsing template: %w", err)
}

var tmplBytes bytes.Buffer
err = tmpl.Execute(&tmplBytes, output)
if err != nil {
return errors.Wrap(err, "parsing values to the template")
return fmt.Errorf("parsing values to the template: %w", err)
}

if shouldSendEmail {
Expand All @@ -225,12 +225,12 @@ func run(opts *options) error {

if opts.name != "" && opts.email != "" {
if err := m.SetSender(opts.name, opts.email); err != nil {
return errors.Wrap(err, "unable to set mail sender")
return fmt.Errorf("unable to set mail sender: %w", err)
}
} else {
logrus.Info("Retrieving default sender from sendgrid API")
if err := m.SetDefaultSender(); err != nil {
return errors.Wrap(err, "setting default sender")
return fmt.Errorf("setting default sender: %w", err)
}
}

Expand All @@ -243,14 +243,14 @@ func run(opts *options) error {
logrus.Infof("Using Google Groups as announcement target: %v", groups)

if err := m.SetGoogleGroupRecipients(groups...); err != nil {
return errors.Wrap(err, "unable to set mail recipients")
return fmt.Errorf("unable to set mail recipients: %w", err)
}

logrus.Info("Sending mail")
subject := "[Please Read] Patch Releases cherry-pick deadline"

if err := m.Send(tmplBytes.String(), subject); err != nil {
return errors.Wrap(err, "unable to send mail")
return fmt.Errorf("unable to send mail: %w", err)
}
} else {
logrus.Info("No email is needed to send")
Expand All @@ -264,7 +264,7 @@ func (o *options) SetAndValidate() error {
logrus.Info("Validating schedule-path options...")

if o.schedulePath == "" {
return errors.Errorf("need to set the schedule-path")
return errors.New("need to set the schedule-path")
}

return nil
Expand Down
58 changes: 28 additions & 30 deletions cmd/patch-release-notify/cmd/templates/email.tmpl
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
Hello Kubernetes Community!

<!DOCTYPE html>
<html>
<body>
<p>Hello Kubernetes Community!</p>
{{range .Releases}}
The cherry-pick deadline for the {{ .Release }} branches is {{ .CherryPickDeadline }} EOD PT.
<p>The cherry-pick deadline for the <b>{{ .Release }}</b> branches is <b>{{ .CherryPickDeadline }} EOD PT.</b></p>
{{end}}

Here are some quick links to search for cherry-pick PRs:

<br><p>Here are some quick links to search for cherry-pick PRs:</p>
{{range .Releases}}
- release-{{ .Release }}: https://github.com/kubernetes/kubernetes/pulls?q=is%3Apr+is%3Aopen+base%3Arelease-{{ .Release }}+label%3Ado-not-merge%2Fcherry-pick-not-approved
<p> - release-{{ .Release }}: https://github.com/kubernetes/kubernetes/pulls?q=is%3Apr+is%3Aopen+base%3Arelease-{{ .Release }}+label%3Ado-not-merge%2Fcherry-pick-not-approved</p>
{{end}}


For PRs that you intend to land for the upcoming patch sets, please
ensure they have:
- a release note in the PR description
- /sig
- /kind
- /priority
- /lgtm
- /approve
- passing tests

Details on the cherry-pick process can be found here:
https://git.k8s.io/community/contributors/devel/sig-release/cherry-picks.md

We keep general info and up-to-date timelines for patch releases here:
https://kubernetes.io/releases/patch-releases/#upcoming-monthly-releases

If you have any questions for the Release Managers, please feel free to
reach out to us at #release-management (Kubernetes Slack) or [email protected]

We wish everyone a happy and safe week!
SIG-Release Team
<br>
<p>For PRs that you intend to land for the upcoming patch sets, please
ensure they have:</p>
<p> - a release note in the PR description</p>
<p> - /sig</p>
<p> - /kind</p>
<p> - /priority</p>
<p> - /lgtm</p>
<p> - /approve</p>
<p> - passing tests</p>
<br>
<p>Details on the cherry-pick process can be found here:</p>
<p>https://git.k8s.io/community/contributors/devel/sig-release/cherry-picks.md</p>
<p>We keep general info and up-to-date timelines for patch releases here:</p>
<p>https://kubernetes.io/releases/patch-releases/#upcoming-monthly-releases</p>
<p>If you have any questions for the Release Managers, please feel free to
reach out to us at #release-management (Kubernetes Slack) or [email protected]</p><br>
<p>We wish everyone a happy and safe week!</p>
<p>SIG-Release Team</p>
</body>
</html>

0 comments on commit 51bd5dd

Please sign in to comment.