Skip to content

Commit 3233a6e

Browse files
committed
feat: refactor comment handling and introduce content view
1 parent da28cc9 commit 3233a6e

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
@php
2-
$fieldData = $payload['changes']['field_value'] ?? null;
3-
4-
$fieldName = $fieldData['field_name'] ?? 'Unknown Field';
5-
$fromValue = $fieldData['from']['name']
6-
?? $fieldData['from']['title']
7-
?? $fieldData['from']
8-
?? null;
9-
$toValue = $fieldData['to']['name']
10-
?? $fieldData['to']['title']
11-
?? $fieldData['to']
12-
?? null;
13-
@endphp
14-
@include(
15-
'github-project::md.field_types.' . $fieldData['field_type'],
16-
compact('fieldName', 'fromValue', 'toValue', 'fieldData')
17-
)
1+
@include('github-project::md.shared.content', compact('payload'))
182

193
@include('github-project::md.shared.author', compact('payload'))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@php
2+
$fieldData = $payload['changes']['field_value'] ?? null;
3+
4+
$fieldName = $fieldData['field_name'] ?? 'Unknown Field';
5+
$fromValue = $fieldData['from']['name']
6+
?? $fieldData['from']['title']
7+
?? $fieldData['from']
8+
?? null;
9+
$toValue = $fieldData['to']['name']
10+
?? $fieldData['to']['title']
11+
?? $fieldData['to']
12+
?? null;
13+
@endphp
14+
@include(
15+
'github-project::md.field_types.' . $fieldData['field_type'],
16+
compact('fieldName', 'fromValue', 'toValue', 'fieldData')
17+
)

src/Actions/WebhookAction.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public function __invoke(): JsonResponse
3939
return $validationResponse;
4040
}
4141

42-
$message = view('github-project::md.comment', compact('payload'))->render();
43-
44-
$this->githubService->handleComment((string) $payload['projects_v2_item']['content_node_id'], $message);
42+
$this->githubService->handleComment($payload);
4543

4644
return response()->json(['message' => __('github-project::github-project.success.message')]);
4745
}

src/Services/GithubService.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ public function commentOnNode(string $contentNodeId, string $message): array
4040
return $client->graphql()->execute($query, $variables);
4141
}
4242

43-
public function handleComment(string $contentNodeId, string $message): void
43+
public function handleComment(array $payload): void
4444
{
45+
$contentNodeId = (string) $payload['projects_v2_item']['content_node_id'];
46+
4547
if (config('github-project.is_queue_enabled')) {
46-
ProcessWebhookEvent::dispatch($contentNodeId, $message);
48+
ProcessWebhookEvent::dispatch(
49+
$contentNodeId,
50+
view('github-project::md.shared.content', compact('payload'))->render()
51+
);
4752
}
4853

49-
$this->commentOnNode($contentNodeId, $message);
54+
$this->commentOnNode($contentNodeId, view('github-project::md.comment', compact('payload'))->render());
5055
}
5156
}

0 commit comments

Comments
 (0)