Skip to content

Commit a935765

Browse files
committed
feat: enhance comment and author templates with formatted date and avatar support
1 parent b18e200 commit a935765

File tree

6 files changed

+187
-15
lines changed

6 files changed

+187
-15
lines changed

common/helpers.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,3 @@ function format_date(?string $date, string $format = 'Y-m-d'): ?string
4040
}
4141
}
4242
}
43-
44-
if (!function_exists('format_boolean')) {
45-
/**
46-
* Format a boolean value.
47-
*
48-
* @param mixed $value
49-
* @return string
50-
*/
51-
function format_boolean($value): string
52-
{
53-
return filter_var($value, FILTER_VALIDATE_BOOLEAN) ? '' : '';
54-
}
55-
}
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1+
@php
2+
$action = $payload['action'] ?? 'updated';
3+
$actionVerb = match($action) {
4+
'created' => 'created',
5+
'deleted' => 'deleted',
6+
'edited' => 'updated',
7+
default => 'updated'
8+
};
9+
10+
$itemType = $payload['projects_v2_item']['content_type'] ?? 'item';
11+
$itemUrl = $payload['projects_v2_item']['content_url'] ?? '#';
12+
$itemTitle = $payload['projects_v2_item']['content_title'] ?? 'item';
13+
14+
$projectUrl = $payload['projects_v2_item']['project_url'] ?? '#';
15+
$projectTitle = $payload['projects_v2_item']['project_title'] ?? 'project';
16+
@endphp
17+
18+
**📌 {{ ucfirst($actionVerb) }}** in [{{ $projectTitle }}]({{ $projectUrl }})
19+
120
@include('github-project::md.shared.content', compact('payload'))
21+
22+
---
23+
24+
🔗 [View {{ ucfirst($itemType) }}]({{ $itemUrl }})
25+
226
@include('github-project::md.shared.author', [
327
'name' => $payload['sender']['login'] ?? 'Unknown',
4-
'html_url' => $payload['sender']['html_url'] ?? '#'
28+
'html_url' => $payload['sender']['html_url'] ?? '#',
29+
'avatar_url' => $payload['sender']['avatar_url'] ?? null,
30+
'date' => $payload['changes']['updated_at'] ?? now()->toIso8601String()
531
])
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@php
2+
// Convert to arrays if they aren't already
3+
$fromValues = is_array($fromValue) ? $fromValue : (array)($fromValue ?? []);
4+
$toValues = is_array($toValue) ? $toValue : (array)($toValue ?? []);
5+
6+
// Get added and removed values
7+
$added = [];
8+
$removed = [];
9+
10+
foreach ($toValues as $value) {
11+
$found = false;
12+
foreach ($fromValues as $fromVal) {
13+
if (($value['id'] ?? $value) === ($fromVal['id'] ?? $fromVal)) {
14+
$found = true;
15+
break;
16+
}
17+
}
18+
if (!$found) {
19+
$added[] = $value;
20+
}
21+
}
22+
23+
foreach ($fromValues as $value) {
24+
$found = false;
25+
foreach ($toValues as $toVal) {
26+
if (($value['id'] ?? $value) === ($toVal['id'] ?? $toVal)) {
27+
$found = true;
28+
break;
29+
}
30+
}
31+
if (!$found) {
32+
$removed[] = $value;
33+
}
34+
}
35+
36+
// Helper function to get display value
37+
$getDisplayValue = function($item) {
38+
if (is_array($item)) {
39+
$color = $item['color'] ?? null;
40+
$name = $item['name'] ?? $item['title'] ?? 'Unknown';
41+
return $color ? "`{$name}`" : $name;
42+
}
43+
return $item;
44+
};
45+
@endphp
46+
47+
@if(count($added) > 0 || count($removed) > 0)
48+
**`{{ $fieldName }}`** has been updated:
49+
50+
@if(count($added) > 0)
51+
- Added: {!! implode(', ', array_map($getDisplayValue, $added)) !!}
52+
@endif
53+
54+
@if(count($removed) > 0)
55+
- Removed: {!! implode(', ', array_map($getDisplayValue, $removed)) !!}
56+
@endif
57+
@elseif(empty($toValues))
58+
All values have been removed from **`{{ $fieldName }}`**.
59+
@else
60+
**`{{ $fieldName }}`** has been set to: {!! implode(', ', array_map($getDisplayValue, $toValues)) !!}
61+
@endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@php
2+
$truncateLength = 200;
3+
$fromValue = $fromValue ?? '';
4+
$toValue = $toValue ?? '';
5+
6+
$fromTruncated = Str::limit($fromValue, $truncateLength);
7+
$toTruncated = Str::limit($toValue, $truncateLength);
8+
9+
$fromWasTruncated = $fromValue !== $fromTruncated;
10+
$toWasTruncated = $toValue !== $toTruncated;
11+
@endphp
12+
13+
@if($fromValue && $toValue)
14+
**`{{ $fieldName }}`** has been updated:
15+
16+
<details>
17+
<summary>View changes</summary>
18+
19+
### From:
20+
{{ $fromTruncated }}
21+
@if($fromWasTruncated)
22+
*... (content truncated)*
23+
@endif
24+
25+
### To:
26+
{{ $toTruncated }}
27+
@if($toWasTruncated)
28+
*... (content truncated)*
29+
@endif
30+
</details>
31+
@elseif($toValue)
32+
**`{{ $fieldName }}`** has been set:
33+
34+
<details>
35+
<summary>View content</summary>
36+
{{ $toTruncated }}
37+
@if($toWasTruncated)
38+
*... (content truncated)*
39+
@endif
40+
</details>
41+
@else
42+
**`{{ $fieldName }}`** has been cleared.
43+
@endif
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@php
2+
// Try to format the values for display
3+
$formatValue = function($value) {
4+
if ($value === null) {
5+
return '`null`';
6+
}
7+
if (is_bool($value)) {
8+
return $value ? '`true`' : '`false`';
9+
}
10+
if (is_array($value) || is_object($value)) {
11+
return '```json
12+
'.json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).'
13+
```';
14+
}
15+
return '`'.(string)$value.'`';
16+
};
17+
18+
$fromFormatted = $fromValue !== null ? $formatValue($fromValue) : null;
19+
$toFormatted = $toValue !== null ? $formatValue($toValue) : null;
20+
@endphp
21+
22+
**`{{ $fieldName }}`** ({{ $fieldType }}) has been updated:
23+
24+
@if($fromFormatted !== null && $toFormatted !== null)
25+
- From: {!! $fromFormatted !!}
26+
- To: {!! $toFormatted !!}
27+
@elseif($toFormatted !== null)
28+
- Set to: {!! $toFormatted !!}
29+
@else
30+
- Value cleared
31+
@endif
32+
33+
*Note: This field type is not fully supported. Displaying raw data.*
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1+
@php
2+
$date = $date ?? now();
3+
$formattedDate = $date instanceof \DateTimeInterface
4+
? $date->format('Y-m-d H:i:s')
5+
: \Carbon\Carbon::parse($date)->format('Y-m-d H:i:s');
6+
@endphp
17

2-
> Made changes by: [{{ $name }}]({{ $html_url }})
8+
<div style="display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 14px; color: #6a737d;">
9+
@if($avatar_url ?? false)
10+
<img
11+
src="{{ $avatar_url }}"
12+
alt="{{ $name }}"
13+
width="20"
14+
height="20"
15+
style="border-radius: 50%;"
16+
>
17+
@endif
18+
<span>
19+
Changed by <a href="{{ $html_url }}" style="color: #0366d6; text-decoration: none;">{{ $name }}</a>
20+
@if($formattedDate)
21+
<span style="color: #6a737d;">on {{ $formattedDate }}</span>
22+
@endif
23+
</span>
24+
</div>

0 commit comments

Comments
 (0)