From 07c93fddec28089cb6453f9c1b09c40b7065a7f8 Mon Sep 17 00:00:00 2001 From: Tamas Muncsan Date: Sun, 17 Oct 2021 13:27:41 +0200 Subject: [PATCH] fix: report `conditions` in embedded pipelines --- .../__snapshots__/regresion.test.js.snap | 16 ++++++++++++++++ src/rules/prefer-when-expression.ts | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/regression-tests/__snapshots__/regresion.test.js.snap b/regression-tests/__snapshots__/regresion.test.js.snap index 7baa1d8..029d4c8 100644 --- a/regression-tests/__snapshots__/regresion.test.js.snap +++ b/regression-tests/__snapshots__/regresion.test.js.snap @@ -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 { diff --git a/src/rules/prefer-when-expression.ts b/src/rules/prefer-when-expression.ts index 68a0eea..4970467 100644 --- a/src/rules/prefer-when-expression.ts +++ b/src/rules/prefer-when-expression.ts @@ -7,4 +7,18 @@ export default (docs, tekton, report) => { } } } + + for (const triggerTemplate of Object.values(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'); + } + } + } + } };