Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(2331): Warn when trying to override locked step #27

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ function merge(newJob, oldJob, fromTemplate) {
step = { [stepName]: oldSteps[stepName] };
} else if (stepLocked || Hoek.reach(newSteps, stepName)) {
step = { [stepName]: newSteps[stepName] };
if (stepLocked && Hoek.reach(oldSteps, stepName)) {
// eslint-disable-next-line max-len
warnings = warnings.concat(`Cannot override locked step ${stepName}; using step definition from template ${oldJob.template}`);
}
} else {
warnings = warnings.concat(`${stepName} step definition not found; skipping`);
}
Expand Down Expand Up @@ -162,9 +166,15 @@ function merge(newJob, oldJob, fromTemplate) {
mergedSteps.push({ [preStepName]: oldSteps[preStepName] });
}

const stepLocked = Hoek.reach(newJob.steps[i][stepName], 'locked');

// If template step is locked or user doesn't define the same step, add it
if (Hoek.reach(newJob.steps[i][stepName], 'locked') || !oldSteps[stepName]) {
if (stepLocked || !oldSteps[stepName]) {
mergedSteps.push(newJob.steps[i]);
if (stepLocked && oldSteps[stepName]) {
// eslint-disable-next-line max-len
warnings = warnings.concat(`Cannot override locked step ${stepName}; using step definition from template ${oldJob.template}`);
}
} else if (!stepName.startsWith('teardown-')) {
// If user defines the same step, only add if it's not teardown and not locked
// otherwise, skip (it will be overwritten later, otherwise will get duplicate steps)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
"Tiffany Kyi <[email protected]>"
],
"devDependencies": {
"chai": "^4.2.0",
"chai": "^4.3.0",
"eslint": "^4.19.1",
"eslint-config-screwdriver": "^3.0.0",
"mocha": "^8.2.1",
"mocha": "^8.3.0",
"mocha-multi-reporters": "^1.5.1",
"mocha-sonarqube-reporter": "^1.0.2",
"nyc": "^15.0.0",
"sinon": "^9.2.4"
},
"dependencies": {
"@hapi/hoek": "^9.0.4",
"joi": "^17.1.1",
"joi": "^17.4.0",
"js-yaml": "^3.12.1",
"screwdriver-data-schema": "^21.2.0"
"screwdriver-data-schema": "^21.2.4"
},
"release": {
"debug": false,
Expand Down
1 change: 1 addition & 0 deletions test/data/valid_order_and_locked_step_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"version": "1.2.3"
},
"warnMessages": [
"Cannot override locked step security; using step definition from template template_namespace/parent@1",
"blah step definition not found; skipping",
"meow step definition not found; skipping"
]
Expand Down
5 changes: 4 additions & 1 deletion test/data/valid_parent_and_locked_step_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@
"maintainer": "[email protected]",
"name": "template_namespace/child",
"version": "1.2.3"
}
},
"warnMessages": [
"Cannot override locked step security; using step definition from template template_namespace/parent@1"
]
}