Skip to content

Commit

Permalink
Merge branch 'release/1.2.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
ben182 committed Sep 18, 2018
2 parents 192b838 + 5fda890 commit 767d4c6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
13 changes: 10 additions & 3 deletions app/Console/Commands/GitAutoDeployNotificationSlack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use App\Console\ModCommand;
use App\Console\Commands\Tasks\GitAutoDeployNotificationSlackTaskManager;
use App\Setting;

class GitAutoDeployNotificationSlack extends ModCommand
{
Expand Down Expand Up @@ -41,13 +42,19 @@ public function handle()
{
parent::handle();

$this->line('Visit ' . config('services.stool.base') . '/deploy/login/slack and come back with a token');
$sToken = $this->ask('Token?');
$this->line('Visit');
$this->info(self::generateOauthUrl());
$this->line('and give permission to send Slack messages!');

$sChannel = $this->ask('Channel?');

(new GitAutoDeployNotificationSlackTaskManager([
'public_id' => $sToken,
'channel' => $sChannel,
]))->work();
}

public static function generateOauthUrl() {
$sServerId = Setting::where('key', 'server_id')->value('value');
return config('services.stool.base') . '/deploy/login/slack/' . $sServerId;
}
}
7 changes: 7 additions & 0 deletions app/Console/Commands/InstallationFinishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public function handle()
{
parent::handle();

// Init
$oBody = (new ApiRequestService())->request('server/init');
Setting::create([
'key' => 'server_id',
'value' => $oBody->public_id,
]);

// Deploy Job
(new CreateDeamonTaskManager([
'name' => 'stool-deploy',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Console\Commands\Tasks\Task;
use App\Services\ApiRequestService;
use App\Setting;
use App\Console\Commands\GitAutoDeployNotificationSlack;

class GitAutoDeployNotificationSlackTask extends Task
{
Expand All @@ -22,14 +23,15 @@ public function localRequirements()

public function handle()
{
(new ApiRequestService())->request('verifySlack', [
'public_id' => $this->oOptions->public_id,
'channel' => $this->oOptions->channel,
]); // TODO: validate response
$oBody = (new ApiRequestService())->request('slack/isTokenSet');
if ($oBody->ok === false) {
return $this->shell->saveError('No write Permission! Please visit ' . GitAutoDeployNotificationSlack::generateOauthUrl() . ' and give permission to send Slack messages!');
}

Setting::create([
'key' => 'deploy_slack_token',
'value' => $this->oOptions->public_id,
Setting::updateOrCreate([
'key' => 'slack_channel',
], [
'value' => $this->oOptions->channel,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class GitAutoDeployNotificationSlackTaskManager extends Taskmanager
public function validate()
{
return [
'public_id' => 'required',
'channel' => 'required',
];
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle()
exec($sCommand, $aOutput, $iExit);

if ($iExit != 0) {
(new ApiRequestService())->request('sendEmail', [
(new ApiRequestService())->request('email/send', [
'type' => 'DeployFailed',
'email' => Setting::where('key', 'admin_email')->value('value'),
'repository' => $this->repository->dir,
Expand Down
8 changes: 5 additions & 3 deletions app/Services/ApiRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public function __construct()
],
]);
}
public function request($sRoute, $aParams)
public function request($sRoute, $aParams = [])
{
return $this->client->request('POST', $sRoute, [
$oResponse = $this->client->request('POST', $sRoute, [
'form_params' => $aParams,
])->getBody();
]);

return json_decode($oResponse->getBody());
}
}
10 changes: 5 additions & 5 deletions app/Services/Slack.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

class Slack
{
public $token;
public $channel;

public function __construct()
{
$this->token = Setting::where('key', 'deploy_slack_token')->value('value');
$this->channel = Setting::where('key', 'slack_channel')->value('value');
}
public function send($sText, $sFormat = null)
{
if (! $this->token) {
if (! $this->channel) {
return false;
}

return (new ApiRequestService())->request('sendSlack', [
'public_id' => $this->token,
return (new ApiRequestService())->request('slack/send', [
'text' => $sText,
'channel' => $this->channel,
'format' => $sFormat,
]);
}
Expand Down
12 changes: 6 additions & 6 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

# http://patorjk.com/software/taag/#p=display&v=0&f=Slant&t=stool%20v1.2.6
# http://patorjk.com/software/taag/#p=display&v=0&f=Slant&t=stool%20v1.2.8
cat << "EOF"
__ __ ___ ___ _____
_____/ /_____ ____ / / _ _< /|__ \/__ /
/ ___/ __/ __ \/ __ \/ / | | / / / __/ / / /
(__ ) /_/ /_/ / /_/ / / | |/ / / / __/_ / /
/____/\__/\____/\____/_/ |___/_(_)____(_)_/
__ __ ___ ___ ____
_____/ /_____ ____ / / _ _< /|__ \ ( __ )
/ ___/ __/ __ \/ __ \/ / | | / / / __/ / / __ |
(__ ) /_/ /_/ / /_/ / / | |/ / / / __/_/ /_/ /
/____/\__/\____/\____/_/ |___/_(_)____(_)____/
EOF

Expand Down
3 changes: 3 additions & 0 deletions scripts/partials/finish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ finish () {
# Fix for laravel mix
sudo apt-get install libpng-dev -y

# unzip
sudo apt-get install unzip -y

# APACHE PERMISSIONS
apache_permissions
service apache2 reload
Expand Down

0 comments on commit 767d4c6

Please sign in to comment.