@@ -19,6 +19,7 @@ package client
1919import (
2020 "context"
2121 "fmt"
22+ repository4 "github.com/devtron-labs/devtron/pkg/cluster/repository"
2223 "strings"
2324 "time"
2425
@@ -35,7 +36,7 @@ import (
3536)
3637
3738type EventFactory interface {
38- Build (eventType util.EventType , sourceId * int , appId int , envId * int , pipelineType util.PipelineType ) Event
39+ Build (eventType util.EventType , sourceId * int , appId int , envId * int , pipelineType util.PipelineType ) ( Event , error )
3940 BuildExtraCDData (event Event , wfr * pipelineConfig.CdWorkflowRunner , pipelineOverrideId int , stage bean2.WorkflowType ) Event
4041 BuildExtraCIData (event Event , material * MaterialTriggerInfo ) Event
4142 //BuildFinalData(event Event) *Payload
@@ -50,14 +51,15 @@ type EventSimpleFactoryImpl struct {
5051 ciPipelineRepository pipelineConfig.CiPipelineRepository
5152 pipelineRepository pipelineConfig.PipelineRepository
5253 userRepository repository.UserRepository
54+ envRepository repository4.EnvironmentRepository
5355 ciArtifactRepository repository2.CiArtifactRepository
5456}
5557
5658func NewEventSimpleFactoryImpl (logger * zap.SugaredLogger , cdWorkflowRepository pipelineConfig.CdWorkflowRepository ,
5759 pipelineOverrideRepository chartConfig.PipelineOverrideRepository , ciWorkflowRepository pipelineConfig.CiWorkflowRepository ,
5860 ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository ,
5961 ciPipelineRepository pipelineConfig.CiPipelineRepository , pipelineRepository pipelineConfig.PipelineRepository ,
60- userRepository repository.UserRepository , ciArtifactRepository repository2.CiArtifactRepository ) * EventSimpleFactoryImpl {
62+ userRepository repository.UserRepository , envRepository repository4. EnvironmentRepository , ciArtifactRepository repository2.CiArtifactRepository ) * EventSimpleFactoryImpl {
6163 return & EventSimpleFactoryImpl {
6264 logger : logger ,
6365 cdWorkflowRepository : cdWorkflowRepository ,
@@ -68,10 +70,11 @@ func NewEventSimpleFactoryImpl(logger *zap.SugaredLogger, cdWorkflowRepository p
6870 pipelineRepository : pipelineRepository ,
6971 userRepository : userRepository ,
7072 ciArtifactRepository : ciArtifactRepository ,
73+ envRepository : envRepository ,
7174 }
7275}
7376
74- func (impl * EventSimpleFactoryImpl ) Build (eventType util.EventType , sourceId * int , appId int , envId * int , pipelineType util.PipelineType ) Event {
77+ func (impl * EventSimpleFactoryImpl ) Build (eventType util.EventType , sourceId * int , appId int , envId * int , pipelineType util.PipelineType ) ( Event , error ) {
7578 correlationId := uuid .NewV4 ()
7679 event := Event {}
7780 event .EventTypeId = int (eventType )
@@ -80,12 +83,19 @@ func (impl *EventSimpleFactoryImpl) Build(eventType util.EventType, sourceId *in
8083 }
8184 event .AppId = appId
8285 if envId != nil {
86+ env , err := impl .envRepository .FindById (* envId )
87+ if err != nil {
88+ impl .logger .Errorw ("error in getting env" , "envId" , * envId , "err" , err )
89+ return event , err
90+ }
8391 event .EnvId = * envId
92+ event .ClusterId = env .ClusterId
93+ event .IsProdEnv = env .Default
8494 }
8595 event .PipelineType = string (pipelineType )
8696 event .CorrelationId = fmt .Sprintf ("%s" , correlationId )
8797 event .EventTime = time .Now ().Format (bean .LayoutRFC3339 )
88- return event
98+ return event , nil
8999}
90100
91101func (impl * EventSimpleFactoryImpl ) BuildExtraCDData (event Event , wfr * pipelineConfig.CdWorkflowRunner , pipelineOverrideId int , stage bean2.WorkflowType ) Event {
0 commit comments