From a7bc70d55c00b330ff89d7be35c252d55a4a3f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Thu, 4 Nov 2021 21:50:16 +0900 Subject: [PATCH 01/24] Send notification to users via Slack when the application misses .pipe.yaml file --- pkg/app/piped/notifier/slack.go | 6 ++++++ pkg/app/piped/trigger/BUILD.bazel | 1 + pkg/app/piped/trigger/deployment.go | 17 +++++++++++++++++ pkg/app/piped/trigger/trigger.go | 5 +++++ pkg/model/notificationevent.proto | 9 +++++++++ 5 files changed, 38 insertions(+) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 99da863514..4a4e754446 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -213,6 +213,12 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) md := event.Metadata.(*model.NotificationEventPipedStopped) title = "A piped has been stopped" generatePipedEventData(md.Id, md.Name, md.Version, md.ProjectId) + + case model.NotificationEventType_EVENT_PIPED_FAILED: + md := event.Metadata.(*model.NotificationEventPipedFailed) + title = "A piped failed to start" + text = md.Reason + generatePipedEventData(md.Id, md.Name, md.Version, md.ProjectId) // TODO: Support application type of notification event. default: diff --git a/pkg/app/piped/trigger/BUILD.bazel b/pkg/app/piped/trigger/BUILD.bazel index 28126f1dca..eb8fc419c4 100644 --- a/pkg/app/piped/trigger/BUILD.bazel +++ b/pkg/app/piped/trigger/BUILD.bazel @@ -18,6 +18,7 @@ go_library( "//pkg/filematcher:go_default_library", "//pkg/git:go_default_library", "//pkg/model:go_default_library", + "//pkg/version:go_default_library", "@com_github_google_uuid//:go_default_library", "@org_golang_google_grpc//:go_default_library", "@org_golang_google_grpc//codes:go_default_library", diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 2d5a2d8d53..475aaf02ac 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -29,6 +29,7 @@ import ( "github.com/pipe-cd/pipe/pkg/config" "github.com/pipe-cd/pipe/pkg/git" "github.com/pipe-cd/pipe/pkg/model" + "github.com/pipe-cd/pipe/pkg/version" ) const notificationsKey = "DeploymentNotification" @@ -44,6 +45,7 @@ func (t *Trigger) triggerDeployment( n, err := t.getNotification(app.GitPath) if err != nil { t.logger.Error("failed to get the list of mentions", zap.Error(err)) + t.reportDeploymentFailed(ctx, fmt.Sprintf("failed to get the list of mentions %v", err)) return } @@ -183,6 +185,21 @@ func buildDeployment( return deployment, nil } +func (t *Trigger) reportDeploymentFailed(ctx context.Context, reason string) { + defer func() { + t.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_PIPED_FAILED, + Metadata: &model.NotificationEventPipedFailed{ + Id: t.config.PipedID, + Name: t.config.Name, + Version: version.Get().Version, + ProjectId: t.config.ProjectID, + Reason: reason, + }, + }) + }() +} + func (t *Trigger) getNotification(p *model.ApplicationGitPath) (*config.DeploymentNotification, error) { // Find the application repo from pre-loaded ones. repo, ok := t.gitRepos[p.Repo.Id] diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index 7b3831a75c..edb630eae0 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -45,6 +45,7 @@ type apiClient interface { GetApplicationMostRecentDeployment(ctx context.Context, req *pipedservice.GetApplicationMostRecentDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.GetApplicationMostRecentDeploymentResponse, error) CreateDeployment(ctx context.Context, in *pipedservice.CreateDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.CreateDeploymentResponse, error) ReportApplicationMostRecentDeployment(ctx context.Context, req *pipedservice.ReportApplicationMostRecentDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.ReportApplicationMostRecentDeploymentResponse, error) + ReportDeploymentCompleted(ctx context.Context, req *pipedservice.ReportDeploymentCompletedRequest, opts ...grpc.CallOption) (*pipedservice.ReportDeploymentCompletedResponse, error) } type gitClient interface { @@ -80,6 +81,8 @@ type Trigger struct { gitRepos map[string]git.Repo gracePeriod time.Duration logger *zap.Logger + + nowFunc func() time.Time } // NewTrigger creates a new instance for Trigger. @@ -116,6 +119,7 @@ func NewTrigger( gitRepos: make(map[string]git.Repo, len(cfg.Repositories)), gracePeriod: gracePeriod, logger: logger.Named("trigger"), + nowFunc: time.Now, } return t, nil @@ -233,6 +237,7 @@ func (t *Trigger) checkNewCommits(ctx context.Context) error { shouldTrigger, err := d.ShouldTrigger(ctx, app) if err != nil { t.logger.Error(fmt.Sprintf("failed to check application: %s", app.Id), zap.Error(err)) + t.reportDeploymentFailed(ctx, fmt.Sprintf("failed to get the list of mentions %v", err)) continue } diff --git a/pkg/model/notificationevent.proto b/pkg/model/notificationevent.proto index 650dd256ef..1479c85099 100644 --- a/pkg/model/notificationevent.proto +++ b/pkg/model/notificationevent.proto @@ -39,6 +39,7 @@ enum NotificationEventType { EVENT_PIPED_STARTED = 300; EVENT_PIPED_STOPPED = 301; + EVENT_PIPED_FAILED = 302; } @@ -126,3 +127,11 @@ message NotificationEventPipedStopped { string version = 3; string project_id = 4 [(validate.rules).string.min_len = 1]; } + +message NotificationEventPipedFailed { + string id = 1 [(validate.rules).string.min_len = 1]; + string name = 2 [(validate.rules).string.min_len = 1]; + string version = 3; + string project_id = 4 [(validate.rules).string.min_len = 1]; + string reason = 5; +} From 54bac139033f855c243c6bf9274db8781159cba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Thu, 4 Nov 2021 21:55:06 +0900 Subject: [PATCH 02/24] Remove the unused field --- pkg/app/piped/trigger/trigger.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index edb630eae0..ee8b75b1ab 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -81,8 +81,6 @@ type Trigger struct { gitRepos map[string]git.Repo gracePeriod time.Duration logger *zap.Logger - - nowFunc func() time.Time } // NewTrigger creates a new instance for Trigger. @@ -119,7 +117,6 @@ func NewTrigger( gitRepos: make(map[string]git.Repo, len(cfg.Repositories)), gracePeriod: gracePeriod, logger: logger.Named("trigger"), - nowFunc: time.Now, } return t, nil From 06ea6c9cc677057b263e20a4390dfdf636dfdabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Thu, 4 Nov 2021 21:56:58 +0900 Subject: [PATCH 03/24] Remove the unused argument --- pkg/app/piped/trigger/deployment.go | 4 ++-- pkg/app/piped/trigger/trigger.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 475aaf02ac..33ac15b80d 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -45,7 +45,7 @@ func (t *Trigger) triggerDeployment( n, err := t.getNotification(app.GitPath) if err != nil { t.logger.Error("failed to get the list of mentions", zap.Error(err)) - t.reportDeploymentFailed(ctx, fmt.Sprintf("failed to get the list of mentions %v", err)) + t.reportDeploymentFailed(fmt.Sprintf("failed to get the list of mentions %v", err)) return } @@ -185,7 +185,7 @@ func buildDeployment( return deployment, nil } -func (t *Trigger) reportDeploymentFailed(ctx context.Context, reason string) { +func (t *Trigger) reportDeploymentFailed(reason string) { defer func() { t.notifier.Notify(model.NotificationEvent{ Type: model.NotificationEventType_EVENT_PIPED_FAILED, diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index ee8b75b1ab..cd8eec3954 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -234,7 +234,7 @@ func (t *Trigger) checkNewCommits(ctx context.Context) error { shouldTrigger, err := d.ShouldTrigger(ctx, app) if err != nil { t.logger.Error(fmt.Sprintf("failed to check application: %s", app.Id), zap.Error(err)) - t.reportDeploymentFailed(ctx, fmt.Sprintf("failed to get the list of mentions %v", err)) + t.reportDeploymentFailed(fmt.Sprintf("failed to get the list of mentions %v", err)) continue } From d7b9cb0caea97c16867c25b295566cb5f1474a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Thu, 4 Nov 2021 21:57:41 +0900 Subject: [PATCH 04/24] Format codes --- pkg/app/piped/notifier/slack.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 4a4e754446..74e62e4ca5 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -213,7 +213,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) md := event.Metadata.(*model.NotificationEventPipedStopped) title = "A piped has been stopped" generatePipedEventData(md.Id, md.Name, md.Version, md.ProjectId) - + case model.NotificationEventType_EVENT_PIPED_FAILED: md := event.Metadata.(*model.NotificationEventPipedFailed) title = "A piped failed to start" From ceb0c36ab73619d5ecf349e5b97a371498399e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Fri, 5 Nov 2021 11:25:59 +0900 Subject: [PATCH 05/24] Change the event name from "NotificationEventType_EVENT_PIPED_FAILED" to "NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED" --- pkg/app/piped/notifier/slack.go | 12 ++++++------ pkg/app/piped/trigger/deployment.go | 4 ++-- pkg/model/notificationevent.proto | 19 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 74e62e4ca5..8544354bd2 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -204,6 +204,12 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) color = slackWarnColor generateDeploymentEventData(md.Deployment, md.EnvName, getAccountsAsString(md.MentionedAccounts)) + case model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED: + md := event.Metadata.(*model.NotificationEventDeploymentTriggerFailed) + title = "Deployment Trigger was failed" + text = md.Reason + generatePipedEventData(md.Id, md.Name, md.Version, md.ProjectId) + case model.NotificationEventType_EVENT_PIPED_STARTED: md := event.Metadata.(*model.NotificationEventPipedStarted) title = "A piped has been started" @@ -214,12 +220,6 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) title = "A piped has been stopped" generatePipedEventData(md.Id, md.Name, md.Version, md.ProjectId) - case model.NotificationEventType_EVENT_PIPED_FAILED: - md := event.Metadata.(*model.NotificationEventPipedFailed) - title = "A piped failed to start" - text = md.Reason - generatePipedEventData(md.Id, md.Name, md.Version, md.ProjectId) - // TODO: Support application type of notification event. default: return slackMessage{}, false diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 33ac15b80d..7e5629f4fd 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -188,8 +188,8 @@ func buildDeployment( func (t *Trigger) reportDeploymentFailed(reason string) { defer func() { t.notifier.Notify(model.NotificationEvent{ - Type: model.NotificationEventType_EVENT_PIPED_FAILED, - Metadata: &model.NotificationEventPipedFailed{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED, + Metadata: &model.NotificationEventDeploymentTriggerFailed{ Id: t.config.PipedID, Name: t.config.Name, Version: version.Get().Version, diff --git a/pkg/model/notificationevent.proto b/pkg/model/notificationevent.proto index 1479c85099..b6a3e9fe43 100644 --- a/pkg/model/notificationevent.proto +++ b/pkg/model/notificationevent.proto @@ -30,6 +30,7 @@ enum NotificationEventType { EVENT_DEPLOYMENT_FAILED = 5; EVENT_DEPLOYMENT_CANCELLED = 6; EVENT_DEPLOYMENT_WAIT_APPROVAL = 7; + EVENT_DEPLOYMENT_TRIGGER_FAILED = 8; EVENT_APPLICATION_SYNCED = 100; EVENT_APPLICATION_OUT_OF_SYNC = 101; @@ -39,8 +40,6 @@ enum NotificationEventType { EVENT_PIPED_STARTED = 300; EVENT_PIPED_STOPPED = 301; - EVENT_PIPED_FAILED = 302; - } enum NotificationEventGroup { @@ -102,6 +101,14 @@ message NotificationEventDeploymentWaitApproval { repeated string mentioned_accounts = 3; } +message NotificationEventDeploymentTriggerFailed { + string id = 1 [(validate.rules).string.min_len = 1]; + string name = 2 [(validate.rules).string.min_len = 1]; + string version = 3; + string project_id = 4 [(validate.rules).string.min_len = 1]; + string reason = 5; +} + message NotificationEventApplicationSynced { Application application = 1 [(validate.rules).message.required = true]; string env_name = 2 [(validate.rules).string.min_len = 1]; @@ -127,11 +134,3 @@ message NotificationEventPipedStopped { string version = 3; string project_id = 4 [(validate.rules).string.min_len = 1]; } - -message NotificationEventPipedFailed { - string id = 1 [(validate.rules).string.min_len = 1]; - string name = 2 [(validate.rules).string.min_len = 1]; - string version = 3; - string project_id = 4 [(validate.rules).string.min_len = 1]; - string reason = 5; -} From a5a73cafdfff988c5bd4a0c3fb92957b0ac60ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Fri, 5 Nov 2021 11:36:40 +0900 Subject: [PATCH 06/24] Remove defer block --- pkg/app/piped/trigger/deployment.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 7e5629f4fd..976dda01a4 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -186,18 +186,16 @@ func buildDeployment( } func (t *Trigger) reportDeploymentFailed(reason string) { - defer func() { - t.notifier.Notify(model.NotificationEvent{ - Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED, - Metadata: &model.NotificationEventDeploymentTriggerFailed{ - Id: t.config.PipedID, - Name: t.config.Name, - Version: version.Get().Version, - ProjectId: t.config.ProjectID, - Reason: reason, - }, - }) - }() + t.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED, + Metadata: &model.NotificationEventDeploymentTriggerFailed{ + Id: t.config.PipedID, + Name: t.config.Name, + Version: version.Get().Version, + ProjectId: t.config.ProjectID, + Reason: reason, + }, + }) } func (t *Trigger) getNotification(p *model.ApplicationGitPath) (*config.DeploymentNotification, error) { From 70bdb71f919ceb330d1efa007994790f770f6a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Fri, 5 Nov 2021 14:33:51 +0900 Subject: [PATCH 07/24] Modify fields in Slack to make it easier to read --- pkg/app/piped/notifier/slack.go | 15 ++++++++++++++- pkg/app/piped/trigger/deployment.go | 16 ++++++++-------- pkg/app/piped/trigger/trigger.go | 2 +- pkg/model/notificationevent.proto | 13 ++++++++----- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 8544354bd2..62076123cb 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -151,6 +151,15 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) {"Started At", makeSlackDate(d.CreatedAt), true}, } } + generateDeploymentEventDataForTriggerFailed := func(app *model.Application, commit *model.GitCommit) { + link = makeCommitLink(app.GitPath, commit.Hash) + fields = []slackField{ + {"Project", truncateText(app.ProjectId, 8), true}, + {"Application", makeSlackLink(app.Name, fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)), true}, + {"Kind", strings.ToLower(app.Kind.String()), true}, + {"Commit", makeSlackLink(truncateText(commit.Message, 8), link), true}, + } + } generatePipedEventData := func(id, name, version, project string) { link = fmt.Sprintf("%s/settings/piped?project=%s", webURL, project) fields = []slackField{ @@ -208,7 +217,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) md := event.Metadata.(*model.NotificationEventDeploymentTriggerFailed) title = "Deployment Trigger was failed" text = md.Reason - generatePipedEventData(md.Id, md.Name, md.Version, md.ProjectId) + generateDeploymentEventDataForTriggerFailed(md.Application, md.Commit) case model.NotificationEventType_EVENT_PIPED_STARTED: md := event.Metadata.(*model.NotificationEventPipedStarted) @@ -289,3 +298,7 @@ func getAccountsAsString(accounts []string) string { } return strings.Join(formattedAccounts, " ") } + +func makeCommitLink(gp *model.ApplicationGitPath, hash string) string { + return strings.Replace(gp.Url, fmt.Sprintf("/tree/master/%s", gp.Path), "", 1) + fmt.Sprintf("/commit/%s", hash) +} diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 976dda01a4..f8b6e4655e 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -29,7 +29,6 @@ import ( "github.com/pipe-cd/pipe/pkg/config" "github.com/pipe-cd/pipe/pkg/git" "github.com/pipe-cd/pipe/pkg/model" - "github.com/pipe-cd/pipe/pkg/version" ) const notificationsKey = "DeploymentNotification" @@ -45,7 +44,7 @@ func (t *Trigger) triggerDeployment( n, err := t.getNotification(app.GitPath) if err != nil { t.logger.Error("failed to get the list of mentions", zap.Error(err)) - t.reportDeploymentFailed(fmt.Sprintf("failed to get the list of mentions %v", err)) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to get the list of mentions %v", err), commit) return } @@ -185,15 +184,16 @@ func buildDeployment( return deployment, nil } -func (t *Trigger) reportDeploymentFailed(reason string) { +func (t *Trigger) reportDeploymentFailed(app *model.Application, reason string, commit git.Commit) { t.notifier.Notify(model.NotificationEvent{ Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED, Metadata: &model.NotificationEventDeploymentTriggerFailed{ - Id: t.config.PipedID, - Name: t.config.Name, - Version: version.Get().Version, - ProjectId: t.config.ProjectID, - Reason: reason, + Application: app, + Commit: &model.GitCommit{ + Hash: commit.Hash, + Message: commit.Message, + }, + Reason: reason, }, }) } diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index cd8eec3954..5a7ae18fb0 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -234,7 +234,7 @@ func (t *Trigger) checkNewCommits(ctx context.Context) error { shouldTrigger, err := d.ShouldTrigger(ctx, app) if err != nil { t.logger.Error(fmt.Sprintf("failed to check application: %s", app.Id), zap.Error(err)) - t.reportDeploymentFailed(fmt.Sprintf("failed to get the list of mentions %v", err)) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to get the list of mentions %v", err), headCommit) continue } diff --git a/pkg/model/notificationevent.proto b/pkg/model/notificationevent.proto index b6a3e9fe43..5434c33b3c 100644 --- a/pkg/model/notificationevent.proto +++ b/pkg/model/notificationevent.proto @@ -102,11 +102,9 @@ message NotificationEventDeploymentWaitApproval { } message NotificationEventDeploymentTriggerFailed { - string id = 1 [(validate.rules).string.min_len = 1]; - string name = 2 [(validate.rules).string.min_len = 1]; - string version = 3; - string project_id = 4 [(validate.rules).string.min_len = 1]; - string reason = 5; + Application application = 1 [(validate.rules).message.required = true]; + GitCommit commit = 2 [(validate.rules).message.required = true]; + string reason = 3 [(validate.rules).string.min_len = 1]; } message NotificationEventApplicationSynced { @@ -134,3 +132,8 @@ message NotificationEventPipedStopped { string version = 3; string project_id = 4 [(validate.rules).string.min_len = 1]; } + +message GitCommit { + string hash = 4 [(validate.rules).string.min_len = 1]; + string message = 7 [(validate.rules).string.min_len = 1]; +} From 811f5bc5a27cad1c8b65cb2f13fb8056d7f84380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Fri, 5 Nov 2021 16:14:00 +0900 Subject: [PATCH 08/24] Format codes --- pkg/app/piped/trigger/deployment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index f8b6e4655e..61b0ee80ff 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -190,7 +190,7 @@ func (t *Trigger) reportDeploymentFailed(app *model.Application, reason string, Metadata: &model.NotificationEventDeploymentTriggerFailed{ Application: app, Commit: &model.GitCommit{ - Hash: commit.Hash, + Hash: commit.Hash, Message: commit.Message, }, Reason: reason, From f179e320ca2c4ada7344c9b49a417f50a04a31c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 10:39:16 +0900 Subject: [PATCH 09/24] Define a couple of fields in "NotificationEventDeploymentTriggerFailed" directly --- pkg/app/piped/notifier/slack.go | 8 ++++---- pkg/app/piped/trigger/deployment.go | 8 +++----- pkg/model/notificationevent.proto | 10 +++------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 62076123cb..7868201241 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -151,13 +151,13 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) {"Started At", makeSlackDate(d.CreatedAt), true}, } } - generateDeploymentEventDataForTriggerFailed := func(app *model.Application, commit *model.GitCommit) { - link = makeCommitLink(app.GitPath, commit.Hash) + generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg string) { + link = makeCommitLink(app.GitPath, hash) fields = []slackField{ {"Project", truncateText(app.ProjectId, 8), true}, {"Application", makeSlackLink(app.Name, fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)), true}, {"Kind", strings.ToLower(app.Kind.String()), true}, - {"Commit", makeSlackLink(truncateText(commit.Message, 8), link), true}, + {"Commit", makeSlackLink(truncateText(msg, 8), link), true}, } } generatePipedEventData := func(id, name, version, project string) { @@ -217,7 +217,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) md := event.Metadata.(*model.NotificationEventDeploymentTriggerFailed) title = "Deployment Trigger was failed" text = md.Reason - generateDeploymentEventDataForTriggerFailed(md.Application, md.Commit) + generateDeploymentEventDataForTriggerFailed(md.Application, md.Hash, md.Message) case model.NotificationEventType_EVENT_PIPED_STARTED: md := event.Metadata.(*model.NotificationEventPipedStarted) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 61b0ee80ff..f51fd101bb 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -189,11 +189,9 @@ func (t *Trigger) reportDeploymentFailed(app *model.Application, reason string, Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED, Metadata: &model.NotificationEventDeploymentTriggerFailed{ Application: app, - Commit: &model.GitCommit{ - Hash: commit.Hash, - Message: commit.Message, - }, - Reason: reason, + Hash: commit.Hash, + Message: commit.Message, + Reason: reason, }, }) } diff --git a/pkg/model/notificationevent.proto b/pkg/model/notificationevent.proto index 5434c33b3c..7b9740550d 100644 --- a/pkg/model/notificationevent.proto +++ b/pkg/model/notificationevent.proto @@ -103,8 +103,9 @@ message NotificationEventDeploymentWaitApproval { message NotificationEventDeploymentTriggerFailed { Application application = 1 [(validate.rules).message.required = true]; - GitCommit commit = 2 [(validate.rules).message.required = true]; - string reason = 3 [(validate.rules).string.min_len = 1]; + string hash = 2 [(validate.rules).string.min_len = 1]; + string message = 3 [(validate.rules).string.min_len = 1]; + string reason = 4 [(validate.rules).string.min_len = 1]; } message NotificationEventApplicationSynced { @@ -132,8 +133,3 @@ message NotificationEventPipedStopped { string version = 3; string project_id = 4 [(validate.rules).string.min_len = 1]; } - -message GitCommit { - string hash = 4 [(validate.rules).string.min_len = 1]; - string message = 7 [(validate.rules).string.min_len = 1]; -} From 777c9f790fae84851a3a314389772cd2c8a28340 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Wed, 10 Nov 2021 11:01:28 +0900 Subject: [PATCH 10/24] Update pkg/app/piped/notifier/slack.go Co-authored-by: Le Van Nghia --- pkg/app/piped/notifier/slack.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 7868201241..f75d5ef22b 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -215,7 +215,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) case model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED: md := event.Metadata.(*model.NotificationEventDeploymentTriggerFailed) - title = "Deployment Trigger was failed" + title = fmt.Sprintf("Failed to trigger a new deployment for %s", md.Application.Name) text = md.Reason generateDeploymentEventDataForTriggerFailed(md.Application, md.Hash, md.Message) From 4d72d046223b9b0f3fd468d4b393ee18cf6cb532 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Wed, 10 Nov 2021 11:01:39 +0900 Subject: [PATCH 11/24] Update pkg/model/notificationevent.proto Co-authored-by: Le Van Nghia --- pkg/model/notificationevent.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/model/notificationevent.proto b/pkg/model/notificationevent.proto index 7b9740550d..17cd7dcf6c 100644 --- a/pkg/model/notificationevent.proto +++ b/pkg/model/notificationevent.proto @@ -103,8 +103,8 @@ message NotificationEventDeploymentWaitApproval { message NotificationEventDeploymentTriggerFailed { Application application = 1 [(validate.rules).message.required = true]; - string hash = 2 [(validate.rules).string.min_len = 1]; - string message = 3 [(validate.rules).string.min_len = 1]; + string commit_hash = 2 [(validate.rules).string.min_len = 1]; + string commit_message = 3 [(validate.rules).string.min_len = 1]; string reason = 4 [(validate.rules).string.min_len = 1]; } From 3fe1d8a4673c42eb1e1fd866588f907302428ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 11:30:13 +0900 Subject: [PATCH 12/24] Update name of fields --- pkg/app/piped/notifier/slack.go | 2 +- pkg/app/piped/trigger/deployment.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index f75d5ef22b..b389ce090d 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -217,7 +217,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) md := event.Metadata.(*model.NotificationEventDeploymentTriggerFailed) title = fmt.Sprintf("Failed to trigger a new deployment for %s", md.Application.Name) text = md.Reason - generateDeploymentEventDataForTriggerFailed(md.Application, md.Hash, md.Message) + generateDeploymentEventDataForTriggerFailed(md.Application, md.CommitHash, md.CommitMessage) case model.NotificationEventType_EVENT_PIPED_STARTED: md := event.Metadata.(*model.NotificationEventPipedStarted) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index f51fd101bb..4552e6b58c 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -188,10 +188,10 @@ func (t *Trigger) reportDeploymentFailed(app *model.Application, reason string, t.notifier.Notify(model.NotificationEvent{ Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED, Metadata: &model.NotificationEventDeploymentTriggerFailed{ - Application: app, - Hash: commit.Hash, - Message: commit.Message, - Reason: reason, + Application: app, + CommitHash: commit.Hash, + CommitMessage: commit.Message, + Reason: reason, }, }) } From 5e1668bc5769e860c06b4affc7b4b1495d57efda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 11:30:48 +0900 Subject: [PATCH 13/24] Remove the unnecessary function --- pkg/app/piped/trigger/trigger.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index 5a7ae18fb0..81c4a627fa 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -45,7 +45,6 @@ type apiClient interface { GetApplicationMostRecentDeployment(ctx context.Context, req *pipedservice.GetApplicationMostRecentDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.GetApplicationMostRecentDeploymentResponse, error) CreateDeployment(ctx context.Context, in *pipedservice.CreateDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.CreateDeploymentResponse, error) ReportApplicationMostRecentDeployment(ctx context.Context, req *pipedservice.ReportApplicationMostRecentDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.ReportApplicationMostRecentDeploymentResponse, error) - ReportDeploymentCompleted(ctx context.Context, req *pipedservice.ReportDeploymentCompletedRequest, opts ...grpc.CallOption) (*pipedservice.ReportDeploymentCompletedResponse, error) } type gitClient interface { From ff81c6f4a7fbe783eeaa069c27687c63bf47c500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 12:09:24 +0900 Subject: [PATCH 14/24] Use "git.MakeCommitURL" to make a commit link --- pkg/app/piped/notifier/BUILD.bazel | 1 + pkg/app/piped/notifier/slack.go | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/app/piped/notifier/BUILD.bazel b/pkg/app/piped/notifier/BUILD.bazel index d22de40391..1b1c45dd36 100644 --- a/pkg/app/piped/notifier/BUILD.bazel +++ b/pkg/app/piped/notifier/BUILD.bazel @@ -12,6 +12,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/config:go_default_library", + "//pkg/git:go_default_library", "//pkg/model:go_default_library", "//pkg/version:go_default_library", "@org_golang_x_sync//errgroup:go_default_library", diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index b389ce090d..be391b7d85 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -27,6 +27,7 @@ import ( "go.uber.org/zap" "github.com/pipe-cd/pipe/pkg/config" + "github.com/pipe-cd/pipe/pkg/git" "github.com/pipe-cd/pipe/pkg/model" ) @@ -152,7 +153,11 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) } } generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg string) { - link = makeCommitLink(app.GitPath, hash) + var err error + link, err = git.MakeCommitURL(app.GitPath.Repo.Remote, hash) + if err != nil { + s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err)) + } fields = []slackField{ {"Project", truncateText(app.ProjectId, 8), true}, {"Application", makeSlackLink(app.Name, fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)), true}, @@ -298,7 +303,3 @@ func getAccountsAsString(accounts []string) string { } return strings.Join(formattedAccounts, " ") } - -func makeCommitLink(gp *model.ApplicationGitPath, hash string) string { - return strings.Replace(gp.Url, fmt.Sprintf("/tree/master/%s", gp.Path), "", 1) + fmt.Sprintf("/commit/%s", hash) -} From a7b9ab31e8e5fefc1a3ab7dd783d17106228d36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 13:26:33 +0900 Subject: [PATCH 15/24] Define variable "commitURL" instead of using "link" --- pkg/app/piped/notifier/slack.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index be391b7d85..0825985487 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -153,8 +153,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) } } generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg string) { - var err error - link, err = git.MakeCommitURL(app.GitPath.Repo.Remote, hash) + commitURL, err := git.MakeCommitURL(app.GitPath.Repo.Remote, hash) if err != nil { s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err)) } @@ -162,7 +161,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) {"Project", truncateText(app.ProjectId, 8), true}, {"Application", makeSlackLink(app.Name, fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)), true}, {"Kind", strings.ToLower(app.Kind.String()), true}, - {"Commit", makeSlackLink(truncateText(msg, 8), link), true}, + {"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}, } } generatePipedEventData := func(id, name, version, project string) { From cc626c26bf8778e90c61ad917ce73f1cc40b2d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 13:38:32 +0900 Subject: [PATCH 16/24] Report failures when it fails to trigger deployment --- pkg/app/piped/trigger/deployment.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 4552e6b58c..91f7c0f195 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -51,6 +51,7 @@ func (t *Trigger) triggerDeployment( deployment, err = buildDeployment(app, branch, commit, commander, syncStrategy, time.Now(), n) if err != nil { t.logger.Error("failed to build the deployment", zap.Error(err)) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to build the deployment %v", err), commit) return } @@ -61,10 +62,12 @@ func (t *Trigger) triggerDeployment( defer func() { if err != nil { + t.reportDeploymentFailed(app, fmt.Sprintf("%v", err), commit) return } env, err := t.environmentLister.Get(ctx, deployment.EnvId) if err != nil { + t.reportDeploymentFailed(app, fmt.Sprintf("%v", err), commit) return } t.notifier.Notify(model.NotificationEvent{ @@ -85,6 +88,7 @@ func (t *Trigger) triggerDeployment( } if _, err = t.apiClient.CreateDeployment(ctx, req); err != nil { t.logger.Error("failed to create deployment", zap.Error(err)) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to create deployment %v", err), commit) return } From 6c9c67a90a8067a3f0cfdebf5f84360525184223 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Wed, 10 Nov 2021 13:38:51 +0900 Subject: [PATCH 17/24] Update pkg/app/piped/trigger/deployment.go Co-authored-by: Ryo Nakao --- pkg/app/piped/trigger/deployment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 91f7c0f195..8c4f1fcf14 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -44,7 +44,7 @@ func (t *Trigger) triggerDeployment( n, err := t.getNotification(app.GitPath) if err != nil { t.logger.Error("failed to get the list of mentions", zap.Error(err)) - t.reportDeploymentFailed(app, fmt.Sprintf("failed to get the list of mentions %v", err), commit) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to find the list of mentions from %s: %v", app.GitPath.GetDeploymentConfigFilePath(), err), commit) return } From 3956a084956df936d50e0c8e77792a6708991464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 13:48:55 +0900 Subject: [PATCH 18/24] Navigate title link to Application detail Page --- pkg/app/piped/notifier/slack.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 0825985487..43a62f07ad 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -157,9 +157,10 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) if err != nil { s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err)) } + link = makeSlackLink(app.Name, fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)) fields = []slackField{ {"Project", truncateText(app.ProjectId, 8), true}, - {"Application", makeSlackLink(app.Name, fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)), true}, + {"Application", link, true}, {"Kind", strings.ToLower(app.Kind.String()), true}, {"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}, } From 6c1c9bc73c86386e2485f1ef8d867df8a62684a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 13:59:57 +0900 Subject: [PATCH 19/24] Fix links --- pkg/app/piped/notifier/slack.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 43a62f07ad..73174b0c67 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -153,14 +153,14 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) } } generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg string) { + link = fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId) commitURL, err := git.MakeCommitURL(app.GitPath.Repo.Remote, hash) if err != nil { s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err)) } - link = makeSlackLink(app.Name, fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)) fields = []slackField{ {"Project", truncateText(app.ProjectId, 8), true}, - {"Application", link, true}, + {"Application", makeSlackLink(app.Name, link), true}, {"Kind", strings.ToLower(app.Kind.String()), true}, {"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}, } From 1829c2d074e6c528bd415554114be2d98c480663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 15:56:25 +0900 Subject: [PATCH 20/24] Fix logs --- pkg/app/piped/trigger/deployment.go | 4 ++-- pkg/app/piped/trigger/trigger.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index 8c4f1fcf14..980ca569c0 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -51,7 +51,7 @@ func (t *Trigger) triggerDeployment( deployment, err = buildDeployment(app, branch, commit, commander, syncStrategy, time.Now(), n) if err != nil { t.logger.Error("failed to build the deployment", zap.Error(err)) - t.reportDeploymentFailed(app, fmt.Sprintf("failed to build the deployment %v", err), commit) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to build the deployment: %v", err), commit) return } @@ -88,7 +88,7 @@ func (t *Trigger) triggerDeployment( } if _, err = t.apiClient.CreateDeployment(ctx, req); err != nil { t.logger.Error("failed to create deployment", zap.Error(err)) - t.reportDeploymentFailed(app, fmt.Sprintf("failed to create deployment %v", err), commit) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to create deployment: %v", err), commit) return } diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index 81c4a627fa..e87fc57184 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -233,7 +233,7 @@ func (t *Trigger) checkNewCommits(ctx context.Context) error { shouldTrigger, err := d.ShouldTrigger(ctx, app) if err != nil { t.logger.Error(fmt.Sprintf("failed to check application: %s", app.Id), zap.Error(err)) - t.reportDeploymentFailed(app, fmt.Sprintf("failed to get the list of mentions %v", err), headCommit) + t.reportDeploymentFailed(app, fmt.Sprintf("failed to find the list of mentions from %s: %v", app.GitPath.GetDeploymentConfigFilePath(), err), headCommit) continue } From 944908a2cc13f95d9ba3a7e8997dc765a9e160bd Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Wed, 10 Nov 2021 17:09:05 +0900 Subject: [PATCH 21/24] Update pkg/app/piped/notifier/slack.go Co-authored-by: Ryo Nakao --- pkg/app/piped/notifier/slack.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 73174b0c67..80b0f18693 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -153,7 +153,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) } } generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg string) { - link = fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId) + link = fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.ProjectId) commitURL, err := git.MakeCommitURL(app.GitPath.Repo.Remote, hash) if err != nil { s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err)) From 50284836c15e85fab671d293359e4003beaedbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=87=8E=20=E7=9B=B4=E4=BA=BA?= Date: Wed, 10 Nov 2021 17:29:39 +0900 Subject: [PATCH 22/24] Hide Commit field if "commitURL" is empty --- pkg/app/piped/notifier/slack.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 80b0f18693..c64d5b199b 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -158,12 +158,21 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) if err != nil { s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err)) } - fields = []slackField{ - {"Project", truncateText(app.ProjectId, 8), true}, - {"Application", makeSlackLink(app.Name, link), true}, - {"Kind", strings.ToLower(app.Kind.String()), true}, - {"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}, + if commitURL == "" { + fields = []slackField{ + {"Project", truncateText(app.ProjectId, 8), true}, + {"Application", makeSlackLink(app.Name, link), true}, + {"Kind", strings.ToLower(app.Kind.String()), true}, + } + } else { + fields = []slackField{ + {"Project", truncateText(app.ProjectId, 8), true}, + {"Application", makeSlackLink(app.Name, link), true}, + {"Kind", strings.ToLower(app.Kind.String()), true}, + {"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}, + } } + } generatePipedEventData := func(id, name, version, project string) { link = fmt.Sprintf("%s/settings/piped?project=%s", webURL, project) From 6d6df1442d1e49c9ca3d7033a6fa3cb8f3c5a55a Mon Sep 17 00:00:00 2001 From: pipecd-bot Date: Wed, 10 Nov 2021 08:31:25 +0000 Subject: [PATCH 23/24] Format unfmt-ed files --- pkg/app/piped/notifier/slack.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index c64d5b199b..077059040b 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -172,7 +172,7 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) {"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}, } } - + } generatePipedEventData := func(id, name, version, project string) { link = fmt.Sprintf("%s/settings/piped?project=%s", webURL, project) From 0f8efd10c2a9c7ab9e3344f219cf287923654a62 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Wed, 10 Nov 2021 19:40:30 +0900 Subject: [PATCH 24/24] Update pkg/app/piped/notifier/slack.go Co-authored-by: Ryo Nakao --- pkg/app/piped/notifier/slack.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index 077059040b..aba9c26890 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -158,19 +158,13 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) if err != nil { s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err)) } - if commitURL == "" { - fields = []slackField{ - {"Project", truncateText(app.ProjectId, 8), true}, - {"Application", makeSlackLink(app.Name, link), true}, - {"Kind", strings.ToLower(app.Kind.String()), true}, - } - } else { - fields = []slackField{ - {"Project", truncateText(app.ProjectId, 8), true}, - {"Application", makeSlackLink(app.Name, link), true}, - {"Kind", strings.ToLower(app.Kind.String()), true}, - {"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}, - } + fields = []slackField{ + {"Project", truncateText(app.ProjectId, 8), true}, + {"Application", makeSlackLink(app.Name, link), true}, + {"Kind", strings.ToLower(app.Kind.String()), true}, + } + if commitURL != "" { + fields = append(fields, slackField{"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true}) } }