Skip to content

Commit

Permalink
fix: add event for pr cancelled
Browse files Browse the repository at this point in the history
Signed-off-by: xu.zhu <xu.zhu.work@outlook.com>
  • Loading branch information
xuzhu-591 committed Oct 19, 2023
1 parent c718945 commit 4f2b1ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/controller/pipelinerun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -93,6 +95,7 @@ type controller struct {
commitGetter code.GitGetter
clusterGitRepo gitrepo.ClusterGitRepo
userMgr usermanager.Manager
eventSvc eventservice.Service
}

var _ Controller = (*controller)(nil)
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions pkg/event/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/event/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit 4f2b1ad

Please sign in to comment.