Skip to content

Commit

Permalink
opt(cloudevents-server): skip notify for task runs (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: wuhuizuo <wuhuizuo@126.com>

---------

Signed-off-by: wuhuizuo <wuhuizuo@126.com>
  • Loading branch information
wuhuizuo authored Dec 8, 2023
1 parent bcd76b2 commit 3ad8efa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cloudevents-server/pkg/events/custom/tekton/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tekton
import (
"context"
"net/http"
"strings"

"github.com/PingCAP-QE/ee-apps/cloudevents-server/pkg/config"
cloudevents "github.com/cloudevents/sdk-go/v2"
Expand All @@ -21,7 +22,7 @@ func NewHandler(cfg config.Lark) (*Handler, error) {
return &Handler{
LarkClient: newLarkClient(cfg),
Receiver: cfg.Receiver,
RunDetailBaseURL: "https://do.pigncap.net/tekton",
RunDetailBaseURL: "https://do.pingcap.net/tekton",
}, nil
}

Expand Down Expand Up @@ -50,6 +51,15 @@ func (h *Handler) Handle(event cloudevents.Event) cloudevents.Result {
return cloudevents.NewHTTPResult(http.StatusBadRequest, err.Error())
}

if strings.HasPrefix(event.Type(), "dev.tekton.event.pipelinerun.") {
return h.notifyRunStatus(event)
}

log.Debug().Str("ce-type", event.Type()).Msg("skip notifing for the event type.")
return cloudevents.ResultACK
}

func (h *Handler) notifyRunStatus(event cloudevents.Event) cloudevents.Result {
createMsgReq, err := newLarkMessage(h.Receiver, event, h.RunDetailBaseURL)
if err != nil {
log.Error().Err(err).Msg("compose lark message failed")
Expand Down

0 comments on commit 3ad8efa

Please sign in to comment.