Skip to content

Commit

Permalink
fix: report conditions in embedded pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas Muncsan authored and madbence committed Oct 17, 2021
1 parent 151ff2c commit 1c90fbc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions regression-tests/__snapshots__/regresion.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,22 @@ Array [
"path": "./regression-tests/prefer-when-expression.yaml",
"rule": "no-missing-resource",
},
Object {
"level": "warning",
"loc": Object {
"endColumn": 13,
"endLine": 35,
"range": Array [
676,
714,
],
"startColumn": 17,
"startLine": 34,
},
"message": "Task 'task-1' in PipelineRun 'prefer-when-expression-run' is guarded by condition(s) ('condition'). Conditions are deprecated, use WhenExpressions instead.",
"path": "./regression-tests/prefer-when-expression.yaml",
"rule": "prefer-when-expression",
},
Object {
"level": "error",
"loc": Object {
Expand Down
14 changes: 14 additions & 0 deletions src/rules/prefer-when-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ export default (docs, tekton, report) => {
}
}
}

for (const triggerTemplate of Object.values<any>(tekton.triggerTemplates)) {
for (const crd of triggerTemplate.spec.resourcetemplates) {
if (crd.kind !== 'PipelineRun') continue;
const pipelineSpec = crd.spec.pipelineSpec;
if (!pipelineSpec || !pipelineSpec.tasks) continue;
for (const task of pipelineSpec.tasks) {
if (task.conditions) {
const guardedBy = task.conditions.map(condition => condition.conditionRef);
report(`Task '${task.name}' in PipelineRun '${crd.metadata.name}' is guarded by condition(s) ('${guardedBy.join(', ')}'). Conditions are deprecated, use WhenExpressions instead.`, task, 'conditions');
}
}
}
}
};

0 comments on commit 1c90fbc

Please sign in to comment.