From 22235f7a2345987240ea4a9713faaf775dd4de7b Mon Sep 17 00:00:00 2001 From: Elliot Derhay Date: Tue, 16 Apr 2024 22:17:19 -0400 Subject: [PATCH] Fix data expectations for new events --- app/DataTransferObjects/GithubEventDTO.php | 48 ++++++++++++------- .../PullRequestReviewCommentEvent.php | 11 +++-- .../EventTypes/PullRequestReviewEvent.php | 11 +++-- ...ull-request-review-comment-event.blade.php | 9 ++-- .../pull-request-review-event.blade.php | 9 ++-- 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/app/DataTransferObjects/GithubEventDTO.php b/app/DataTransferObjects/GithubEventDTO.php index 864dc061..917d1b37 100644 --- a/app/DataTransferObjects/GithubEventDTO.php +++ b/app/DataTransferObjects/GithubEventDTO.php @@ -4,36 +4,48 @@ use Illuminate\Support\Carbon; -class GithubEventDTO +readonly class GithubEventDTO { public function __construct( - public readonly string $id, - public readonly string $type, - public readonly ?string $action, - public readonly string $date, - public readonly GithubUserDTO $user, - public readonly ?string $source, - public readonly string $repo, + public string $id, + public string $type, + public string|null $action, + public string $date, + public GithubUserDTO $user, + public string|null $source, + public string $repo, ) {} - public static function getAction(array $data): ?string + public static function getAction(array $data): string|null { return match ($data['type']) { - 'IssuesEvent' => \optional($data['payload'])['action'], - 'PullRequestEvent' => (\optional($data['payload'])['merged'] - ? 'merged' - : \optional($data['payload'])['action']), + 'IssuesEvent' => optional($data['payload'])['action'], + + 'PullRequestEvent' => match (true) { + optional($data['payload'])['merged'] !== null => 'merged', + default => optional($data['payload'])['action'], + }, + + 'PullRequestReviewCommentEvent' => match (optional($data['payload'])['action']) { + 'created' => 'commented on a review of', + 'deleted' => 'deleted a review comment on', + default => 'updated a review comment on', + }, + + 'PullRequestReviewEvent' => 'started a review on', default => null, }; } - public static function getEventSource(array $data): ?string + public static function getEventSource(array $data): string|null { return match ($data['type']) { - 'CreateEvent', 'DeleteEvent', 'PushEvent' => $data['payload']['ref'], - 'ForkEvent' => $data['payload']['forkee']['full_name'], - 'IssueCommentEvent', 'IssuesEvent' => $data['payload']['issue']['number'], - 'PullRequestEvent' => $data['payload']['pull_request']['number'], + 'CreateEvent', 'DeleteEvent', 'PushEvent' => $data['payload']['ref'], + 'ForkEvent' => $data['payload']['forkee']['full_name'], + 'IssueCommentEvent', 'IssuesEvent' => $data['payload']['issue']['number'], + 'PullRequestEvent', + 'PullRequestReviewCommentEvent', + 'PullRequestReviewEvent' => $data['payload']['pull_request']['number'], default => null, }; } diff --git a/app/View/Components/Github/EventTypes/PullRequestReviewCommentEvent.php b/app/View/Components/Github/EventTypes/PullRequestReviewCommentEvent.php index 07ae0a63..868e7c9d 100644 --- a/app/View/Components/Github/EventTypes/PullRequestReviewCommentEvent.php +++ b/app/View/Components/Github/EventTypes/PullRequestReviewCommentEvent.php @@ -3,9 +3,14 @@ namespace App\View\Components\Github\EventTypes; use App\Models\GithubEvent; +use App\Traits\CanHavePreposition; +use App\Traits\HasPullRequestNumber; class PullRequestReviewCommentEvent extends BaseComponent { + use CanHavePreposition, + HasPullRequestNumber; + /** * Create a new component instance. * @@ -14,12 +19,12 @@ class PullRequestReviewCommentEvent extends BaseComponent public function __construct(GithubEvent $event) { parent::__construct( - $event->action ?? 'posted a review comment on', + $event->action ?? 'commented on a review of', 'fas fa-comment-alt', $event ); - // $this->preposition = 'at'; - // $this->setPullRequestNumberText($this->event->source); + $this->preposition = 'at'; + $this->setPullRequestNumberText($this->event->source); } } diff --git a/app/View/Components/Github/EventTypes/PullRequestReviewEvent.php b/app/View/Components/Github/EventTypes/PullRequestReviewEvent.php index 9b4a576b..387b8727 100644 --- a/app/View/Components/Github/EventTypes/PullRequestReviewEvent.php +++ b/app/View/Components/Github/EventTypes/PullRequestReviewEvent.php @@ -3,9 +3,14 @@ namespace App\View\Components\Github\EventTypes; use App\Models\GithubEvent; +use App\Traits\CanHavePreposition; +use App\Traits\HasPullRequestNumber; class PullRequestReviewEvent extends BaseComponent { + use CanHavePreposition, + HasPullRequestNumber; + /** * Create a new component instance. * @@ -14,12 +19,12 @@ class PullRequestReviewEvent extends BaseComponent public function __construct(GithubEvent $event) { parent::__construct( - $event->action ?? 'reviewed a PR on', + $event->action ?? 'reviewed', 'fas fa-edit', $event ); - // $this->preposition = 'at'; - // $this->setPullRequestNumberText($this->event->source); + $this->preposition = 'at'; + $this->setPullRequestNumberText($this->event->source); } } diff --git a/resources/views/components/github/event-types/pull-request-review-comment-event.blade.php b/resources/views/components/github/event-types/pull-request-review-comment-event.blade.php index c71313ad..4f6083ce 100644 --- a/resources/views/components/github/event-types/pull-request-review-comment-event.blade.php +++ b/resources/views/components/github/event-types/pull-request-review-comment-event.blade.php @@ -15,11 +15,12 @@ {{ $action }} - {{-- --}} - {{-- {{ $pullRequestNumberText }}--}} - {{-- --}} + + {{ $pullRequestNumberText }} + - {{-- {{ $preposition }}--}} + {{ $preposition }} {{ $event->repo }} diff --git a/resources/views/components/github/event-types/pull-request-review-event.blade.php b/resources/views/components/github/event-types/pull-request-review-event.blade.php index c71313ad..4f6083ce 100644 --- a/resources/views/components/github/event-types/pull-request-review-event.blade.php +++ b/resources/views/components/github/event-types/pull-request-review-event.blade.php @@ -15,11 +15,12 @@ {{ $action }} - {{-- --}} - {{-- {{ $pullRequestNumberText }}--}} - {{-- --}} + + {{ $pullRequestNumberText }} + - {{-- {{ $preposition }}--}} + {{ $preposition }} {{ $event->repo }}