diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a28bfc6..fcb7360f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,15 +5,20 @@ ### Updates - [#183][is_183]: Upgrade to Laravel 11 ([#190][pr_190]) +- [#39][is_39]: Look into support for new GitHub events ([#193][pr_193]) ### Development - Purge old VS Code configs +[is_39]: https://github.com/JSn1nj4/ElliotDerhay.com/issues/39 + [is_183]: https://github.com/JSn1nj4/ElliotDerhay.com/issues/183 [pr_190]: https://github.com/JSn1nj4/ElliotDerhay.com/pull/190 +[pr_193]: https://github.com/JSn1nj4/ElliotDerhay.com/pull/193 + ## Version 2.8.6 ### Fix diff --git a/app/Console/Commands/GithubEventPullCommand.php b/app/Console/Commands/GithubEventPullCommand.php index f22df464..c7cb3531 100644 --- a/app/Console/Commands/GithubEventPullCommand.php +++ b/app/Console/Commands/GithubEventPullCommand.php @@ -29,16 +29,6 @@ class GithubEventPullCommand extends Command */ protected $description = 'Fetch events from GitHub\'s events API.'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @@ -60,13 +50,13 @@ public function handle(GithubService $github): int $events = $github->getEvents('JSn1nj4', $this->option('count')); - if($this->option('file')) { + if ($this->option('file')) { Storage::disk('debug')->put($this->option('file'), $events->toJson()); return self::SUCCESS; } - if($this->option('debug')) { + if ($this->option('debug')) { dd($events); } diff --git a/app/DataTransferObjects/GithubEventDTO.php b/app/DataTransferObjects/GithubEventDTO.php index 864dc061..b5c69583 100644 --- a/app/DataTransferObjects/GithubEventDTO.php +++ b/app/DataTransferObjects/GithubEventDTO.php @@ -4,36 +4,61 @@ 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']), + 'CommitCommentEvent' => match (optional($data['payload'])['action']) { + 'created' => 'commented on', + default => 'deleted a comment on', + }, + + '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', + + 'ReleaseEvent' => match (optional($data['payload'])['action']) { + null => 'updated', + default => optional($data['payload'])['action'], + }, + 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'], + 'CommitCommentEvent' => $data['payload']['comment']['commit_id'], + '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'], + 'ReleaseEvent' => $data['payload']['release']['html_url'], default => null, }; } diff --git a/app/Services/Github/GithubService.php b/app/Services/Github/GithubService.php index 69797012..7b1959f0 100644 --- a/app/Services/Github/GithubService.php +++ b/app/Services/Github/GithubService.php @@ -30,6 +30,7 @@ class GithubService implements GitHostService * Reference: https://docs.github.com/en/developers/webhooks-and-events/events/github-event-types */ private array $supportedEventTypes = [ + 'CommitCommentEvent', 'CreateEvent', 'DeleteEvent', 'ForkEvent', @@ -37,7 +38,10 @@ class GithubService implements GitHostService 'IssuesEvent', 'PublicEvent', 'PullRequestEvent', + 'PullRequestReviewCommentEvent', + 'PullRequestReviewEvent', 'PushEvent', + 'ReleaseEvent', 'WatchEvent', ]; @@ -51,10 +55,10 @@ class GithubService implements GitHostService public function __construct() { foreach ([ - 'services.github.token', - 'mail.to.name', - 'mail.to.address', - ] as $key) { + 'services.github.token', + 'mail.to.name', + 'mail.to.address', + ] as $key) { if (config($key) === null) { throw new Exception("Config option '{$key}' not set."); } @@ -142,11 +146,11 @@ public function filterEventTypes(Response $response): Collection */ public function getEvents(string $user, int $count): Collection { - if($count < 1) { + if ($count < 1) { throw new Exception("'\$count' value must be 1 or higher. Value is '{$count}'."); } - if($count > 100) { + if ($count > 100) { throw new Exception("'\$count' value must be 100 or less. Value is '{$count}'."); } diff --git a/app/View/Components/Github/EventTypes/CommitCommentEvent.php b/app/View/Components/Github/EventTypes/CommitCommentEvent.php new file mode 100644 index 00000000..cbc96b7f --- /dev/null +++ b/app/View/Components/Github/EventTypes/CommitCommentEvent.php @@ -0,0 +1,31 @@ +action, + icon: 'fas fa-comment', + event: $event, + ); + + if ($this->refNull($this->event->source)) return; + + $this->preposition = 'at'; + $this->setRefName(str($this->event->source)->limit(7, '')); + + if (str($this->action)->contains('deleted', true)) return; + + $this->setRefUrl($this->repoUrl()); + } +} diff --git a/app/View/Components/Github/EventTypes/PullRequestReviewCommentEvent.php b/app/View/Components/Github/EventTypes/PullRequestReviewCommentEvent.php new file mode 100644 index 00000000..868e7c9d --- /dev/null +++ b/app/View/Components/Github/EventTypes/PullRequestReviewCommentEvent.php @@ -0,0 +1,30 @@ +action ?? 'commented on a review of', + 'fas fa-comment-alt', + $event + ); + + $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 new file mode 100644 index 00000000..387b8727 --- /dev/null +++ b/app/View/Components/Github/EventTypes/PullRequestReviewEvent.php @@ -0,0 +1,30 @@ +action ?? 'reviewed', + 'fas fa-edit', + $event + ); + + $this->preposition = 'at'; + $this->setPullRequestNumberText($this->event->source); + } +} diff --git a/app/View/Components/Github/EventTypes/ReleaseEvent.php b/app/View/Components/Github/EventTypes/ReleaseEvent.php new file mode 100644 index 00000000..3e853caa --- /dev/null +++ b/app/View/Components/Github/EventTypes/ReleaseEvent.php @@ -0,0 +1,31 @@ +action, + icon: 'fas fa-tag', + event: $event, + ); + + $this->preposition = 'at'; + $this->releaseUrl = $event->source; + $this->releaseText = str($event->source)->after('releases/'); + } +} diff --git a/resources/views/components/github/event-types/commit-comment-event.blade.php b/resources/views/components/github/event-types/commit-comment-event.blade.php new file mode 100644 index 00000000..3f9dad93 --- /dev/null +++ b/resources/views/components/github/event-types/commit-comment-event.blade.php @@ -0,0 +1,38 @@ +
+
+ +
+

