Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
feat(github): handle releases
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Apr 13, 2021
1 parent eda2b54 commit 308e606
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ func (b *Bot) handleHook(e echo.Context) error {
zap.String("type", fmt.Sprintf("%T", event)),
)
log.Info("Processing event")
ctx := e.Request().Context()
switch event := event.(type) {
case *github.PullRequestEvent:
return b.handlePR(e.Request().Context(), event)
return b.handlePR(ctx, event)
case *github.ReleaseEvent:
return b.handleRelease(ctx, event)
default:
log.Info("No handler")
return e.String(http.StatusOK, "ok")
Expand Down Expand Up @@ -155,3 +158,24 @@ func (b *Bot) handlePR(ctx context.Context, e *github.PullRequestEvent) error {
}
return nil
}

func (b *Bot) handleRelease(ctx context.Context, e *github.ReleaseEvent) error {
if e.GetAction() != "published" {
return nil
}

p, err := b.resolver.ResolveDomain(ctx, b.notifyGroup)
if err != nil {
return xerrors.Errorf("resolve: %w", err)
}

if _, err := b.sender.To(p).StyledText(ctx,
styling.Plain("New release: "),
styling.TextURL(e.GetRelease().GetTagName(), e.GetRelease().GetHTMLURL()),
styling.Plain(fmt.Sprintf(" for %s", e.GetRepo().GetFullName())),
); err != nil {
return xerrors.Errorf("send: %w", err)
}

return nil
}

0 comments on commit 308e606

Please sign in to comment.