40 lines
1.8 KiB
PHP
40 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Webhooks;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Webhooks\GitlabRequest;
|
|
use App\Mail\Webhooks\Gitlab;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class GitlabController extends Controller
|
|
{
|
|
public function handle(GitlabRequest $request)
|
|
{
|
|
$event_type = $request->event_type;
|
|
if ($event_type === 'merge_request') {
|
|
// Si le state est <> de opened on ne fait rien
|
|
if ($request->object_attributes['state'] !== 'opened') {
|
|
exit;
|
|
}
|
|
// Si l'action est set et egale à approved on ne fait rien
|
|
if (isset($request->object_attributes['action']) && $request->object_attributes['action'] === 'approved') {
|
|
exit;
|
|
}
|
|
|
|
$datas = [];
|
|
$datas['user'] = $request->user['name'];
|
|
$datas['project_name'] = $request->project['name'];
|
|
$datas['project_path'] = $request->project['path_with_namespace'];
|
|
$datas['attributes_description'] = $request->object_attributes['description'];
|
|
$datas['attributes_status'] = $request->object_attributes['merge_status'];
|
|
$datas['attributes_request_status'] = $request->object_attributes['state'];
|
|
$datas['attributes_source_branch'] = $request->object_attributes['source_branch'];
|
|
$datas['attributes_target_branch'] = $request->object_attributes['target_branch'];
|
|
$datas['attributes_url'] = $request->object_attributes['url'];
|
|
$datas['last_commit_author'] = $request->object_attributes['last_commit']['author']['name'];
|
|
|
|
Mail::to(\explode(',', config('webhooks.gitlab.notify')))->send(new Gitlab($datas));
|
|
}//end if
|
|
}
|
|
}
|