@@ -19,28 +19,30 @@ type Workflow struct {
1919 Workflow map [string ]NodeEntry `json:"workflow,omitempty" yaml:"workflow,omitempty"`
2020 Hooks map [string ][]HookEntry `json:"hooks,omitempty" yaml:"hooks,omitempty"`
2121 // This will be filled for simple workflows
22- DependsOn []string `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`
23- Conditions * sdk.WorkflowNodeConditions `json:"conditions,omitempty" yaml:"conditions,omitempty"`
24- When []string `json:"when,omitempty" yaml:"when,omitempty"` //This is use only for manual and success condition
25- PipelineName string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"`
26- Payload map [string ]interface {} `json:"payload,omitempty" yaml:"payload,omitempty"`
27- Parameters map [string ]string `json:"parameters,omitempty" yaml:"parameters,omitempty"`
28- ApplicationName string `json:"application,omitempty" yaml:"application,omitempty"`
29- EnvironmentName string `json:"environment,omitempty" yaml:"environment,omitempty"`
30- ProjectPlatformName string `json:"platform,omitempty" yaml:"platform,omitempty"`
31- PipelineHooks []HookEntry `json:"pipeline_hooks,omitempty" yaml:"pipeline_hooks,omitempty"`
32- Permissions map [string ]int `json:"permissions,omitempty" yaml:"permissions,omitempty"`
33- Metadata map [string ]string `json:"metadata,omitempty" yaml:"metadata,omitempty" db:"-"`
34- PurgeTags []string `json:"purge_tags,omitempty" yaml:"purge_tags,omitempty" db:"-"`
35- HistoryLength int64 `json:"history_length,omitempty" yaml:"history_length,omitempty" db:"-"`
22+ DependsOn []string `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`
23+ Conditions * sdk.WorkflowNodeConditions `json:"conditions,omitempty" yaml:"conditions,omitempty"`
24+ When []string `json:"when,omitempty" yaml:"when,omitempty"` //This is used only for manual and success condition
25+ PipelineName string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"`
26+ Payload map [string ]interface {} `json:"payload,omitempty" yaml:"payload,omitempty"`
27+ Parameters map [string ]string `json:"parameters,omitempty" yaml:"parameters,omitempty"`
28+ ApplicationName string `json:"application,omitempty" yaml:"application,omitempty"`
29+ EnvironmentName string `json:"environment,omitempty" yaml:"environment,omitempty"`
30+ ProjectPlatformName string `json:"platform,omitempty" yaml:"platform,omitempty"`
31+ PipelineHooks []HookEntry `json:"pipeline_hooks,omitempty" yaml:"pipeline_hooks,omitempty"`
32+ Permissions map [string ]int `json:"permissions,omitempty" yaml:"permissions,omitempty"`
33+ Metadata map [string ]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
34+ PurgeTags []string `json:"purge_tags,omitempty" yaml:"purge_tags,omitempty"`
35+ HistoryLength * int64 `json:"history_length,omitempty" yaml:"history_length,omitempty"`
36+ Notifications []NotificationEntry `json:"notify,omitempty" yaml:"notify,omitempty"` // This is used when the workflow have only one pipeline
37+ MapNotifications map [string ][]NotificationEntry `json:"notifications,omitempty" yaml:"notifications,omitempty"` // This is used when the workflow have more than one pipeline
3638}
3739
3840// NodeEntry represents a node as code
3941type NodeEntry struct {
4042 ID int64 `json:"-" yaml:"-"`
4143 DependsOn []string `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`
4244 Conditions * sdk.WorkflowNodeConditions `json:"conditions,omitempty" yaml:"conditions,omitempty"`
43- When []string `json:"when,omitempty" yaml:"when,omitempty"` //This is use only for manual and success condition
45+ When []string `json:"when,omitempty" yaml:"when,omitempty"` //This is used only for manual and success condition
4446 PipelineName string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"`
4547 ApplicationName string `json:"application,omitempty" yaml:"application,omitempty"`
4648 EnvironmentName string `json:"environment,omitempty" yaml:"environment,omitempty"`
@@ -222,10 +224,8 @@ func NewWorkflow(w sdk.Workflow, opts ...WorkflowOptions) (Workflow, error) {
222224 }
223225 }
224226
225- if w .HistoryLength > 0 {
226- exportedWorkflow .HistoryLength = w .HistoryLength
227- } else {
228- exportedWorkflow .HistoryLength = 20
227+ if w .HistoryLength > 0 && w .HistoryLength != sdk .DefaultHistoryLength {
228+ exportedWorkflow .HistoryLength = & w .HistoryLength
229229 }
230230
231231 exportedWorkflow .PurgeTags = w .PurgeTags
@@ -296,6 +296,11 @@ func NewWorkflow(w sdk.Workflow, opts ...WorkflowOptions) (Workflow, error) {
296296 }
297297 }
298298
299+ //Notifications
300+ if err := craftNotifications (w , & exportedWorkflow ); err != nil {
301+ return exportedWorkflow , err
302+ }
303+
299304 for _ , f := range opts {
300305 if err := f (w , & exportedWorkflow ); err != nil {
301306 return exportedWorkflow , sdk .WrapError (err , "Unable to run function" )
@@ -367,6 +372,9 @@ func (w Workflow) checkValidity() error {
367372 }
368373 }
369374
375+ //Checks map notifications validity
376+ mError .Append (checkWorkflowNotificationsValidity (w ))
377+
370378 if mError .IsEmpty () {
371379 return nil
372380 }
@@ -429,8 +437,10 @@ func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
429437 wf .Metadata [k ] = v
430438 }
431439 }
432- if w .HistoryLength > 0 && w .HistoryLength != sdk .DefaultHistoryLength {
433- wf .HistoryLength = w .HistoryLength
440+ if w .HistoryLength != nil && * w .HistoryLength > 0 {
441+ wf .HistoryLength = * w .HistoryLength
442+ } else {
443+ wf .HistoryLength = sdk .DefaultHistoryLength
434444 }
435445
436446 rand .Seed (time .Now ().Unix ())
@@ -466,6 +476,11 @@ func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
466476 wf .Groups = append (wf .Groups , perm )
467477 }
468478
479+ //Compute notifications
480+ if err := w .processNotifications (wf ); err != nil {
481+ return nil , err
482+ }
483+
469484 wf .SortNode ()
470485
471486 return wf , nil
0 commit comments