Commit a73ad50c authored by beardedwarrior's avatar beardedwarrior

added better processing of the proposal files

parent 301a6ff9
......@@ -41,7 +41,7 @@ class ProcessProposals extends Command
foreach ($files as $file) {
if (strpos($file,'.md')) {
$amount['name'] = $file;
$amount['amount'] = $this->getAmountFromText($file);
$amount['values'] = $this->getAmountFromText($file);
$amounts[] = $amount;
}
}
......@@ -52,20 +52,40 @@ class ProcessProposals extends Command
* Gets the ffs amount requested from a file
*
* @param string $filename
* @return int
* @return array
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function getAmountFromText($filename = 'additional-gui-dev.md')
{
$input = Storage::get($filename);
$lines = preg_split('/\r\n|\r|\n/', $input);
$values = [];
$flag = false;
$isPayoutLine = false;
foreach($lines as $line) {
$line = str_replace(' ','', $line);
if ($line === '---') {
if ($flag === true) {
break;
}
$flag = true;
continue;
}
$details = explode(':', $line);
if ($details[0] === 'amount') {
return $details[1];
if (count($details) < 2) {
continue;
}
if ($details[0] === 'payouts') {
$isPayoutLine = true;
continue;
}
if ($isPayoutLine) {
$name = trim(str_replace('-','', $details[0]));
$values['payouts'][][$name] = ltrim($details[1]);
continue;
}
$values[$details[0]] = ltrim($details[1]);
}
return 0;
return $values;
}
}
......@@ -38,16 +38,21 @@ class UpdateSiteProposals extends Command
*/
public function handle()
{
$ffs = json_decode(\Storage::get('_data_ffs.json'));
$ffs[0]->proposals = array_merge($ffs[0]->proposals, $this->getNewProposals());
$yaml = json_encode($ffs, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
\Storage::put('new.json', $yaml);
$response = [
$this->ideaProposals(),
$this->fundingRequiredProposals(),
$this->workInProgressProposals(),
];
$json = json_encode($response, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
\Storage::put('new.json', $json);
}
public function getNewProposals()
public function ideaProposals()
{
$group = new stdClass();
$group->stage = 'Ideas';
$responseProposals = [];
$proposals = Project::where('gitlab_state', 'opened')->get();
$proposals = Project::where('gitlab_state', 'opened')->where('state', 'IDEA')->get();
foreach ($proposals as $proposal) {
$prop = new stdClass();
$prop->name = $proposal->title;
......@@ -56,6 +61,56 @@ class UpdateSiteProposals extends Command
$prop->date = $proposal->gitlab_created_at->format('F j, Y');
$responseProposals[] = $prop;
}
return $responseProposals;
$group->proposals = $responseProposals;
return $group;
}
public function fundingRequiredProposals()
{
$group = new stdClass();
$group->stage = 'Funding Required';
$responseProposals = [];
$proposals = Project::where('gitlab_state', 'merged')->where('state', 'FUNDING-REQUIRED')->get();
foreach ($proposals as $proposal) {
$prop = new stdClass();
$prop->name = $proposal->title;
$prop->{'gitlab-url'} = $proposal->gitlab_url;
$prop->{'local-url'} = '#';
$prop->{'donate-url'} = '#';
$prop->percentage = 0;
$prop->amount = $proposal->target_amount;
$prop->{'amount-funded'} = $proposal->target_amount;
$prop->author = $proposal->gitlab_username;
$prop->date = $proposal->gitlab_created_at->format('F j, Y');
$responseProposals[] = $prop;
}
$group->proposals = $responseProposals;
return $group;
}
public function workInProgressProposals()
{
$group = new stdClass();
$group->stage = 'Work in Progress';
$responseProposals = [];
$proposals = Project::where('gitlab_state', 'merged')->where('state', 'WORK-IN-PROGRESS')->get();
foreach ($proposals as $proposal) {
$prop = new stdClass();
$prop->name = $proposal->title;
$prop->{'gitlab-url'} = $proposal->gitlab_url;
$prop->{'local-url'} = '#';
$prop->milestones = 4;
$prop->{'milestones-completed'} = 4;
$prop->{'milestones-percentage'} = 100;
$prop->percentage = 0;
$prop->amount = $proposal->target_amount;
$prop->{'amount-funded'} = $proposal->target_amount;
$prop->author = $proposal->gitlab_username;
$prop->date = $proposal->gitlab_created_at->format('F j, Y');
$responseProposals[] = $prop;
}
$group->proposals = $responseProposals;
return $group;
}
}
......@@ -20,6 +20,7 @@ class CreateProjectsTable extends Migration
$table->string('address')->nullable();
$table->string('target_amount')->nullable();
$table->string('state')->default('OPENED');
$table->string('filename')->nullable();
$table->unsignedInteger('merge_request_id')->unique();
$table->string('gitlab_username');
$table->string('gitlab_url');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment