diff --git a/core/controller/pipelinerun/controller.go b/core/controller/pipelinerun/controller.go index 51fc0d60..257da76d 100644 --- a/core/controller/pipelinerun/controller.go +++ b/core/controller/pipelinerun/controller.go @@ -36,6 +36,8 @@ import ( "github.com/horizoncd/horizon/pkg/config/token" envmanager "github.com/horizoncd/horizon/pkg/environment/manager" perror "github.com/horizoncd/horizon/pkg/errors" + eventmodels "github.com/horizoncd/horizon/pkg/event/models" + eventservice "github.com/horizoncd/horizon/pkg/event/service" membermanager "github.com/horizoncd/horizon/pkg/member" "github.com/horizoncd/horizon/pkg/param" prmanager "github.com/horizoncd/horizon/pkg/pr/manager" @@ -93,6 +95,7 @@ type controller struct { commitGetter code.GitGetter clusterGitRepo gitrepo.ClusterGitRepo userMgr usermanager.Manager + eventSvc eventservice.Service } var _ Controller = (*controller)(nil) @@ -113,6 +116,7 @@ func NewController(config *config.Config, param *param.Param) Controller { clusterGitRepo: param.ClusterGitRepo, userMgr: param.UserMgr, templateReleaseMgr: param.TemplateReleaseMgr, + eventSvc: param.EventSvc, } } @@ -496,7 +500,13 @@ func (c *controller) Cancel(ctx context.Context, pipelinerunID uint) error { if pr.Status != string(prmodels.StatusPending) && pr.Status != string(prmodels.StatusReady) { return perror.Wrapf(herrors.ErrParamInvalid, "pipelinerun is not pending or ready to cancel") } - return c.prMgr.PipelineRun.UpdateStatusByID(ctx, pipelinerunID, prmodels.StatusCancelled) + err = c.prMgr.PipelineRun.UpdateStatusByID(ctx, pipelinerunID, prmodels.StatusCancelled) + if err != nil { + return err + } + c.eventSvc.CreateEventIgnoreError(ctx, common.ResourcePipelinerun, pipelinerunID, + eventmodels.PipelinerunCancelled, nil) + return nil } func (c *controller) ListCheckRuns(ctx context.Context, pipelinerunID uint) ([]*prmodels.CheckRun, error) { diff --git a/pkg/event/manager/manager.go b/pkg/event/manager/manager.go index 2a456d5c..0d39e4b5 100644 --- a/pkg/event/manager/manager.go +++ b/pkg/event/manager/manager.go @@ -141,6 +141,7 @@ var supportedEvents = map[string]string{ models.MemberUpdated: "Member has been updated", models.MemberDeleted: "Member has been deleted", models.PipelinerunCreated: "New pipelinerun has been created", + models.PipelinerunCancelled: "Pipelinerun has been cancelled", } func (m *manager) ListSupportEvents() map[string]string { diff --git a/pkg/event/models/event.go b/pkg/event/models/event.go index 13e2389b..d9d0cfda 100644 --- a/pkg/event/models/event.go +++ b/pkg/event/models/event.go @@ -42,6 +42,7 @@ const ( MemberUpdated string = "members_updated" MemberDeleted string = "members_deleted" PipelinerunCreated string = "pipelineruns_created" + PipelinerunCancelled string = "pipelineruns_cancelled" // TODO: add group events )