Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
9.09% covered (danger)
9.09%
1 / 11
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PipelineResult
9.09% covered (danger)
9.09%
1 / 11
50.00% covered (danger)
50.00%
1 / 2
9.76
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace App\Console\Commands\Pipeline;
4
5use App\Mail\MessageEmail;
6use App\Mail\PipelineEmail;
7use Illuminate\Console\Command;
8use Illuminate\Support\Facades\Mail;
9
10class PipelineResult extends Command
11{
12    /**
13     * The name and signature of the console command.
14     *
15     * @var string
16     */
17    protected $signature = 'pipeline:result {--result=} {--msg=}';
18
19    /**
20     * The console command description.
21     *
22     * @var string
23     */
24    protected $description = 'Command to send an e-mail with the result of each pipeline';
25
26    /**
27     * Create a new command instance.
28     *
29     * @return void
30     */
31    public function __construct()
32    {
33        parent::__construct();
34    }
35
36    /**
37     * Execute the console command.
38     *
39     * @return int
40     */
41    public function handle(): int
42    {
43        $result  = $this->option('result');
44        $message = $this->option('msg');
45
46        if ($result === 'ok')
47        {
48            $this->info($result = "Pipeline success! ✅ 🏆");
49            $message = "Congrats.. everything is in production.. up and running!";
50        }
51        else
52        {
53            $this->error($result = "Pipeline failed! ❌");
54            $message = "$message\nCheck Jenkins logs for more details.";
55        }
56
57        // Send Jenkins notification
58        Mail::to(env('MAIL_USERNAME'))
59            ->send(new PipelineEmail($result, $message));
60
61        return 0;
62    }
63}