Skip to content

Commit f7fec7d

Browse files
committed
Added variables to .env.example and validation to prevent RequestException
1 parent 6af29c7 commit f7fec7d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ PROXY_METHOD=
2727
PROXY_SERVER=
2828
PROXY_USER=
2929
PROXY_PASS=
30+
31+
SLACK_CHANNEL=channel-name
32+
SLACK_BOT_NAME=bot-name
33+
SLACK_WEBHOOK=endpoint

app/Services/SlackService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace GitScrum\Services;
44

55
use GitScrum\Contracts\SlackInterface;
6+
use Log;
67
use Maknz\Slack\Client;
78

89

@@ -16,6 +17,9 @@ class SlackService implements SlackInterface
1617

1718
public function __construct()
1819
{
20+
$channel = env('SLACK_CHANNEL', '');
21+
$username = env('SLACK_BOT_NAME', '');
22+
$webhook = env('SLACK_WEBHOOK', '');
1923
$this->settings = [
2024
'channel' => env('SLACK_CHANNEL', ''),
2125
'username' => env('SLACK_BOT_NAME', ''),
@@ -36,6 +40,13 @@ public function __construct()
3640
*/
3741
public function send($content, $type = 0)
3842
{
43+
if (empty($this->client->getEndpoint()) || empty($this->client->getDefaultChannel())
44+
|| empty($this->client->getDefaultUsername())) {
45+
Log::info('One or more settings are missing, Slack notifications are not availables');
46+
47+
return;
48+
}
49+
3950
$message = $this->buildMessage($content, $type);
4051
$this->client->attach([
4152
'title' => $content['title'],

0 commit comments

Comments
 (0)