From 3ad8efaf35bc203928bcb3e64d0e54413c2ae370 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Fri, 8 Dec 2023 20:01:46 +0800 Subject: [PATCH] opt(cloudevents-server): skip notify for task runs (#34) Signed-off-by: wuhuizuo --------- Signed-off-by: wuhuizuo --- .../pkg/events/custom/tekton/handler.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cloudevents-server/pkg/events/custom/tekton/handler.go b/cloudevents-server/pkg/events/custom/tekton/handler.go index 7a8c3f90..b3009f83 100644 --- a/cloudevents-server/pkg/events/custom/tekton/handler.go +++ b/cloudevents-server/pkg/events/custom/tekton/handler.go @@ -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" @@ -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 } @@ -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")