-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from dshoreman/project-progress
- Loading branch information
Showing
21 changed files
with
567 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Servidor\Http\Controllers\Projects; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Response; | ||
use Servidor\Http\Requests\Projects\NewProjectApp; | ||
use Servidor\Projects\Application; | ||
use Servidor\Projects\Project; | ||
|
||
class CreateProjectApp extends Controller | ||
{ | ||
public function __invoke(NewProjectApp $request, Project $project): JsonResponse | ||
{ | ||
$app = new Application($request->validated()); | ||
|
||
$project->applications()->save($app); | ||
|
||
return response()->json($app, Response::HTTP_CREATED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Servidor\Http\Controllers\Projects; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Response; | ||
use Servidor\Http\Requests\Projects\NewProjectRedirect; | ||
use Servidor\Projects\Project; | ||
use Servidor\Projects\Redirect; | ||
|
||
class CreateProjectRedirect extends Controller | ||
{ | ||
public function __invoke(NewProjectRedirect $request, Project $project): JsonResponse | ||
{ | ||
$redirect = new Redirect($request->validated()); | ||
|
||
$project->redirects()->save($redirect); | ||
|
||
return response()->json($redirect, Response::HTTP_CREATED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Servidor\Http\Requests\Projects; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Validator; | ||
use Servidor\Projects\Application; | ||
use Servidor\Rules\Domain; | ||
|
||
class NewProjectApp extends FormRequest | ||
{ | ||
private const BRANCH_CMD = 'git ls-remote --heads --exit-code "%s" %s'; | ||
|
||
private const ERR_NO_REFS = "This branch doesn't exist."; | ||
private const ERR_NON_ZERO = 'Branch listing failed. Is this repo valid?'; | ||
private const ERR_NOT_FOUND = "This repo couldn't be found. Does it require auth?"; | ||
|
||
private const GIT_NO_REFS = 2; | ||
private const GIT_NOT_FOUND = 128; | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'template' => 'required|in:html,php,laravel', | ||
'domain' => [new Domain()], | ||
'provider' => 'required|in:github,bitbucket', | ||
'repository' => 'required|nullable|regex:_^([a-z-]+)/([a-z-]+)$_i', | ||
'branch' => 'nullable|string', | ||
]; | ||
} | ||
|
||
public function validated(): array | ||
{ | ||
$data = parent::validated(); | ||
|
||
return [ | ||
'template' => $data['template'], | ||
'domain_name' => $data['domain'], | ||
'source_provider' => $data['provider'], | ||
'source_repository' => $data['repository'], | ||
'source_branch' => $data['branch'] ?? '', | ||
]; | ||
} | ||
|
||
public function withValidator(Validator $validator): void | ||
{ | ||
$validator->after(function (Validator $validator): void { | ||
/** | ||
* @var array{provider: string, repository: string, branch?: string} | ||
*/ | ||
$app = $validator->getData(); | ||
|
||
if (isset($app['repository'], $app['provider'])) { | ||
$this->validateAppRepository($validator, $app); | ||
} | ||
}); | ||
} | ||
|
||
/** @param array{provider: string, repository: string, branch?: string} $app */ | ||
private function validateAppRepository(Validator $validator, array $app): void | ||
{ | ||
$branch = $app['branch'] ?? ''; | ||
$branch = $branch ? escapeshellarg($branch) : ''; | ||
$repo = Application::SOURCE_PROVIDERS[$app['provider']]; | ||
$repo = str_replace('{repo}', $app['repository'], $repo); | ||
|
||
exec(sprintf(self::BRANCH_CMD, $repo, $branch), $_, $status); | ||
|
||
if (self::GIT_NO_REFS === $status) { | ||
$validator->errors()->add('branch', self::ERR_NO_REFS); | ||
} elseif (0 !== $status) { | ||
$message = self::GIT_NOT_FOUND === $status | ||
? self::ERR_NOT_FOUND : self::ERR_NON_ZERO; | ||
|
||
$validator->errors()->add('repository', $message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Servidor\Http\Requests\Projects; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Servidor\Rules\Domain; | ||
|
||
class NewProjectRedirect extends FormRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'domain' => ['required', new Domain()], | ||
'target' => 'required|string', | ||
'type' => 'required|integer', | ||
]; | ||
} | ||
|
||
public function validated(): array | ||
{ | ||
$data = parent::validated(); | ||
|
||
$data['domain_name'] = (string) $data['domain']; | ||
unset($data['domain']); | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<template> | ||
<sui-modal size="tiny" v-model="visible"> | ||
<sui-modal-header>{{ title }}</sui-modal-header> | ||
<sui-progress attached top :percent="done" /> | ||
<sui-modal-content> | ||
<sui-list> | ||
<sui-list-item v-for="step in steps" :key="step.name"> | ||
<sui-icon :name="step.icon" color="green" size="large" /> | ||
<sui-list-content> | ||
{{ step.text }} | ||
</sui-list-content> | ||
</sui-list-item> | ||
</sui-list> | ||
</sui-modal-content> | ||
</sui-modal> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters } from 'vuex'; | ||
export default { | ||
computed: { | ||
...mapGetters({ | ||
done: 'progress/done', | ||
title: 'progress/title', | ||
steps: 'progress/steps', | ||
visible: 'progress/visible', | ||
}), | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.