Skip to content

Commit

Permalink
Fix data expectations for new events
Browse files Browse the repository at this point in the history
  • Loading branch information
JSn1nj4 committed Apr 17, 2024
1 parent 611e486 commit 22235f7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
48 changes: 30 additions & 18 deletions app/DataTransferObjects/GithubEventDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}
11 changes: 8 additions & 3 deletions app/View/Components/Github/EventTypes/PullRequestReviewEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

{{ $action }}

{{-- <a href="{{ $repoUrl() }}/pull/{{ $event->source }}" target="_blank" class="text-caribbeanGreen-600 dark:text-caribbeanGreen-500">--}}
{{-- {{ $pullRequestNumberText }}--}}
{{-- </a>--}}
<a href="{{ $repoUrl() }}/pull/{{ $event->source }}" target="_blank"
class="text-caribbeanGreen-600 dark:text-caribbeanGreen-500">
{{ $pullRequestNumberText }}
</a>

{{-- {{ $preposition }}--}}
{{ $preposition }}

<a href="{{ $repoUrl() }}" target="_blank">
{{ $event->repo }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

{{ $action }}

{{-- <a href="{{ $repoUrl() }}/pull/{{ $event->source }}" target="_blank" class="text-caribbeanGreen-600 dark:text-caribbeanGreen-500">--}}
{{-- {{ $pullRequestNumberText }}--}}
{{-- </a>--}}
<a href="{{ $repoUrl() }}/pull/{{ $event->source }}" target="_blank"
class="text-caribbeanGreen-600 dark:text-caribbeanGreen-500">
{{ $pullRequestNumberText }}
</a>

{{-- {{ $preposition }}--}}
{{ $preposition }}

<a href="{{ $repoUrl() }}" target="_blank">
{{ $event->repo }}
Expand Down

0 comments on commit 22235f7

Please sign in to comment.