From 849203aa607b83fd1630562af839dcaba8c63e21 Mon Sep 17 00:00:00 2001 From: nghialv Date: Fri, 8 Jan 2021 18:34:05 +0900 Subject: [PATCH 1/4] Rename notification event model --- BUILD.bazel | 2 + pkg/app/piped/controller/controller.go | 2 +- pkg/app/piped/controller/planner.go | 18 +++---- pkg/app/piped/controller/scheduler.go | 18 +++---- pkg/app/piped/notifier/matcher.go | 2 +- pkg/app/piped/notifier/matcher_test.go | 54 +++++++++---------- pkg/app/piped/notifier/notifier.go | 16 +++--- pkg/app/piped/notifier/slack.go | 38 ++++++------- pkg/app/piped/notifier/webhook.go | 2 +- pkg/app/piped/trigger/deployment.go | 6 +-- pkg/app/piped/trigger/trigger.go | 2 +- pkg/model/BUILD.bazel | 11 +++- pkg/model/{event.go => notificationevent.go} | 32 +++++------ .../{event.proto => notificationevent.proto} | 26 ++++----- 14 files changed, 119 insertions(+), 110 deletions(-) rename pkg/model/{event.go => notificationevent.go} (53%) rename pkg/model/{event.proto => notificationevent.proto} (84%) diff --git a/BUILD.bazel b/BUILD.bazel index 5798d20d00..cddef9a894 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -58,9 +58,11 @@ genrule( # gazelle:exclude pkg/model/deployment.pb.validate.go # gazelle:exclude pkg/model/environment.pb.validate.go # gazelle:exclude pkg/model/event.pb.validate.go +# gazelle:exclude pkg/model/imagemetadata.pb.validate.go # gazelle:exclude pkg/model/imagereference.pb.validate.go # gazelle:exclude pkg/model/insight.pb.validate.go # gazelle:exclude pkg/model/logblock.pb.validate.go +# gazelle:exclude pkg/model/notificationevent.pb.validate.go # gazelle:exclude pkg/model/piped.pb.validate.go # gazelle:exclude pkg/model/piped_stats.pb.validate.go # gazelle:exclude pkg/model/project.pb.validate.go diff --git a/pkg/app/piped/controller/controller.go b/pkg/app/piped/controller/controller.go index c4fd9a7878..25740b3ae8 100644 --- a/pkg/app/piped/controller/controller.go +++ b/pkg/app/piped/controller/controller.go @@ -84,7 +84,7 @@ type liveResourceLister interface { } type notifier interface { - Notify(event model.Event) + Notify(event model.NotificationEvent) } type sealedSecretDecrypter interface { diff --git a/pkg/app/piped/controller/planner.go b/pkg/app/piped/controller/planner.go index 19a909ad8a..7bb982b81e 100644 --- a/pkg/app/piped/controller/planner.go +++ b/pkg/app/piped/controller/planner.go @@ -216,9 +216,9 @@ func (p *planner) reportDeploymentPlanned(ctx context.Context, runningCommitHash ) defer func() { - p.notifier.Notify(model.Event{ - Type: model.EventType_EVENT_DEPLOYMENT_PLANNED, - Metadata: &model.EventDeploymentPlanned{ + p.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED, + Metadata: &model.NotificationEventDeploymentPlanned{ Deployment: p.deployment, EnvName: p.envName, Summary: out.Summary, @@ -254,9 +254,9 @@ func (p *planner) reportDeploymentFailed(ctx context.Context, reason string) err ) defer func() { - p.notifier.Notify(model.Event{ - Type: model.EventType_EVENT_DEPLOYMENT_FAILED, - Metadata: &model.EventDeploymentFailed{ + p.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_FAILED, + Metadata: &model.NotificationEventDeploymentFailed{ Deployment: p.deployment, EnvName: p.envName, Reason: reason, @@ -292,9 +292,9 @@ func (p *planner) reportDeploymentCancelled(ctx context.Context, commander, reas ) defer func() { - p.notifier.Notify(model.Event{ - Type: model.EventType_EVENT_DEPLOYMENT_CANCELLED, - Metadata: &model.EventDeploymentCancelled{ + p.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_CANCELLED, + Metadata: &model.NotificationEventDeploymentCancelled{ Deployment: p.deployment, EnvName: p.envName, Commander: commander, diff --git a/pkg/app/piped/controller/scheduler.go b/pkg/app/piped/controller/scheduler.go index 846b5b2ca2..46894a375e 100644 --- a/pkg/app/piped/controller/scheduler.go +++ b/pkg/app/piped/controller/scheduler.go @@ -581,18 +581,18 @@ func (s *scheduler) reportDeploymentCompleted(ctx context.Context, status model. defer func() { switch status { case model.DeploymentStatus_DEPLOYMENT_SUCCESS: - s.notifier.Notify(model.Event{ - Type: model.EventType_EVENT_DEPLOYMENT_SUCCEEDED, - Metadata: &model.EventDeploymentSucceeded{ + s.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED, + Metadata: &model.NotificationEventDeploymentSucceeded{ Deployment: s.deployment, EnvName: s.envName, }, }) case model.DeploymentStatus_DEPLOYMENT_FAILURE: - s.notifier.Notify(model.Event{ - Type: model.EventType_EVENT_DEPLOYMENT_FAILED, - Metadata: &model.EventDeploymentFailed{ + s.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_FAILED, + Metadata: &model.NotificationEventDeploymentFailed{ Deployment: s.deployment, EnvName: s.envName, Reason: desc, @@ -600,9 +600,9 @@ func (s *scheduler) reportDeploymentCompleted(ctx context.Context, status model. }) case model.DeploymentStatus_DEPLOYMENT_CANCELLED: - s.notifier.Notify(model.Event{ - Type: model.EventType_EVENT_DEPLOYMENT_CANCELLED, - Metadata: &model.EventDeploymentCancelled{ + s.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_CANCELLED, + Metadata: &model.NotificationEventDeploymentCancelled{ Deployment: s.deployment, EnvName: s.envName, Commander: cancelCommander, diff --git a/pkg/app/piped/notifier/matcher.go b/pkg/app/piped/notifier/matcher.go index af0bf0e351..f89a987537 100644 --- a/pkg/app/piped/notifier/matcher.go +++ b/pkg/app/piped/notifier/matcher.go @@ -51,7 +51,7 @@ type envNameMetadata interface { GetEnvName() string } -func (m *matcher) Match(event model.Event) bool { +func (m *matcher) Match(event model.NotificationEvent) bool { if _, ok := m.ignoreEvents[event.Type.String()]; ok { return false } diff --git a/pkg/app/piped/notifier/matcher_test.go b/pkg/app/piped/notifier/matcher_test.go index ad3111adef..6d1b5d380e 100644 --- a/pkg/app/piped/notifier/matcher_test.go +++ b/pkg/app/piped/notifier/matcher_test.go @@ -27,14 +27,14 @@ func TestMatch(t *testing.T) { testcases := []struct { name string config config.NotificationRoute - matchings map[model.Event]bool + matchings map[model.NotificationEvent]bool }{ { name: "empty config", config: config.NotificationRoute{}, - matchings: map[model.Event]bool{ + matchings: map[model.NotificationEvent]bool{ {}: true, - {Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED}: true, + {Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED}: true, }, }, { @@ -47,12 +47,12 @@ func TestMatch(t *testing.T) { "DEPLOYMENT_ROLLING_BACK", }, }, - matchings: map[model.Event]bool{ + matchings: map[model.NotificationEvent]bool{ { - Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED, + Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED, }: true, { - Type: model.EventType_EVENT_DEPLOYMENT_ROLLING_BACK, + Type: model.NotificationEventType_EVENT_DEPLOYMENT_ROLLING_BACK, }: false, }, }, @@ -66,12 +66,12 @@ func TestMatch(t *testing.T) { "APPLICATION", }, }, - matchings: map[model.Event]bool{ + matchings: map[model.NotificationEvent]bool{ { - Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED, + Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED, }: true, { - Type: model.EventType_EVENT_APPLICATION_SYNCED, + Type: model.NotificationEventType_EVENT_APPLICATION_SYNCED, }: false, }, }, @@ -85,34 +85,34 @@ func TestMatch(t *testing.T) { "bluegreen", }, }, - matchings: map[model.Event]bool{ + matchings: map[model.NotificationEvent]bool{ { - Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED, - Metadata: &model.EventDeploymentTriggered{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED, + Metadata: &model.NotificationEventDeploymentTriggered{ Deployment: &model.Deployment{ ApplicationName: "canary", }, }, }: true, { - Type: model.EventType_EVENT_DEPLOYMENT_PLANNED, - Metadata: &model.EventDeploymentTriggered{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED, + Metadata: &model.NotificationEventDeploymentTriggered{ Deployment: &model.Deployment{ ApplicationName: "bluegreen", }, }, }: false, { - Type: model.EventType_EVENT_DEPLOYMENT_SUCCEEDED, - Metadata: &model.EventDeploymentTriggered{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED, + Metadata: &model.NotificationEventDeploymentTriggered{ Deployment: &model.Deployment{ ApplicationName: "not-specified", }, }, }: false, { - Type: model.EventType_EVENT_PIPED_STARTED, - Metadata: &model.EventPipedStarted{}, + Type: model.NotificationEventType_EVENT_PIPED_STARTED, + Metadata: &model.NotificationEventPipedStarted{}, }: true, }, }, @@ -126,10 +126,10 @@ func TestMatch(t *testing.T) { "dev", }, }, - matchings: map[model.Event]bool{ + matchings: map[model.NotificationEvent]bool{ { - Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED, - Metadata: &model.EventDeploymentTriggered{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED, + Metadata: &model.NotificationEventDeploymentTriggered{ Deployment: &model.Deployment{ EnvId: "prod-id", }, @@ -137,8 +137,8 @@ func TestMatch(t *testing.T) { }, }: true, { - Type: model.EventType_EVENT_DEPLOYMENT_PLANNED, - Metadata: &model.EventDeploymentTriggered{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED, + Metadata: &model.NotificationEventDeploymentTriggered{ Deployment: &model.Deployment{ EnvId: "dev-id", }, @@ -146,8 +146,8 @@ func TestMatch(t *testing.T) { }, }: false, { - Type: model.EventType_EVENT_DEPLOYMENT_SUCCEEDED, - Metadata: &model.EventDeploymentTriggered{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED, + Metadata: &model.NotificationEventDeploymentTriggered{ Deployment: &model.Deployment{ EnvId: "not-specified", }, @@ -155,8 +155,8 @@ func TestMatch(t *testing.T) { }, }: false, { - Type: model.EventType_EVENT_PIPED_STARTED, - Metadata: &model.EventPipedStarted{}, + Type: model.NotificationEventType_EVENT_PIPED_STARTED, + Metadata: &model.NotificationEventPipedStarted{}, }: true, }, }, diff --git a/pkg/app/piped/notifier/notifier.go b/pkg/app/piped/notifier/notifier.go index 5505722b9a..78a454573d 100644 --- a/pkg/app/piped/notifier/notifier.go +++ b/pkg/app/piped/notifier/notifier.go @@ -45,7 +45,7 @@ type handler struct { type sender interface { Run(ctx context.Context) error - Notify(event model.Event) + Notify(event model.NotificationEvent) Close(ctx context.Context) } @@ -99,9 +99,9 @@ func (n *Notifier) Run(ctx context.Context) error { } // Send the PIPED_STARTED event. - n.Notify(model.Event{ - Type: model.EventType_EVENT_PIPED_STARTED, - Metadata: &model.EventPipedStarted{ + n.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_PIPED_STARTED, + Metadata: &model.NotificationEventPipedStarted{ Id: n.config.PipedID, Version: version.Get().Version, }, @@ -114,9 +114,9 @@ func (n *Notifier) Run(ctx context.Context) error { } // Send the PIPED_STOPPED event. - n.Notify(model.Event{ - Type: model.EventType_EVENT_PIPED_STOPPED, - Metadata: &model.EventPipedStopped{ + n.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_PIPED_STOPPED, + Metadata: &model.NotificationEventPipedStopped{ Id: n.config.PipedID, Version: version.Get().Version, }, @@ -136,7 +136,7 @@ func (n *Notifier) Run(ctx context.Context) error { return nil } -func (n *Notifier) Notify(event model.Event) { +func (n *Notifier) Notify(event model.NotificationEvent) { if n.closed.Load() { n.logger.Warn("ignore an event because notifier is already closed", zap.String("type", event.Type.String())) return diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index b68d80f243..e013daf3a5 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -44,7 +44,7 @@ type slack struct { config config.NotificationReceiverSlack webURL string httpClient *http.Client - eventCh chan model.Event + eventCh chan model.NotificationEvent logger *zap.Logger } @@ -56,7 +56,7 @@ func newSlackSender(name string, cfg config.NotificationReceiverSlack, webURL st httpClient: &http.Client{ Timeout: 5 * time.Second, }, - eventCh: make(chan model.Event, 100), + eventCh: make(chan model.NotificationEvent, 100), logger: logger.Named("slack"), } } @@ -74,7 +74,7 @@ func (s *slack) Run(ctx context.Context) error { } } -func (s *slack) Notify(event model.Event) { +func (s *slack) Notify(event model.NotificationEvent) { s.eventCh <- event } @@ -95,7 +95,7 @@ func (s *slack) Close(ctx context.Context) { } } -func (s *slack) sendEvent(ctx context.Context, event model.Event) { +func (s *slack) sendEvent(ctx context.Context, event model.NotificationEvent) { msg, ok := s.buildSlackMessage(event, s.webURL) if !ok { s.logger.Info(fmt.Sprintf("ignore event %s", event.Type.String())) @@ -131,7 +131,7 @@ func (s *slack) sendMessage(ctx context.Context, msg slackMessage) error { return nil } -func (s *slack) buildSlackMessage(event model.Event, webURL string) (slackMessage, bool) { +func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) (slackMessage, bool) { var ( title, link, text string color = slackInfoColor @@ -159,44 +159,44 @@ func (s *slack) buildSlackMessage(event model.Event, webURL string) (slackMessag } switch event.Type { - case model.EventType_EVENT_DEPLOYMENT_TRIGGERED: - md := event.Metadata.(*model.EventDeploymentTriggered) + case model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED: + md := event.Metadata.(*model.NotificationEventDeploymentTriggered) title = fmt.Sprintf("Triggered a new deployment for %q", md.Deployment.ApplicationName) generateDeploymentEventData(md.Deployment, md.EnvName) - case model.EventType_EVENT_DEPLOYMENT_PLANNED: - md := event.Metadata.(*model.EventDeploymentPlanned) + case model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED: + md := event.Metadata.(*model.NotificationEventDeploymentPlanned) title = fmt.Sprintf("Deployment for %q was planned", md.Deployment.ApplicationName) text = md.Summary generateDeploymentEventData(md.Deployment, md.EnvName) - case model.EventType_EVENT_DEPLOYMENT_SUCCEEDED: - md := event.Metadata.(*model.EventDeploymentSucceeded) + case model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED: + md := event.Metadata.(*model.NotificationEventDeploymentSucceeded) title = fmt.Sprintf("Deployment for %q was completed successfully", md.Deployment.ApplicationName) color = slackSuccessColor generateDeploymentEventData(md.Deployment, md.EnvName) - case model.EventType_EVENT_DEPLOYMENT_FAILED: - md := event.Metadata.(*model.EventDeploymentFailed) + case model.NotificationEventType_EVENT_DEPLOYMENT_FAILED: + md := event.Metadata.(*model.NotificationEventDeploymentFailed) title = fmt.Sprintf("Deployment for %q was failed", md.Deployment.ApplicationName) text = md.Reason color = slackErrorColor generateDeploymentEventData(md.Deployment, md.EnvName) - case model.EventType_EVENT_DEPLOYMENT_CANCELLED: - md := event.Metadata.(*model.EventDeploymentCancelled) + case model.NotificationEventType_EVENT_DEPLOYMENT_CANCELLED: + md := event.Metadata.(*model.NotificationEventDeploymentCancelled) title = fmt.Sprintf("Deployment for %q was cancelled", md.Deployment.ApplicationName) text = fmt.Sprintf("Cancelled by %s", md.Commander) color = slackWarnColor generateDeploymentEventData(md.Deployment, md.EnvName) - case model.EventType_EVENT_PIPED_STARTED: - md := event.Metadata.(*model.EventPipedStarted) + case model.NotificationEventType_EVENT_PIPED_STARTED: + md := event.Metadata.(*model.NotificationEventPipedStarted) title = "A piped has been started" generatePipedEventData(md.Id, md.Version) - case model.EventType_EVENT_PIPED_STOPPED: - md := event.Metadata.(*model.EventPipedStopped) + case model.NotificationEventType_EVENT_PIPED_STOPPED: + md := event.Metadata.(*model.NotificationEventPipedStopped) title = "A piped has been stopped" generatePipedEventData(md.Id, md.Version) diff --git a/pkg/app/piped/notifier/webhook.go b/pkg/app/piped/notifier/webhook.go index e1843cf105..6846f6a7e4 100644 --- a/pkg/app/piped/notifier/webhook.go +++ b/pkg/app/piped/notifier/webhook.go @@ -41,7 +41,7 @@ func (s *webhook) Run(ctx context.Context) error { return nil } -func (s *webhook) Notify(event model.Event) { +func (s *webhook) Notify(event model.NotificationEvent) { } func (s *webhook) Close(ctx context.Context) { diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index dd5302e3f1..2acb431956 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -48,9 +48,9 @@ func (t *Trigger) triggerDeployment( if env, ok := t.environmentLister.Get(deployment.EnvId); ok { envName = env.Name } - t.notifier.Notify(model.Event{ - Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED, - Metadata: &model.EventDeploymentTriggered{ + t.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED, + Metadata: &model.NotificationEventDeploymentTriggered{ Deployment: deployment, EnvName: envName, }, diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index e8a06f4e55..95fbe4f452 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -68,7 +68,7 @@ type environmentLister interface { } type notifier interface { - Notify(event model.Event) + Notify(event model.NotificationEvent) } type Trigger struct { diff --git a/pkg/model/BUILD.bazel b/pkg/model/BUILD.bazel index 44780888a0..001172ce39 100644 --- a/pkg/model/BUILD.bazel +++ b/pkg/model/BUILD.bazel @@ -11,10 +11,10 @@ proto_library( "common.proto", "deployment.proto", "environment.proto", - "event.proto", "imagereference.proto", "insight.proto", "logblock.proto", + "notificationevent.proto", "piped.proto", "piped_stats.proto", "project.proto", @@ -53,11 +53,13 @@ go_library( "deployment.go", "docs.go", "environment.go", - "event.go", "filestore.go", "image_name.go", + "imagemetadata.pb.go", + "imagemetadata.pb.validate.go", "imageprovider.go", "model.go", + "notificationevent.go", "piped.go", "project.go", "stage.go", @@ -66,7 +68,12 @@ go_library( importpath = "github.com/pipe-cd/pipe/pkg/model", visibility = ["//visibility:public"], deps = [ + "@com_github_envoyproxy_protoc_gen_validate//validate:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//ptypes:go_default_library_gen", "@org_golang_google_protobuf//proto:go_default_library", + "@org_golang_google_protobuf//reflect/protoreflect:go_default_library", + "@org_golang_google_protobuf//runtime/protoimpl:go_default_library", "@org_golang_x_crypto//bcrypt:go_default_library", "@org_golang_x_oauth2//:go_default_library", "@org_golang_x_oauth2//github:go_default_library", diff --git a/pkg/model/event.go b/pkg/model/notificationevent.go similarity index 53% rename from pkg/model/event.go rename to pkg/model/notificationevent.go index 773dc29feb..bc84dbade6 100644 --- a/pkg/model/event.go +++ b/pkg/model/notificationevent.go @@ -14,54 +14,54 @@ package model -type Event struct { - Type EventType +type NotificationEvent struct { + Type NotificationEventType Metadata interface{} } -func (e Event) Group() EventGroup { +func (e NotificationEvent) Group() NotificationEventGroup { switch { case e.Type < 100: - return EventGroup_EVENT_DEPLOYMENT + return NotificationEventGroup_EVENT_DEPLOYMENT case e.Type < 200: - return EventGroup_EVENT_APPLICATION_SYNC + return NotificationEventGroup_EVENT_APPLICATION_SYNC case e.Type < 300: - return EventGroup_EVENT_APPLICATION_HEALTH + return NotificationEventGroup_EVENT_APPLICATION_HEALTH case e.Type < 400: - return EventGroup_EVENT_PIPED + return NotificationEventGroup_EVENT_PIPED default: - return EventGroup_EVENT_NONE + return NotificationEventGroup_EVENT_NONE } } -func (e *EventDeploymentTriggered) GetAppName() string { +func (e *NotificationEventDeploymentTriggered) GetAppName() string { return e.Deployment.ApplicationName } -func (e *EventDeploymentPlanned) GetAppName() string { +func (e *NotificationEventDeploymentPlanned) GetAppName() string { return e.Deployment.ApplicationName } -func (e *EventDeploymentApproved) GetAppName() string { +func (e *NotificationEventDeploymentApproved) GetAppName() string { return e.Deployment.ApplicationName } -func (e *EventDeploymentRollingBack) GetAppName() string { +func (e *NotificationEventDeploymentRollingBack) GetAppName() string { return e.Deployment.ApplicationName } -func (e *EventDeploymentSucceeded) GetAppName() string { +func (e *NotificationEventDeploymentSucceeded) GetAppName() string { return e.Deployment.ApplicationName } -func (e *EventDeploymentFailed) GetAppName() string { +func (e *NotificationEventDeploymentFailed) GetAppName() string { return e.Deployment.ApplicationName } -func (e *EventApplicationSynced) GetAppName() string { +func (e *NotificationEventApplicationSynced) GetAppName() string { return e.Application.Id } -func (e *EventApplicationOutOfSync) GetAppName() string { +func (e *NotificationEventApplicationOutOfSync) GetAppName() string { return e.Application.Id } diff --git a/pkg/model/event.proto b/pkg/model/notificationevent.proto similarity index 84% rename from pkg/model/event.proto rename to pkg/model/notificationevent.proto index 97ef55f145..7e41535397 100644 --- a/pkg/model/event.proto +++ b/pkg/model/notificationevent.proto @@ -21,7 +21,7 @@ import "validate/validate.proto"; import "pkg/model/application.proto"; import "pkg/model/deployment.proto"; -enum EventType { +enum NotificationEventType { EVENT_DEPLOYMENT_TRIGGERED = 0; EVENT_DEPLOYMENT_PLANNED = 1; EVENT_DEPLOYMENT_APPROVED = 2; @@ -41,7 +41,7 @@ enum EventType { } -enum EventGroup { +enum NotificationEventGroup { EVENT_NONE = 0; EVENT_DEPLOYMENT = 1; EVENT_APPLICATION_SYNC = 2; @@ -49,63 +49,63 @@ enum EventGroup { EVENT_PIPED = 4; } -message EventDeploymentTriggered { +message NotificationEventDeploymentTriggered { Deployment deployment = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; } -message EventDeploymentPlanned { +message NotificationEventDeploymentPlanned { Deployment deployment = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; string summary = 3; } -message EventDeploymentApproved { +message NotificationEventDeploymentApproved { Deployment deployment = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; string approver = 3; } -message EventDeploymentRollingBack { +message NotificationEventDeploymentRollingBack { Deployment deployment = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; } -message EventDeploymentSucceeded { +message NotificationEventDeploymentSucceeded { Deployment deployment = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; } -message EventDeploymentFailed { +message NotificationEventDeploymentFailed { Deployment deployment = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; string reason = 3; } -message EventDeploymentCancelled { +message NotificationEventDeploymentCancelled { Deployment deployment = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; string commander = 3; } -message EventApplicationSynced { +message NotificationEventApplicationSynced { Application application = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; ApplicationSyncState state = 3 [(validate.rules).message.required = true]; } -message EventApplicationOutOfSync { +message NotificationEventApplicationOutOfSync { Application application = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; ApplicationSyncState state = 3 [(validate.rules).message.required = true]; } -message EventPipedStarted { +message NotificationEventPipedStarted { string id = 1 [(validate.rules).string.min_len = 1]; string version = 2; } -message EventPipedStopped { +message NotificationEventPipedStopped { string id = 1 [(validate.rules).string.min_len = 1]; string version = 2; } From 4a1b49877f8979c98b848ee046029b3751716f18 Mon Sep 17 00:00:00 2001 From: nghialv Date: Fri, 8 Jan 2021 18:39:29 +0900 Subject: [PATCH 2/4] Fix build --- BUILD.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index cddef9a894..85ae68a085 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -57,7 +57,6 @@ genrule( # gazelle:exclude pkg/model/common.pb.validate.go # gazelle:exclude pkg/model/deployment.pb.validate.go # gazelle:exclude pkg/model/environment.pb.validate.go -# gazelle:exclude pkg/model/event.pb.validate.go # gazelle:exclude pkg/model/imagemetadata.pb.validate.go # gazelle:exclude pkg/model/imagereference.pb.validate.go # gazelle:exclude pkg/model/insight.pb.validate.go From 5ccecc8c43bf904f21530393ce2c3dcba64ad2eb Mon Sep 17 00:00:00 2001 From: nghialv Date: Fri, 8 Jan 2021 18:59:53 +0900 Subject: [PATCH 3/4] Fix BUILD.bazel --- BUILD.bazel | 1 - pkg/model/BUILD.bazel | 7 ------- 2 files changed, 8 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 85ae68a085..c2bce60ba5 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -57,7 +57,6 @@ genrule( # gazelle:exclude pkg/model/common.pb.validate.go # gazelle:exclude pkg/model/deployment.pb.validate.go # gazelle:exclude pkg/model/environment.pb.validate.go -# gazelle:exclude pkg/model/imagemetadata.pb.validate.go # gazelle:exclude pkg/model/imagereference.pb.validate.go # gazelle:exclude pkg/model/insight.pb.validate.go # gazelle:exclude pkg/model/logblock.pb.validate.go diff --git a/pkg/model/BUILD.bazel b/pkg/model/BUILD.bazel index 001172ce39..db09715afa 100644 --- a/pkg/model/BUILD.bazel +++ b/pkg/model/BUILD.bazel @@ -55,8 +55,6 @@ go_library( "environment.go", "filestore.go", "image_name.go", - "imagemetadata.pb.go", - "imagemetadata.pb.validate.go", "imageprovider.go", "model.go", "notificationevent.go", @@ -68,12 +66,7 @@ go_library( importpath = "github.com/pipe-cd/pipe/pkg/model", visibility = ["//visibility:public"], deps = [ - "@com_github_envoyproxy_protoc_gen_validate//validate:go_default_library", - "@com_github_golang_protobuf//proto:go_default_library", - "@com_github_golang_protobuf//ptypes:go_default_library_gen", "@org_golang_google_protobuf//proto:go_default_library", - "@org_golang_google_protobuf//reflect/protoreflect:go_default_library", - "@org_golang_google_protobuf//runtime/protoimpl:go_default_library", "@org_golang_x_crypto//bcrypt:go_default_library", "@org_golang_x_oauth2//:go_default_library", "@org_golang_x_oauth2//github:go_default_library", From 4cc337319324edfebc38f023a05a54e892adb5be Mon Sep 17 00:00:00 2001 From: Le Van Nghia Date: Fri, 8 Jan 2021 19:06:59 +0900 Subject: [PATCH 4/4] Update pkg/app/piped/notifier/webhook.go --- pkg/app/piped/notifier/webhook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/notifier/webhook.go b/pkg/app/piped/notifier/webhook.go index 6846f6a7e4..51d7a545ff 100644 --- a/pkg/app/piped/notifier/webhook.go +++ b/pkg/app/piped/notifier/webhook.go @@ -41,7 +41,7 @@ func (s *webhook) Run(ctx context.Context) error { return nil } -func (s *webhook) Notify(event model.NotificationEvent) { +func (s *webhook) Notify(_ model.NotificationEvent) { } func (s *webhook) Close(ctx context.Context) {