From 660601ab8d5e1107d0bc1978e1fd14e39bc3731e Mon Sep 17 00:00:00 2001 From: Michael Poutre Date: Sun, 29 May 2022 19:12:30 -0700 Subject: [PATCH 1/3] feat: Validate inputs that cannot be used together --- main.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.js b/main.js index b0c43f06..5cdc8f12 100644 --- a/main.js +++ b/main.js @@ -31,6 +31,29 @@ async function main() { console.log("==> Conclusion:", workflowConclusion) + const uniqueInputSets = [ + { + "pr": pr, + "commit": commit, + "branch": branch, + "run_id": runID + }, + { + "workflow_conclusion": workflowConclusion, + "run_id": runID + } + ] + uniqueInputSets.forEach((inputSet) => { + const occurrences = Object.values(inputSet).reduce((occurrences, val) => { + if (val !== '') { + return occurrences++ + } + },0) + if(occurrences > 1) { + throw new Error(`The following inputs cannot be used together: ${Object.keys(inputSet).join(", ")}`) + } + }) + if (pr) { console.log("==> PR:", pr) From 46e94b82fc6e06c4fec73859f593683115332280 Mon Sep 17 00:00:00 2001 From: Michael Poutre Date: Tue, 31 May 2022 12:57:29 -0700 Subject: [PATCH 2/3] Fix reduce callback --- main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 5cdc8f12..80b010c7 100644 --- a/main.js +++ b/main.js @@ -46,8 +46,9 @@ async function main() { uniqueInputSets.forEach((inputSet) => { const occurrences = Object.values(inputSet).reduce((occurrences, val) => { if (val !== '') { - return occurrences++ + occurrences++ } + return occurrences },0) if(occurrences > 1) { throw new Error(`The following inputs cannot be used together: ${Object.keys(inputSet).join(", ")}`) From 8a84e0850a137fb552e7ba1b233e5e549dc4e9ee Mon Sep 17 00:00:00 2001 From: Michael Poutre Date: Tue, 31 May 2022 13:00:57 -0700 Subject: [PATCH 3/3] Simplify inputSet validation --- main.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index 80b010c7..a9869c47 100644 --- a/main.js +++ b/main.js @@ -37,20 +37,12 @@ async function main() { "commit": commit, "branch": branch, "run_id": runID - }, - { - "workflow_conclusion": workflowConclusion, - "run_id": runID } ] uniqueInputSets.forEach((inputSet) => { - const occurrences = Object.values(inputSet).reduce((occurrences, val) => { - if (val !== '') { - occurrences++ - } - return occurrences - },0) - if(occurrences > 1) { + const inputs = Object.values(inputSet) + const providedInputs = inputs.filter(input => input !== '') + if (providedInputs.length > 1) { throw new Error(`The following inputs cannot be used together: ${Object.keys(inputSet).join(", ")}`) } })