@@ -26,34 +26,17 @@ public function __invoke(): JsonResponse
2626 /** @var array<string, mixed> $payload */
2727 $ payload = json_decode ($ request ->getContent (), true );
2828
29- if (!isset ($ payload ['action ' ])) {
30- return response ()->json (
31- ['message ' => __ ('github-project::github-project.error.event.action_not_found ' )],
32- 400
33- );
29+ $ validationResponse = $ this ->webhookService ->validatePayload ($ payload );
30+ if ($ validationResponse !== null ) {
31+ return $ validationResponse ;
3432 }
3533
36- $ nodeId = $ payload ['projects_v2_item ' ]['content_node_id ' ] ?? null ;
37- $ fieldData = $ payload ['changes ' ]['field_value ' ] ?? null ;
38- $ editor = $ payload ['sender ' ]['login ' ] ?? 'Unknown ' ;
39-
40- if (!$ nodeId || !$ fieldData ) {
41- return response ()->json (
42- ['message ' => __ ('github-project::github-project.error.event.missing_fields ' )],
43- 400
44- );
45- }
46-
47- $ fieldName = $ fieldData ['field_name ' ] ?? 'Unknown Field ' ;
48- $ fromValue = $ fieldData ['from ' ]['name ' ] ?? 'Unknown ' ;
49- $ toValue = $ fieldData ['to ' ]['name ' ] ?? 'Unknown ' ;
50-
5134 $ message = view (
5235 'github-project::md.comment ' ,
53- compact ('editor ' , ' fieldName ' , ' fromValue ' , ' toValue ' )
36+ compact ('payload ' )
5437 )->render ();
5538
56- $ this ->webhookService ->commentOnNode ((string ) $ nodeId , $ message );
39+ $ this ->webhookService ->commentOnNode ((string ) $ payload [ ' projects_v2_item ' ][ ' content_node_id ' ] , $ message );
5740
5841 return response ()->json (['message ' => __ ('github-project::github-project.success.message ' )]);
5942 }
0 commit comments