Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/app/piped/notifier/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/trigger/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions pkg/app/piped/trigger/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -183,6 +185,21 @@ func buildDeployment(
return deployment, nil
}

func (t *Trigger) reportDeploymentFailed(ctx context.Context, reason string) {
Comment thread
ono-max marked this conversation as resolved.
Outdated
defer func() {
t.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_PIPED_FAILED,
Comment thread
ono-max marked this conversation as resolved.
Outdated
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]
Expand Down
5 changes: 5 additions & 0 deletions pkg/app/piped/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
ono-max marked this conversation as resolved.
Outdated
}

type gitClient interface {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/model/notificationevent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum NotificationEventType {

EVENT_PIPED_STARTED = 300;
EVENT_PIPED_STOPPED = 301;
EVENT_PIPED_FAILED = 302;

}

Expand Down Expand Up @@ -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;
}