Skip to content

Commit de5b29f

Browse files
committed
feat: refactor payload validation in GenerateCommentAction and WebhookService
1 parent c8d957f commit de5b29f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Actions/GenerateCommentAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __invoke(Request $request, bool $validate = true): JsonResponse
4545
}
4646

4747
if ($validate) {
48-
$validationResponse = $this->webhookService->validatePayload($payload);
48+
$validationResponse = $this->webhookService->validatePayloadForComment($payload);
4949
if ($validationResponse !== null) {
5050
return $validationResponse;
5151
}

src/Services/WebhookService.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,23 @@ protected function createErrorResponse(string $message, int $statusCode = 400):
5757
*/
5858
public function validatePayload(array $payload): ?JsonResponse
5959
{
60-
if (!$this->isActionPresent($payload)) {
61-
return $this->createErrorResponse('github-project::github-project.error.event.action_not_found', 404);
60+
if ($this->validatePayloadForComment($payload) !== null) {
61+
return $this->validatePayloadForComment($payload);
6262
}
6363

6464
if (!$this->isStatusCommentEnabled($payload)) {
6565
return $this->createErrorResponse('github-project::github-project.error.event.status_comment_disabled');
6666
}
6767

68+
return null;
69+
}
70+
71+
public function validatePayloadForComment(array $payload): ?JsonResponse
72+
{
73+
if (!$this->isActionPresent($payload)) {
74+
return $this->createErrorResponse('github-project::github-project.error.event.action_not_found', 404);
75+
}
76+
6877
if (!$this->hasValidNodeAndFieldData($payload)) {
6978
return $this->createErrorResponse('github-project::github-project.error.event.missing_fields');
7079
}

0 commit comments

Comments
 (0)