@@ -24,6 +24,7 @@ import (
2424 "github.com/ovh/cds/engine/api/keys"
2525 "github.com/ovh/cds/engine/api/observability"
2626 "github.com/ovh/cds/engine/api/pipeline"
27+ "github.com/ovh/cds/engine/api/workflowtemplate"
2728 "github.com/ovh/cds/sdk"
2829 "github.com/ovh/cds/sdk/log"
2930)
@@ -71,6 +72,7 @@ type LoadOptions struct {
7172 WithIcon bool
7273 WithAsCodeUpdateEvent bool
7374 WithIntegrations bool
75+ WithTemplate bool
7476}
7577
7678// UpdateOptions is option to parse a workflow
@@ -587,6 +589,18 @@ func load(ctx context.Context, db gorp.SqlExecutor, proj sdk.Project, opts LoadO
587589 res .EventIntegrations = integrations
588590 }
589591
592+ if opts .WithTemplate {
593+ wti , err := workflowtemplate .LoadInstanceByWorkflowID (ctx , db , res .ID , workflowtemplate .LoadInstanceOptions .WithTemplate )
594+ if err != nil && ! sdk .ErrorIs (err , sdk .ErrNotFound ) {
595+ return nil , err
596+ }
597+ if wti != nil {
598+ res .TemplateInstance = wti
599+ res .FromTemplate = fmt .Sprintf ("%s@%d" , wti .Template .Path (), wti .WorkflowTemplateVersion )
600+ res .TemplateUpToDate = wti .Template .Version == wti .WorkflowTemplateVersion
601+ }
602+ }
603+
590604 _ , next = observability .Span (ctx , "workflow.load.loadNotifications" )
591605 notifs , errN := loadNotifications (db , & res )
592606 next ()
@@ -1256,7 +1270,7 @@ func checkProjectIntegration(proj sdk.Project, w *sdk.Workflow, n *sdk.Node) err
12561270 }
12571271 }
12581272 if ppProj .ID == 0 {
1259- return sdk .WithStack (sdk .ErrorWithData ( sdk . ErrIntegrationtNotFound , n .Context .ProjectIntegrationName ) )
1273+ return sdk .WithData (sdk .ErrIntegrationtNotFound , n .Context .ProjectIntegrationName )
12601274 }
12611275 w .ProjectIntegrations [ppProj .ID ] = ppProj
12621276 n .Context .ProjectIntegrationID = ppProj .ID
@@ -1338,7 +1352,7 @@ func checkApplication(store cache.Store, db gorp.SqlExecutor, proj sdk.Project,
13381352 appDB , err := application .LoadByName (db , proj .Key , n .Context .ApplicationName , application .LoadOptions .WithDeploymentStrategies , application .LoadOptions .WithVariables )
13391353 if err != nil {
13401354 if sdk .ErrorIs (err , sdk .ErrNotFound ) {
1341- return sdk .WithStack (sdk .ErrorWithData ( sdk . ErrNotFound , n .Context .ApplicationName ) )
1355+ return sdk .WithData (sdk .ErrNotFound , n .Context .ApplicationName )
13421356 }
13431357 return sdk .WrapError (err , "unable to load application %s" , n .Context .ApplicationName )
13441358 }
0 commit comments