8000 feat(api,ui): add custom step name (#3259) · ovh/cds@a209ade · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit a209ade

Browse files
bnjjjyesnault
authored andcommitted
feat(api,ui): add custom step name (#3259)
close #1408 Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
1 parent 919dc31 commit a209ade

File tree

17 files changed

+149
-40
lines changed

17 files changed

+149
-40
lines changed

engine/api/action/children.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"github.com/ovh/cds/sdk/log"
1111
)
1212

13-
func insertEdge(db gorp.SqlExecutor, parentID, childID int64, execOrder int, optional, alwaysExecuted, enabled bool) (int64, error) {
14-
query := `INSERT INTO action_edge (parent_id, child_id, exec_order, optional, always_executed, enabled) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id`
13+
func insertEdge(db gorp.SqlExecutor, parentID, childID int64, execOrder int, stepName string, optional, alwaysExecuted, enabled bool) (int64, error) {
14+
query := `INSERT INTO action_edge (parent_id, child_id, exec_order, step_name, optional, always_executed, enabled) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id`
1515

1616
var id int64
17-
err := db.QueryRow(query, parentID, childID, execOrder, optional, alwaysExecuted, enabled).Scan(&id)
17+
err := db.QueryRow(query, parentID, childID, execOrder, stepName, optional, alwaysExecuted, enabled).Scan(&id)
1818
if err != nil {
1919
return 0, err
2020
}
@@ -27,7 +27,12 @@ func insertActionChild(db gorp.SqlExecutor, actionID int64, child sdk.Action, ex
2727
return fmt.Errorf("insertActionChild: child action has no id")
2828
}
2929

30-
id, err := insertEdge(db, actionID, child.ID, execOrder, child.Optional, child.AlwaysExecuted, child.Enabled)
30+
//Useful to not save a step_name if it's the same than the default name (for ascode)
31+
if strings.ToLower(child.Name) == strings.ToLower(child.StepName) {
32+
child.StepName = ""
33+
}
34+
35+
id, err := insertEdge(db, actionID, child.ID, execOrder, child.StepName, child.Optional, child.AlwaysExecuted, child.Enabled)
3136
if err != nil {
3237
return err
3338
}
@@ -54,7 +59,7 @@ func insertChildActionParameter(db gorp.SqlExecutor, edgeID, parentID, childID i
5459
name,
5560
type,
5661
value,
57-
description,
62+
description,
5863
advanced) VALUES ($1, $2, $3, $4, $5, $6)`
5964

6065
if _, err := db.Exec(query, edgeID, param.Name, string(param.Type), param.Value, param.Description, param.Advanced); err != nil {
@@ -68,7 +73,7 @@ func loadActionChildren(db gorp.SqlExecutor, actionID int64) ([]sdk.Action, erro
6873
var children []sdk.Action
6974
var edgeIDs []int64
7075
var childrenIDs []int64
71-
query := `SELECT id, child_id, exec_order, optional, always_executed, enabled FROM action_edge WHERE parent_id = $1 ORDER BY exec_order ASC`
76+
query := `SELECT id, child_id, exec_order, step_name, optional, always_executed, enabled FROM action_edge WHERE parent_id = $1 ORDER BY exec_order ASC`
7277

7378
rows, err := db.Query(query, actionID)
7479
if err != nil {
@@ -78,18 +83,21 @@ func loadActionChildren(db gorp.SqlExecutor, actionID int64) ([]sdk.Action, erro
7883

7984
var edgeID, childID int64
8085
var execOrder int
86+
var stepName string
8187
var optional, alwaysExecuted, enabled bool
88+
var mapStepName = make(map[int64]string)
8289
var mapOptional = make(map[int64]bool)
8390
var mapAlwaysExecuted = make(map[int64]bool)
8491
var mapEnabled = make(map[int64]bool)
8592

8693
for rows.Next() {
87-
err = rows.Scan(&edgeID, &childID, &execOrder, &optional, &alwaysExecuted, &enabled)
94+
err = rows.Scan(&edgeID, &childID, &execOrder, &stepName, &optional, &alwaysExecuted, &enabled)
8895
if err != nil {
8996
return nil, err
9097
}
9198
edgeIDs = append(edgeIDs, edgeID)
9299
childrenIDs = append(childrenIDs, childID)
100+
mapStepName[edgeID] = stepName
93101
mapOptional[edgeID] = optional
94102
mapAlwaysExecuted[edgeID] = alwaysExecuted
95103
mapEnabled[edgeID] = enabled
@@ -114,6 +122,7 @@ func loadActionChildren(db gorp.SqlExecutor, actionID int64) ([]sdk.Action, erro
114122
// If child action has been modified, new parameters will show
115123
// and delete one won't be there anymore
116124
replaceChildActionParameters(&children[i], params)
125+
children[i].StepName = mapStepName[edgeIDs[i]]
117126
// Get optional & always_executed flags
118127
children[i].Optional = mapOptional[edgeIDs[i]]
119128
children[i].AlwaysExecuted = mapAlwaysExecuted[edgeIDs[i]]

engine/api/pipeline/pipeline_action.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ func UpdateJob(db gorp.SqlExecutor, job *sdk.Job, userID int64) error {
118118
return sdk.ErrForbidden
119119
}
120120

121-
query := `UPDATE pipeline_action set action_id=$1, pipeline_stage_id=$2, enabled=$4 WHERE id=$3`
122-
_, err = db.Exec(query, job.Action.ID, job.PipelineStageID, job.PipelineActionID, job.Enabled)
123-
if err != nil {
121+
if err := UpdatePipelineAction(db, *job); err != nil {
124122
return err
125123
}
126124
job.Action.Enabled = job.Enabled
@@ -134,10 +132,8 @@ func DeleteJob(db gorp.SqlExecutor, job sdk.Job, userID int64) error {
134132

135133
// UpdatePipelineAction Update an action in a pipeline
136134
func UpdatePipelineAction(db gorp.SqlExecutor, job sdk.Job) error {
137-
query := `UPDATE pipeline_action set action_id=$1, pipeline_stage_id=$2, enabled=$4 WHERE id=$3`
138-
139-
_, err := db.Exec(query, job.Action.ID, job.PipelineStageID, job.PipelineActionID, job.Enabled)
140-
if err != nil {
135+
query := `UPDATE pipeline_action set action_id=$1, pipeline_stage_id=$2, enabled=$3 WHERE id=$4`
136+
if _, err := db.Exec(query, job.Action.ID, job.PipelineStageID, job.Enabled, job.PipelineActionID); err != nil {
141137
return err
142138
}
143139

engine/api/pipeline/pipeline_stage.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,21 @@ func LoadPipelineStage(ctx context.Context, db gorp.SqlExecutor, p *sdk.Pipeline
104104
}
105105

106106
query := `
107-
SELECT pipeline_stage_R.id as stage_id, pipeline_stage_R.pipeline_id, pipeline_stage_R.name, pipeline_stage_R.last_modified,
107+
SELECT pipeline_stage_R.id as stage_id, pipeline_stage_R.pipeline_id, pipeline_stage_R.name, pipeline_stage_R.last_modified,
108108
pipeline_stage_R.build_order, pipeline_stage_R.enabled, pipeline_stage_R.parameter,
109109
pipeline_stage_R.expected_value, pipeline_action_R.id as pipeline_action_id, pipeline_action_R.action_id, pipeline_action_R.action_last_modified,
110110
pipeline_action_R.action_args, pipeline_action_R.action_enabled
111111
FROM (
112-
SELECT pipeline_stage.id, pipeline_stage.pipeline_id,
113-
pipeline_stage.name, pipeline_stage.last_modified ,pipeline_stage.build_order,
112+
SELECT pipeline_stage.id, pipeline_stage.pipeline_id,
113+
pipeline_stage.name, pipeline_stage.last_modified, pipeline_stage.build_order,
114114
pipeline_stage.enabled,
115115
pipeline_stage_prerequisite.parameter, pipeline_stage_prerequisite.expected_value
116116
FROM pipeline_stage
117117
LEFT OUTER JOIN pipeline_stage_prerequisite ON pipeline_stage.id = pipeline_stage_prerequisite.pipeline_stage_id
118118
WHERE pipeline_id = $1
119119
) as pipeline_stage_R
120120
LEFT OUTER JOIN (
121-
SELECT pipeline_action.id, action.id as action_id, action.name as action_name, action.last_modified as action_last_modified,
121+
SELECT pipeline_action.id, action.id as action_id, action.name as action_name, action.last_modified as action_last_modified,
122122
pipeline_action.args as action_args, pipeline_action.enabled as action_enabled,
123123
pipeline_action.pipeline_stage_id
124124
FROM action

engine/api/workflow/process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func processWorkflowNodeRun(ctx context.Context, db gorp.SqlExecutor, store cach
623623
// Tag VCS infos : add in tag only if it does not exist
624624
if !w.TagExists(tagGitRepository) {
625625
w.Tag(tagGitRepository, run.VCSRepository)
626-
if run.VCSBranch != "" {
626+
if run.VCSBranch != "" && run.VCSTag == "" {
627627
w.Tag(tagGitBranch, run.VCSBranch)
628628
}
629629
if run.VCSTag != "" {

engine/api/workflow/resync_workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func ResyncNodeRunsWithCommits(ctx context.Context, db gorp.SqlExecutor, store c
135135
}
136136

137137
tagsUpdated := false
138-
if curVCSInfos.Branch != "" {
138+
if curVCSInfos.Branch != "" && curVCSInfos.Tag == "" {
139139
tagsUpdated = wr.Tag(tagGitBranch, curVCSInfos.Branch)
140140
}
141141
if curVCSInfos.Hash != "" {

engine/sql/123_action_custom_name.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- +migrate Up
2+
ALTER TABLE action_edge ADD COLUMN step_name TEXT DEFAULT '';
3+
4+
-- +migrate Down
5+
ALTER TABLE action_edge DROP COLUMN step_name;

sdk/action.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
type Action struct {
1111
ID int64 `json:"id" yaml:"-"`
1212
Name string `json:"name" cli:"name"`
13+
StepName string `json:"step_name,omitempty" yaml:"step_name,omitempty" cli:"step_name"`
1314
Type string `json:"type" yaml:"-" cli:"type"`
1415
Description string `json:"description" yaml:"desc,omitempty"`
1516
Requirements []Requirement `json:"requirements"`

sdk/exportentities/action.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func newSteps(a sdk.Action) []Step {
6262
for i := range a.Actions {
6363
act := &a.Actions[i]
6464
s := Step{}
65+
if act.StepName != "" {
66+
s["name"] = act.StepName
67+
}
6568
if !act.Enabled {
6669
s["enabled"] = act.Enabled
6770
}
@@ -267,6 +270,10 @@ func (s Step) AsScript() (*sdk.Action, bool, error) {
267270
a := sdk.NewStepScript(bS)
268271

269272
var err error
273+
a.StepName, err = s.Name()
274+
if err != nil {
275+
return nil, true, err
276+
}
270277
a.Enabled, err = s.IsFlagged("enabled")
271278
if err != nil {
272279
return nil, true, err
@@ -311,6 +318,10 @@ func (s Step) AsAction() (*sdk.Action, bool, error) {
311318
}
312319

313320
a.Enabled, err = s.IsFlagged("enabled")
321+
a.StepName, err = s.Name()
322+
if err != nil {
323+
return nil, true, err
324+
}
314325
if err != nil {
315326
return nil, true, err
316327
}
@@ -344,6 +355,10 @@ func (s Step) AsJUnitReport() (*sdk.Action, bool, error) {
344355
a := sdk.NewStepJUnitReport(bS)
345356

346357
var err error
358+
a.StepName, err = s.Name()
359+
if err != nil {
360+
return nil, true, err
361+
}
347362
a.Enabled, err = s.IsFlagged("enabled")
348363
if err != nil {
349364
return nil, true, err
@@ -383,6 +398,10 @@ func (s Step) AsGitClone() (*sdk.Action, bool, error) {
383398
a := sdk.NewStepGitClone(argss)
384399

385400
var err error
401+
a.StepName, err = s.Name()
402+
if err != nil {
403+
return nil, true, err
404+
}
386405
a.Enabled, err = s.IsFlagged("enabled")
387406
if err != nil {
388407
return nil, true, err
@@ -428,6 +447,10 @@ func (s Step) AsArtifactUpload() (*sdk.Action, bool, error) {
428447
}
429448

430449
var err error
450+
a.StepName, err = s.Name()
451+
if err != nil {
452+
return nil, true, err
453+
}
431454
a.Enabled, err = s.IsFlagged("enabled")
432455
if err != nil {
433456
return nil, true, err
@@ -462,6 +485,10 @@ func (s Step) AsArtifactDownload() (*sdk.Action, bool, error) {
462485
a := sdk.NewStepArtifactDownload(argss)
463486

464487
var err error
488+
a.StepName, err = s.Name()
489+
if err != nil {
490+
return nil, true, err
491+
}
465492
a.Enabled, err = s.IsFlagged("enabled")
466493
if err != nil {
467494
return nil, true, err
@@ -495,6 +522,10 @@ func (s Step) AsCheckoutApplication() (*sdk.Action, bool, error) {
495522
a := sdk.NewCheckoutApplication(bS)
496523

497524
var err error
525+
a.StepName, err = s.Name()
526+
if err != nil {
527+
return nil, true, err
528+
}
498529
a.Enabled, err = s.IsFlagged("enabled")
499530
if err != nil {
500531
return nil, true, err
@@ -528,6 +559,10 @@ func (s Step) AsCoverageAction() (*sdk.Action, bool, error) {
528559
a := sdk.NewCoverage(argss)
529560

530561
var err error
562+
a.StepName, err = s.Name()
563+
if err != nil {
564+
return nil, true, err
565+
}
531566
a.Enabled, err = s.IsFlagged("enabled")
532567
if err != nil {
533568
return nil, true, err
@@ -561,6 +596,10 @@ func (s Step) AsDeployApplication() (*sdk.Action, bool, error) {
561596
a := sdk.NewDeployApplication(bS)
562597

563598
var err error
599+
a.StepName, err = s.Name()
600+
if err != nil {
601+
return nil, true, err
602+
}
564603
a.Enabled, err = s.IsFlagged("enabled")
565604
if err != nil {
566605
return nil, true, err
@@ -591,6 +630,18 @@ func (s Step) IsFlagged(flag string) (bool, error) {
591630
return bS, nil
592631
}
593632

633+
// Name returns true the step name if exist
634+
func (s Step) Name() (string, error) {
635+
if stepAttr, ok := s["name"]; ok {
636+
if stepName, okName := stepAttr.(string); okName {
637+
return stepName, nil
638+
} else {
639+
return "", fmt.Errorf("Malformatted Step : name must be a string")
640+
}
641+
}
642+
return "", nil
643+
}
644+
594645
// Action returns an sdk.Action
595646
func (act *Action) Action() (*sdk.Action, error) {
596647
a := new(sdk.Action)

sdk/exportentities/pipeline.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Step map[string]interface{}
6868
func (s Step) IsValid() bool {
6969
keys := []string{}
7070
for k := range s {
71-
if k != "enabled" && k != "optional" && k != "always_executed" {
71+
if k != "enabled" && k != "optional" && k != "always_executed" && k != "name" {
7272
keys = append(keys, k)
7373
}
7474
}
@@ -78,7 +78,7 @@ func (s Step) IsValid() bool {
7878
func (s Step) key() string {
7979
keys := []string{}
8080
for k := range s {
81-
if k != "enabled" && k != "optional" && k != "always_executed" {
81+
if k != "enabled" && k != "optional" && k != "always_executed" && k != "name" {
8282
keys = append(keys, k)
8383
}
8484
}

sdk/workflow_run_easyjson.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0