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

Report conditions in embedded pipelines #67

Merged
merged 1 commit into from
Oct 17, 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
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');
}
}
}
}
};