From 290bb0f92adb171fe35f4c65b9eaf1303cf4cf29 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 14 Dec 2021 03:35:00 +0100 Subject: [PATCH] Factor out list input parsing into a function --- src/normalize_needed_jobs_status.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/normalize_needed_jobs_status.py b/src/normalize_needed_jobs_status.py index 994a028..07df075 100755 --- a/src/normalize_needed_jobs_status.py +++ b/src/normalize_needed_jobs_status.py @@ -27,14 +27,17 @@ def set_final_result_outputs(job_matrix_succeeded): set_gha_output(name='success', value=str(job_matrix_succeeded).lower()) -def parse_inputs(raw_allowed_failures, raw_jobs): - """Normalize the action inputs by turning them into data.""" +def parse_as_list(input_text): + """Parse given input as JSON or comma-separated list.""" try: - allowed_failures_input = json.loads(raw_allowed_failures) + return json.loads(input_text) except json.decoder.JSONDecodeError: - allowed_failures_input = list( - map(str.strip, raw_allowed_failures.split(',')), - ) + return [s.strip() for s in input_text.split(',')] + + +def parse_inputs(raw_allowed_failures, raw_jobs): + """Normalize the action inputs by turning them into data.""" + allowed_failures_input = parse_as_list(raw_allowed_failures) return {