Refactor manual webhook handling and add watch path check
This commit is contained in:
parent
b7121c5000
commit
f13fc737f1
@ -22,7 +22,6 @@ class Github extends Controller
|
|||||||
public function manual(Request $request)
|
public function manual(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
ray($request);
|
|
||||||
$return_payloads = collect([]);
|
$return_payloads = collect([]);
|
||||||
$x_github_delivery = request()->header('X-GitHub-Delivery');
|
$x_github_delivery = request()->header('X-GitHub-Delivery');
|
||||||
if (app()->isDownForMaintenance()) {
|
if (app()->isDownForMaintenance()) {
|
||||||
@ -68,6 +67,10 @@ class Github extends Controller
|
|||||||
if (Str::isMatch('/refs\/heads\/*/', $branch)) {
|
if (Str::isMatch('/refs\/heads\/*/', $branch)) {
|
||||||
$branch = Str::after($branch, 'refs/heads/');
|
$branch = Str::after($branch, 'refs/heads/');
|
||||||
}
|
}
|
||||||
|
$added_files = data_get($payload, 'commits.*.added');
|
||||||
|
$removed_files = data_get($payload, 'commits.*.removed');
|
||||||
|
$modified_files = data_get($payload, 'commits.*.modified');
|
||||||
|
$changed_files = collect($added_files)->concat($removed_files)->concat($modified_files)->unique()->flatten();
|
||||||
ray('Manual Webhook GitHub Push Event with branch: ' . $branch);
|
ray('Manual Webhook GitHub Push Event with branch: ' . $branch);
|
||||||
}
|
}
|
||||||
if ($x_github_event === 'pull_request') {
|
if ($x_github_event === 'pull_request') {
|
||||||
@ -118,19 +121,35 @@ class Github extends Controller
|
|||||||
}
|
}
|
||||||
if ($x_github_event === 'push') {
|
if ($x_github_event === 'push') {
|
||||||
if ($application->isDeployable()) {
|
if ($application->isDeployable()) {
|
||||||
ray('Deploying ' . $application->name . ' with branch ' . $branch);
|
$is_watch_path_triggered = $application->isWatchPathsTriggered($changed_files);
|
||||||
$deployment_uuid = new Cuid2(7);
|
if ($is_watch_path_triggered || is_null($application->watch_paths)) {
|
||||||
queue_application_deployment(
|
ray('Deploying ' . $application->name . ' with branch ' . $branch);
|
||||||
application: $application,
|
$deployment_uuid = new Cuid2(7);
|
||||||
deployment_uuid: $deployment_uuid,
|
queue_application_deployment(
|
||||||
force_rebuild: false,
|
application: $application,
|
||||||
is_webhook: true,
|
deployment_uuid: $deployment_uuid,
|
||||||
);
|
force_rebuild: false,
|
||||||
$return_payloads->push([
|
is_webhook: true,
|
||||||
'application' => $application->name,
|
);
|
||||||
'status' => 'success',
|
$return_payloads->push([
|
||||||
'message' => 'Deployment queued.',
|
'status' => 'success',
|
||||||
]);
|
'message' => 'Deployment queued.',
|
||||||
|
'application_uuid' => $application->uuid,
|
||||||
|
'application_name' => $application->name,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$paths = str($application->watch_paths)->explode("\n");
|
||||||
|
$return_payloads->push([
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Changed files do not match watch paths. Ignoring deployment.',
|
||||||
|
'application_uuid' => $application->uuid,
|
||||||
|
'application_name' => $application->name,
|
||||||
|
'details' => [
|
||||||
|
'changed_files' => $changed_files,
|
||||||
|
'watch_paths' => $paths,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$return_payloads->push([
|
$return_payloads->push([
|
||||||
'application' => $application->name,
|
'application' => $application->name,
|
||||||
@ -312,7 +331,6 @@ class Github extends Controller
|
|||||||
if ($x_github_event === 'push') {
|
if ($x_github_event === 'push') {
|
||||||
if ($application->isDeployable()) {
|
if ($application->isDeployable()) {
|
||||||
$is_watch_path_triggered = $application->isWatchPathsTriggered($changed_files);
|
$is_watch_path_triggered = $application->isWatchPathsTriggered($changed_files);
|
||||||
ray('Watch files trigger: ' . !$is_watch_path_triggered);
|
|
||||||
if ($is_watch_path_triggered || is_null($application->watch_paths)) {
|
if ($is_watch_path_triggered || is_null($application->watch_paths)) {
|
||||||
ray('Deploying ' . $application->name . ' with branch ' . $branch);
|
ray('Deploying ' . $application->name . ' with branch ' . $branch);
|
||||||
$deployment_uuid = new Cuid2(7);
|
$deployment_uuid = new Cuid2(7);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user