Merge branch 'develop' into trunk

This commit is contained in:
Vincent BRIDIER 2022-04-27 17:30:51 +02:00
commit 4e4e36500d
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
10 changed files with 133 additions and 5 deletions

View file

@ -42,3 +42,6 @@ MAILJET_APISECRET=
MAILJET_SMSTOKEN=
MAILJET_SMSENDPOINT=
MAILJET_SMSFROM=
WEBHOOKS_GITLAB_NOTIFY=
WEBHOOKS_GITLAB_TOKEN=

View file

@ -0,0 +1,40 @@
<?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));
}
}
}

View file

@ -19,6 +19,6 @@ class VerifyCsrfToken extends Middleware
* @var array
*/
protected $except = [
//
'webhooks/*'
];
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\Webhooks;
use Illuminate\Foundation\Http\FormRequest;
class GitlabRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->header('X-Gitlab-Token') !== null && $this->header('X-Gitlab-Token') === config('webhooks.gitlab.token');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'event_type' => 'required|in:merge_request'
];
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace App\Mail\Webhooks;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class Gitlab extends Mailable
{
use Queueable, SerializesModels;
public $datas;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(array $datas)
{
$this->datas = $datas;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->text('emails.webhooks.gitlab');
}
}

View file

@ -24,8 +24,6 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
if (!app()->environment('local')) {
URL::forceScheme('https');
}
URL::forceScheme('https');
}
}

8
config/webhooks.php Normal file
View file

@ -0,0 +1,8 @@
<?php
return [
'gitlab' => [
'notify' => env('WEBHOOKS_GITLAB_NOTIFY', 'equipe.web@ldc.fr'),
'token' => env('WEBHOOKS_GITLAB_TOKEN')
]
];

View file

@ -1,7 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Le Gaulois Exception Handler</title>
<title>Exception Handler</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

View file

@ -0,0 +1,12 @@
Nouvelle merge request de la part de : {{ $datas['user'] }}
Projet : {{ $datas['project_name'] }}
Dépôt : {{ $datas['project_path'] }}
URL : {{ $datas['attributes_url'] }}
Description : {{ $datas['attributes_description'] }}
Branches : {{ $datas['attributes_source_branch'] }} vers {{ $datas['attributes_target_branch'] }}
Statut du merge : {{ $datas['attributes_status'] }}
Statut de la merge request : {{ $datas['attributes_request_status'] }}
Auteur du dernier commit : {{ $datas['last_commit_author'] }}

View file

@ -11,6 +11,8 @@
|
*/
Route::post('/webhooks/gitlab', 'Webhooks\GitlabController@handle');
Route::get('/login/verify', 'OTPController@verify')->name('auth.verify');
Route::get('/login/send-sms-otp', 'OTPController@sendOTPBySMS')->name('auth.sms-otp');
Route::post('/login/checkOTP', 'OTPController@check')->name('auth.otp');