diff --git a/internal/core/messenger/eventbox/dispatcher/filters/webhookfilter.go b/internal/core/messenger/eventbox/dispatcher/filters/webhookfilter.go index d251a802463e..741e4b3395d8 100644 --- a/internal/core/messenger/eventbox/dispatcher/filters/webhookfilter.go +++ b/internal/core/messenger/eventbox/dispatcher/filters/webhookfilter.go @@ -21,6 +21,7 @@ import ( "github.com/sirupsen/logrus" + "github.com/erda-project/erda-proto-go/core/messenger/eventbox/pb" "github.com/erda-project/erda/apistructs" "github.com/erda-project/erda/internal/core/messenger/eventbox/constant" "github.com/erda-project/erda/internal/core/messenger/eventbox/dispatcher/errors" @@ -61,7 +62,7 @@ func (w *WebhookFilter) Filter(m *types.Message) *errors.DispatchError { Org: "-1", }, eventLabel.Event) - var hs []apistructs.Hook + var hs []*pb.Hook if eventLabel.OrgID != "-1" { hs = w.impl.SearchHooks(apistructs.HookLocation{ Org: eventLabel.OrgID, @@ -78,10 +79,10 @@ func (w *WebhookFilter) Filter(m *types.Message) *errors.DispatchError { urls := []string{} for _, h := range hs { - urls = append(urls, h.URL) + urls = append(urls, h.Url) } for _, h := range internalHs { - urls = append(urls, h.URL) + urls = append(urls, h.Url) } if err := replaceLabel(m, urls); err != nil { diff --git a/internal/core/messenger/eventbox/webhook/builtin.go b/internal/core/messenger/eventbox/webhook/builtin.go index 4173c2a47751..49a186068d11 100644 --- a/internal/core/messenger/eventbox/webhook/builtin.go +++ b/internal/core/messenger/eventbox/webhook/builtin.go @@ -33,9 +33,8 @@ func createIfNotExist(impl *WebHookImpl, req *CreateHookRequest) error { if err != nil { return err } - hooks := []apistructs.Hook(resp) - for i := range hooks { - if hooks[i].Name == req.Name { + for i := range resp { + if resp[i].Name == req.Name { return nil } } diff --git a/internal/core/messenger/eventbox/webhook/http.go b/internal/core/messenger/eventbox/webhook/http.go index 92b0c77874f3..53b7c6f0cd0c 100644 --- a/internal/core/messenger/eventbox/webhook/http.go +++ b/internal/core/messenger/eventbox/webhook/http.go @@ -80,20 +80,8 @@ func (w *WebHookHTTP) ListHooks(ctx context.Context, req *pb.ListHooksRequest, v return nil, err } - if err != nil { - return nil, err - } - data, err := json.Marshal(r) - if err != nil { - return nil, err - } - hooks := make([]*pb.Hook, 0) - err = json.Unmarshal(data, &hooks) - if err != nil { - return nil, err - } return &pb.ListHooksResponse{ - Data: hooks, + Data: r, }, nil } diff --git a/internal/core/messenger/eventbox/webhook/impl.go b/internal/core/messenger/eventbox/webhook/impl.go index 888a402fd616..e81933f9ed76 100644 --- a/internal/core/messenger/eventbox/webhook/impl.go +++ b/internal/core/messenger/eventbox/webhook/impl.go @@ -24,6 +24,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" + "github.com/erda-project/erda-proto-go/core/messenger/eventbox/pb" "github.com/erda-project/erda/apistructs" "github.com/erda-project/erda/internal/core/messenger/eventbox/constant" "github.com/erda-project/erda/pkg/crypto/uuid" @@ -62,31 +63,31 @@ func hookCheckOrg(h Hook, orgID string) bool { } // ListHooks 列出符合 location 的 hook 列表。 -func (w *WebHookImpl) ListHooks(location HookLocation) (ListHooksResponse, error) { +func (w *WebHookImpl) ListHooks(location HookLocation) ([]*pb.Hook, error) { dir := mkLocationDir(location) + var r []*pb.Hook ids := []string{} keys, err := w.js.ListKeys(context.Background(), dir) if err != nil { - return ListHooksResponse{}, errors.Wrap(InternalServerErr, fmt.Sprintf("list hooks fail: %v", err)) + return r, errors.Wrap(InternalServerErr, fmt.Sprintf("list hooks fail: %v", err)) } for _, k := range keys { parts := strings.Split(k, "/") if len(parts) == 0 { - return ListHooksResponse{}, + return r, errors.Wrap(InternalServerErr, fmt.Sprintf("list hooks fail: bad hook index format: %v", k)) } ids = append(ids, parts[len(parts)-1]) } - r := ListHooksResponse{} for _, id := range ids { - h := Hook{} - if err := w.js.Get(context.Background(), mkHookEtcdName(id), &h); err != nil { + h := &pb.Hook{} + if err := w.js.Get(context.Background(), mkHookEtcdName(id), h); err != nil { if err == jsonstore.NotFoundErr { // 如果有索引但没找到数据,则忽略这个webhook continue } - return ListHooksResponse{}, + return r, errors.Wrap(InternalServerErr, fmt.Sprintf("list hooks fail: get hook: %v", mkHookEtcdName(id))) } if envSatisfy(location.Env, h.Env) { @@ -256,12 +257,12 @@ func (w *WebHookImpl) DeleteHook(realOrg, id string) error { } /* search hooks which include 'event' and is 'active' */ -func (w *WebHookImpl) SearchHooks(location HookLocation, event string) []Hook { +func (w *WebHookImpl) SearchHooks(location HookLocation, event string) []*pb.Hook { hs, err := w.ListHooks(location) if err != nil { return nil } - r := []Hook{} + r := []*pb.Hook{} for _, h := range hs { for _, e := range h.Events { if e == event && h.Active {