From d2c1c4c113ce32e48317012a00fdf3fa30b53107 Mon Sep 17 00:00:00 2001 From: Kevin Dice Date: Mon, 27 Sep 2021 15:13:32 -0600 Subject: [PATCH 1/4] fix(#31): preserve skipped steps to avoid Drone DAG reference errors --- plugin.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugin.js b/plugin.js index 94bd2a0..c825b46 100644 --- a/plugin.js +++ b/plugin.js @@ -58,15 +58,26 @@ app.post('/', bodyParser.json({limit: '50mb'}), async (req, res) => { } } - const trimmedSteps = py.steps.filter(s => { + const transformedSteps = py.steps.map(s => { if (!s.when || !s.when.changeset || !s.when.changeset.includes) return true const requiredFiles = s.when.changeset.includes const matchedFiles = glob.match(requiredFiles, filesChanged, { dot: true }) console.log('Matched files for step:', matchedFiles.length, 'Allowed matches:', requiredFiles) - return matchedFiles.length + + if (matchedFiles.length) { + // Allow it through unchanged + return s; + } else { + // Add an impossible conditional which guarantees the step gets skipped + s.when = { + ...s.when, + event: { exclude: ['*']}, + } + return s; + } }) - return trimmedSteps.length ? yaml.stringify({ ...py, steps: trimmedSteps }) : nullYaml(index) + return transformedSteps.length ? yaml.stringify({ ...py, steps: transformedSteps }) : nullYaml(index) }) res.json({ Data: finalYamlDocs.join('\n---\n') }) From 51aa1fdf421a0dc54bfd10954ec7cb627f1655ca Mon Sep 17 00:00:00 2001 From: Kevin Dice Date: Mon, 27 Sep 2021 15:19:32 -0600 Subject: [PATCH 2/4] fix: simplify --- plugin.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugin.js b/plugin.js index c825b46..aac23e9 100644 --- a/plugin.js +++ b/plugin.js @@ -64,17 +64,15 @@ app.post('/', bodyParser.json({limit: '50mb'}), async (req, res) => { const matchedFiles = glob.match(requiredFiles, filesChanged, { dot: true }) console.log('Matched files for step:', matchedFiles.length, 'Allowed matches:', requiredFiles) - if (matchedFiles.length) { - // Allow it through unchanged - return s; - } else { + if (!matchedFiles.length) { // Add an impossible conditional which guarantees the step gets skipped s.when = { ...s.when, event: { exclude: ['*']}, } - return s; } + + return s; }) return transformedSteps.length ? yaml.stringify({ ...py, steps: transformedSteps }) : nullYaml(index) From 567ff8f96911604f36234da2285abb2a79b83c10 Mon Sep 17 00:00:00 2001 From: Kevin Dice Date: Mon, 27 Sep 2021 15:20:40 -0600 Subject: [PATCH 3/4] fix: case where no changeset was defined --- plugin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin.js b/plugin.js index aac23e9..a041d2f 100644 --- a/plugin.js +++ b/plugin.js @@ -59,7 +59,10 @@ app.post('/', bodyParser.json({limit: '50mb'}), async (req, res) => { } const transformedSteps = py.steps.map(s => { - if (!s.when || !s.when.changeset || !s.when.changeset.includes) return true + if (!s.when || !s.when.changeset || !s.when.changeset.includes) { + return s; + } + const requiredFiles = s.when.changeset.includes const matchedFiles = glob.match(requiredFiles, filesChanged, { dot: true }) console.log('Matched files for step:', matchedFiles.length, 'Allowed matches:', requiredFiles) From 455305dae7d14c1ecea651fcff4de91fd1a57591 Mon Sep 17 00:00:00 2001 From: Kevin Dice Date: Mon, 27 Sep 2021 15:21:44 -0600 Subject: [PATCH 4/4] fix: spacing --- plugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.js b/plugin.js index a041d2f..38b2d06 100644 --- a/plugin.js +++ b/plugin.js @@ -62,7 +62,7 @@ app.post('/', bodyParser.json({limit: '50mb'}), async (req, res) => { if (!s.when || !s.when.changeset || !s.when.changeset.includes) { return s; } - + const requiredFiles = s.when.changeset.includes const matchedFiles = glob.match(requiredFiles, filesChanged, { dot: true }) console.log('Matched files for step:', matchedFiles.length, 'Allowed matches:', requiredFiles) @@ -71,7 +71,7 @@ app.post('/', bodyParser.json({limit: '50mb'}), async (req, res) => { // Add an impossible conditional which guarantees the step gets skipped s.when = { ...s.when, - event: { exclude: ['*']}, + event: { exclude: ['*'] }, } }