Skip to content

Commit 9400fca

Browse files
feat: set webhook using cli
1 parent 4f1818c commit 9400fca

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/Commands/SetWebhook.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace CSlant\LaravelTelegramGitNotifier\Commands;
4+
5+
use CSlant\LaravelTelegramGitNotifier\Services\WebhookService;
6+
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
7+
use Illuminate\Console\Command;
8+
use Illuminate\Support\Facades\Log;
9+
10+
class SetWebhook extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'tg-notifier:webhook:set';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Set webhook';
25+
26+
protected WebhookService $webhookService;
27+
28+
public function __construct(WebhookService $webhookService)
29+
{
30+
parent::__construct();
31+
$this->webhookService = $webhookService;
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @return void
38+
*/
39+
public function handle(): void
40+
{
41+
try {
42+
$log = $this->webhookService->handle();
43+
44+
$this->info($log);
45+
} catch (WebhookException $e) {
46+
$this->error($e->getMessage());
47+
}
48+
}
49+
}

src/Providers/TelegramGitNotifierServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CSlant\LaravelTelegramGitNotifier\Providers;
44

55
use CSlant\LaravelTelegramGitNotifier\Commands\ChangeOwnerConfigJson;
6+
use CSlant\LaravelTelegramGitNotifier\Commands\SetWebhook;
67
use Illuminate\Support\ServiceProvider;
78

89
class TelegramGitNotifierServiceProvider extends ServiceProvider
@@ -59,6 +60,7 @@ protected function registerCommands(): void
5960
{
6061
$this->commands([
6162
ChangeOwnerConfigJson::class,
63+
SetWebhook::class,
6264
]);
6365
}
6466

src/Services/WebhookService.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace CSlant\LaravelTelegramGitNotifier\Services;
4+
5+
use CSlant\LaravelTelegramGitNotifier\Http\Actions\WebhookAction;
6+
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
7+
8+
class WebhookService
9+
{
10+
protected WebhookAction $webhookAction;
11+
12+
public function __construct(WebhookAction $webhookAction) {
13+
$this->webhookAction = $webhookAction;
14+
}
15+
16+
17+
/**
18+
* @throws WebhookException
19+
*/
20+
public function handle(): string
21+
{
22+
return $this->webhookAction->set();
23+
}
24+
}

0 commit comments

Comments
 (0)