+ {{ $timeElapsed }} +

+ +

+ + + {{ $event->user->display_login }} + + + {{ $action }} + + {{-- no refUrl assumes it was deleted --}} + @if($refUrl === null) + + {{ $refName }} + + @else + + {{ $refName }} + + @endif + + + {{ $preposition }} + + + {{ $event->repo }} + + +

+
+
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 new file mode 100644 index 00000000..4f6083ce --- /dev/null +++ b/resources/views/components/github/event-types/pull-request-review-comment-event.blade.php @@ -0,0 +1,31 @@ +
+
+ +
+

+ {{ $timeElapsed }} +

+ +

+ + + {{ $event->user->display_login }} + + + {{ $action }} + + + {{ $pullRequestNumberText }} + + + {{ $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 new file mode 100644 index 00000000..4f6083ce --- /dev/null +++ b/resources/views/components/github/event-types/pull-request-review-event.blade.php @@ -0,0 +1,31 @@ +
+
+ +
+

+ {{ $timeElapsed }} +

+ +

+ + + {{ $event->user->display_login }} + + + {{ $action }} + + + {{ $pullRequestNumberText }} + + + {{ $preposition }} + + + {{ $event->repo }} + + +

+
+
diff --git a/resources/views/components/github/event-types/release-event.blade.php b/resources/views/components/github/event-types/release-event.blade.php new file mode 100644 index 00000000..294a042a --- /dev/null +++ b/resources/views/components/github/event-types/release-event.blade.php @@ -0,0 +1,31 @@ +
+
+ +
+

+ {{ $timeElapsed }} +

+ +

+ + + {{ $event->user->display_login }} + + + {{ $action }} + + + {{ $releaseText }} + + + {{ $preposition }} + + + {{ $event->repo }} + + +

+
+