Skip to content

Commit

Permalink
chore: Fixing httputils and mailer usage
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 15, 2021
1 parent b1c1ad6 commit c4fb2ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ func (a App) sendNotification(ctx context.Context, ketchupToNotify map[model.Use
"releases": releases,
}

mailRequest := mailerModel.NewMailRequest().Template("ketchup").From("[email protected]").As("Ketchup").To(user.Email).Data(payload)
mr := mailerModel.NewMailRequest().Template("ketchup").From("[email protected]").As("Ketchup").To(user.Email).Data(payload)
subject := fmt.Sprintf("Ketchup - %d new release", len(releases))
if len(releases) > 1 {
subject += "s"
}
mailRequest.WithSubject(subject)
mr = mr.WithSubject(subject)

if err := a.mailerApp.Send(ctx, *mailRequest); err != nil {
if err := a.mailerApp.Send(ctx, mr); err != nil {
return fmt.Errorf("unable to send email to %s: %s", user.Email, err)
}
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/provider/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/flags"
"github.com/ViBiOh/httputils/v4/pkg/httpjson"
"github.com/ViBiOh/httputils/v4/pkg/logger"
"github.com/ViBiOh/httputils/v4/pkg/redis"
"github.com/ViBiOh/httputils/v4/pkg/request"
"github.com/ViBiOh/ketchup/pkg/model"
"github.com/ViBiOh/ketchup/pkg/semver"
Expand All @@ -31,6 +30,11 @@ var (
}
)

type redis interface {
Ping() error
Exclusive(context.Context, string, time.Duration, func(context.Context) error) error
}

// Tag describes a GitHub Tag
type Tag struct {
Name string `json:"name"`
Expand Down Expand Up @@ -58,7 +62,7 @@ type Config struct {
}

type app struct {
redisApp redis.App
redisApp redis
token string
}

Expand All @@ -70,14 +74,14 @@ func Flags(fs *flag.FlagSet, prefix string) Config {
}

// New creates new App from Config
func New(config Config, redisApp redis.App) App {
func New(config Config, redisApp redis) App {
return app{
token: strings.TrimSpace(*config.token),
redisApp: redisApp,
}
}

func (a app) newClient() *request.Request {
func (a app) newClient() request.Request {
return request.New().Header("Authorization", fmt.Sprintf("token %s", a.token)).WithClient(httpClient)
}

Expand Down

0 comments on commit c4fb2ca

Please sign in to comment.