From f856d4fb7c149c30d143841c2cd748856045ed23 Mon Sep 17 00:00:00 2001 From: xiphon Date: Mon, 28 Jan 2019 11:43:38 +0000 Subject: [PATCH] reject proposal if any mandatoriy field is missing or empty in .md --- app/Console/Commands/ProcessProposals.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/ProcessProposals.php b/app/Console/Commands/ProcessProposals.php index 17b4492..62ab2f4 100644 --- a/app/Console/Commands/ProcessProposals.php +++ b/app/Console/Commands/ProcessProposals.php @@ -62,6 +62,14 @@ class ProcessProposals extends Command private const layoutToState = [ 'fr' => 'FUNDING-REQUIRED', 'wip' => 'WORK-IN-PROGRESS', 'cp' => 'COMPLETED']; + + private const mandatoryFields = [ 'amount', + 'author', + 'date', + 'layout', + 'milestones', + 'title']; + /** * Execute the console command. */ @@ -81,6 +89,12 @@ class ProcessProposals extends Command $detail['name'] = $filename; $detail['values'] = $this->getAmountFromText($file); + foreach ($this::mandatoryFields as $field) { + if (empty($detail['values'][$field])) { + throw new \Exception("Mandatory field $field is missing"); + } + } + $amount = floatval(str_replace(",", ".", $detail['values']['amount'])); $author = htmlspecialchars($detail['values']['author'], ENT_QUOTES); $date = strtotime($detail['values']['date']); @@ -133,7 +147,7 @@ class ProcessProposals extends Command { $contents = preg_split('/\r?\n?---\r?\n/m', Storage::get($filename)); if (sizeof($contents) < 3) { - throw new \Exception("Failed to parse proposal, can't find YAML description surrounded by '---' lines"); + throw new \Exception("Failed to parse proposal, can't find YAML description surrounded by '---' lines"); } return Yaml::parse($contents[1]); } -- GitLab