Skip to content

Commit

Permalink
feat: Adding check if mailer is enabled (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViBiOh authored Apr 11, 2020
1 parent 157b0b9 commit a812e1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ FROM scratch
ENV ZONEINFO zoneinfo.zip
EXPOSE 1080

ENV API_PORT 1080
ENV API_CSP "default-src 'self'; base-uri 'self'; script-src 'self' 'unsafe-inline' unpkg.com/swagger-ui-dist@3/; style-src 'self' 'unsafe-inline' unpkg.com/swagger-ui-dist@3/; img-src 'self' data:"
ENV API_SWAGGER_TITLE ketchup
ENV KETCHUP_PORT 1080
ENV KETCHUP_CSP "default-src 'self'; base-uri 'self'; script-src 'self' 'unsafe-inline' unpkg.com/swagger-ui-dist@3/; style-src 'self' 'unsafe-inline' unpkg.com/swagger-ui-dist@3/; img-src 'self' data:"
ENV KETCHUP_SWAGGER_TITLE ketchup

HEALTHCHECK --retries=5 CMD [ "/ketchup", "-url", "http://localhost:1080/health" ]
ENTRYPOINT [ "/ketchup" ]
Expand Down
7 changes: 5 additions & 2 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const (

// Release describes a Github Release
type Release struct {
TagName string `json:"tag_name"`
Body string `json:"body"`
Repository string `json:"repository"`
TagName string `json:"tag_name"`
Body string `json:"body"`
}

// App of package
Expand Down Expand Up @@ -71,5 +72,7 @@ func (a app) LastRelease(repository string) (Release, error) {
return release, fmt.Errorf("unable to parse release body for %s: %s", repository, err)
}

release.Repository = repository

return release, err
}
6 changes: 4 additions & 2 deletions pkg/ketchup/ketchup.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (a app) checkUpdates(_ time.Time) error {
}

if release.TagName != target.LatestVersion {
logger.Info("New version available for %s", target.Repository)
logger.Info("New version available for %s: %s", target.Repository, release.TagName)
target.LatestVersion = release.TagName

newReleases = append(newReleases, release)
Expand All @@ -92,7 +92,9 @@ func (a app) checkUpdates(_ time.Time) error {
}

if len(newReleases) > 0 {
if err := mailer.NewEmail(a.mailerApp).Template("ketchup").From("ketchup@vibioh.fr").As("Ketchup").WithSubject("Ketchup - New version available").To(a.emailTo).Data(newReleases).Send(context.Background()); err != nil {
if a.mailerApp == nil || !a.mailerApp.Enabled() {
logger.Warn("mailer is not configured")
} else if err := mailer.NewEmail(a.mailerApp).Template("ketchup").From("ketchup@vibioh.fr").As("Ketchup").WithSubject("Ketchup - New update").To(a.emailTo).Data(newReleases).Send(context.Background()); err != nil {
logger.Error("unable to send email to %s: %s", a.emailTo, err)
}
}
Expand Down

0 comments on commit a812e1e

Please sign in to comment.