Skip to content

Commit 1474582

Browse files
Added processing of notifications other than Issues and PR
1 parent 4b88dfd commit 1474582

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

app/Data/ItemData.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66

77
class ItemData extends Data
88
{
9-
public int $id;
10-
119
public bool $isOpen;
1210

1311
public bool $isMerged;
1412

15-
public function __construct(array $data)
13+
public function __construct(?array $data)
1614
{
17-
$this->id = (int) $this->get($data, 'number');
15+
if (is_null($data)) {
16+
$this->isOpen = false;
17+
$this->isMerged = true;
18+
19+
return;
20+
}
1821

1922
$this->isOpen = $this->get($data, 'state') === 'open';
2023
$this->isMerged = (bool) $this->get($data, 'merged');

app/Services/GitHub.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,15 @@ public function mark(): void
7878
foreach ($items as $data) {
7979
$notification = new NotificationData($data);
8080

81-
$data = $notification->type === 'Issue'
82-
? $this->issue($notification)
83-
: $this->pullRequest($notification);
84-
85-
$item = new ItemData($data);
81+
$item = new ItemData($this->requestByType($notification));
8682

8783
$this->shouldSkip($notification, $item)
8884
? $this->output->twoColumnDetail($notification->fullName, 'SKIP')
8985
: $this->output->task($notification->fullName, fn () => $this->markAsRead($notification));
9086
}
9187
}
9288

93-
protected function markAsRead(NotificationData $data): bool
89+
protected function markAsRead(NotificationData $data): void
9490
{
9591
$this->github->notification()->markThreadRead($data->id);
9692
}
@@ -105,6 +101,15 @@ protected function notifications(): Notification
105101
return $this->github->notifications();
106102
}
107103

104+
protected function requestByType(NotificationData $notification): ?array
105+
{
106+
return match ($notification->type) {
107+
'Issue' => $this->issue($notification),
108+
'PullRequest' => $this->pullRequest($notification),
109+
default => null
110+
};
111+
}
112+
108113
protected function issue(NotificationData $notification): array
109114
{
110115
return $this->github->issues()->show(
@@ -141,6 +146,6 @@ protected function shouldSkip(NotificationData $notification, ItemData $item): b
141146
return true;
142147
}
143148

144-
return (bool) ($item->isOpen || ! $item->isMerged);
149+
return $item->isOpen || ! $item->isMerged;
145150
}
146151
}

0 commit comments

Comments
 (0)