Skip to content

Commit ef93526

Browse files
committed
refactor: add eventRequestApproved method to WebhookService for improved event handling
1 parent ecb7223 commit ef93526

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/Actions/WebhookAction.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ public function __construct(WebhookService $webhookService)
1818
public function __invoke(): JsonResponse
1919
{
2020
$request = Request::createFromGlobals();
21-
$event = $request->server->get('HTTP_X_GITHUB_EVENT');
2221

23-
if (!$this->webhookService->eventApproved((string) $event)) {
22+
if (!$this->webhookService->eventRequestApproved($request)) {
2423
return response()->json(['message' => __('github-project::github-project.error.event.denied')], 403);
2524
}
2625

src/Services/WebhookService.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CSlant\GitHubProject\Services;
44

55
use Github\Client;
6+
use Symfony\Component\HttpFoundation\Request;
67

78
class WebhookService
89
{
@@ -18,6 +19,13 @@ public function eventApproved(string $event): bool
1819
return str_contains($event, 'project');
1920
}
2021

22+
public function eventRequestApproved(Request $request): bool
23+
{
24+
$event = $request->server->get('HTTP_X_GITHUB_EVENT');
25+
26+
return $this->eventApproved((string) $event);
27+
}
28+
2129
/**
2230
* @param string $contentNodeId
2331
* @param string $message
@@ -27,17 +35,17 @@ public function eventApproved(string $event): bool
2735
public function commentOnNode(string $contentNodeId, string $message): array
2836
{
2937
$query = <<<'GRAPHQL'
30-
mutation($input: AddCommentInput!) {
31-
addComment(input: $input) {
32-
commentEdge {
33-
node {
34-
id
35-
body
38+
mutation($input: AddCommentInput!) {
39+
addComment(input: $input) {
40+
commentEdge {
41+
node {
42+
id
43+
body
44+
}
3645
}
3746
}
3847
}
39-
}
40-
GRAPHQL;
48+
GRAPHQL;
4149

4250
$variables = [
4351
'input' => [

0 commit comments

Comments
 (0)