/** @test */ public function it_parses_repo_name_correctly() { $repo = new Repo('ashleyhindle/rocks'); $this->assertEquals('ashleyhindle', $repo->getUsername()); $this->assertEquals('rocks', $repo->getRepoName()); $this->assertEquals('ashleyhindle/rocks', $repo->getName()); }
public function view(Request $request, $repo = false) { try { $repo = new Repo($repo); } catch (\Exception $e) { $request->session()->flash(str_random(4), ['type' => 'danger', 'message' => $e->getMessage()]); return redirect('/?ohno'); } $fullRepo = $repo->getName(); $request->session()->set('intendedRepo', $repo->getName()); $github = new Github($this->getGithubClient(), $repo); $json = $github->getFodorJson(); // TODO: Consider: should this be $repo->getFodorConfig() or getConfig or getFodorJson, and pass Github into Repo? if (empty($json)) { $request->session()->flash(str_random(4), ['type' => 'warning', 'message' => 'This repo or repo\'s fodor.json is non-existent']); return redirect(url('/')); } $fodorJson = new Config($json); try { $fodorJson->valid(); } catch (InvalidRepoException $e) { $request->session()->flash(str_random(4), ['type' => 'danger', 'message' => $e->getMessage()]); return redirect('/?ohno'); } $fodorJsonUndecoded = $fodorJson->getJson(); // string of json // Has to be less than 1mb $provisioner = $github->getFileContents($fodorJson->provisioner); if (empty($provisioner)) { $request->session()->flash(str_random(4), ['type' => 'warning', 'message' => 'This repo\'s provisioner was invalid or empty']); return redirect(url('/?ohno')); } $timeEstimate = 0; if (config('fodor.enable_time_estimates')) { $timeEstimate = \DB::select('select AVG(unix_timestamp(dateready)-unix_timestamp(datestarted)) as timeEstimate from provisions where repo=? and datestarted > ? and dateready is not null', [$fullRepo, (new \DateTime())->sub(new \DateInterval('P6M'))->format('Y-m-d H:i:s')]); $timeEstimate = $timeEstimate === null ? 0 : floor($timeEstimate[0]->timeEstimate); } return view('provision.view', ['repo' => $fullRepo, 'description' => $fodorJson->description, 'imageUrl' => $this->getValidUrl($fodorJson, 'image'), 'homepage' => $this->getValidUrl($fodorJson, 'homepage'), 'fodorJson' => $fodorJsonUndecoded, 'provisionerScript' => $provisioner, 'timeEstimate' => $timeEstimate]); }