Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Platform/Github/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Danger\Config;
use Danger\Platform\AbstractPlatform;
use Danger\Struct\Github\PullRequest as GithubPullRequest;
use Danger\Struct\PullRequest;
use Github\Client;

/**
* @property array{'title': string, 'body': ?string, 'labels': array{'name': string}[], 'assignees': array{'login': string}[], 'requested_reviewers': array{'login': string}[], 'created_at': string, 'updated_at': string} $raw
* @property array{'title': string, 'body': ?string, 'state': string, 'merged': bool, 'labels': array{'name': string}[], 'assignees': array{'login': string}[], 'requested_reviewers': array{'login': string}[], 'created_at': string, 'updated_at': string} $raw
*/
class Github extends AbstractPlatform
{
Expand All @@ -27,7 +28,7 @@ public function load(string $projectIdentifier, string $id): void
$this->githubOwner = $owner;
$this->githubRepository = $repository;

/** @var array{'title': string, 'body': ?string, 'labels': array{'name': string}[], 'assignees': array{'login': string}[], 'requested_reviewers': array{'login': string}[], 'created_at': string, 'updated_at': string, head: array{sha: string}} $raw */
/** @var array{'title': string, 'body': ?string, 'state': string, 'merged': bool, 'labels': array{'name': string}[], 'assignees': array{'login': string}[], 'requested_reviewers': array{'login': string}[], 'created_at': string, 'updated_at': string, head: array{sha: string}} $raw */
$raw = $this->client->pullRequest()->show($owner, $repository, (int) $id);
$this->raw = $raw;

Expand All @@ -41,6 +42,9 @@ public function load(string $projectIdentifier, string $id): void
$this->pullRequest->assignees = array_map(static fn (array $assignee): string => $assignee['login'], $this->raw['assignees']
);
$this->pullRequest->reviewers = $this->getReviews($owner, $repository, $id);
$this->pullRequest->state = $this->raw['merged']
? PullRequest::STATE_MERGED
: ($this->raw['state'] === 'open' ? PullRequest::STATE_OPEN : PullRequest::STATE_CLOSED);
$this->pullRequest->createdAt = new \DateTime($this->raw['created_at']);
$this->pullRequest->updatedAt = new \DateTime($this->raw['updated_at']);
}
Expand Down
10 changes: 8 additions & 2 deletions src/Platform/Gitlab/Gitlab.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Danger\Config;
use Danger\Platform\AbstractPlatform;
use Danger\Struct\Gitlab\PullRequest;
use Danger\Struct\PullRequest as BasePullRequest;
use Gitlab\Client;

/**
* @property array{'sha': string, 'title': string, 'web_url': string, 'description': string|null, 'labels': string[], 'assignees': array{'username': string}[], 'reviewers': array{'username': string}[], 'created_at': string, 'updated_at': string} $raw
* @property array{'sha': string, 'title': string, 'web_url': string, 'description': string|null, 'state': string, 'labels': string[], 'assignees': array{'username': string}[], 'reviewers': array{'username': string}[], 'created_at': string, 'updated_at': string} $raw
*/
class Gitlab extends AbstractPlatform
{
Expand All @@ -23,7 +24,7 @@ public function load(string $projectIdentifier, string $id): void
{
$this->projectIdentifier = $projectIdentifier;

/** @var array{'sha': string, 'title': string, 'web_url': string, 'description': string|null, 'labels': string[], 'assignees': array{'username': string}[], 'reviewers': array{'username': string}[], 'created_at': string, 'updated_at': string} $res */
/** @var array{'sha': string, 'title': string, 'web_url': string, 'description': string|null, 'state': string, 'labels': string[], 'assignees': array{'username': string}[], 'reviewers': array{'username': string}[], 'created_at': string, 'updated_at': string} $res */
$res = $this->client->mergeRequests()->show($projectIdentifier, (int) $id);
$this->raw = $res;

Expand All @@ -35,6 +36,11 @@ public function load(string $projectIdentifier, string $id): void
$this->pullRequest->labels = $this->raw['labels'];
$this->pullRequest->assignees = array_map(static fn (array $assignee) => $assignee['username'], $this->raw['assignees']);
$this->pullRequest->reviewers = array_map(static fn (array $reviewer) => $reviewer['username'], $this->raw['reviewers']);
$this->pullRequest->state = match ($this->raw['state']) {
'merged' => BasePullRequest::STATE_MERGED,
'closed' => BasePullRequest::STATE_CLOSED,
default => BasePullRequest::STATE_OPEN,
};
$this->pullRequest->createdAt = new \DateTime($this->raw['created_at']);
$this->pullRequest->updatedAt = new \DateTime($this->raw['updated_at']);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Struct/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

abstract class PullRequest
{
public const STATE_OPEN = 'open';
public const STATE_CLOSED = 'closed';
public const STATE_MERGED = 'merged';

public string $id;

public string $projectIdentifier;
Expand All @@ -13,6 +17,8 @@ abstract class PullRequest

public string $body;

public string $state = self::STATE_OPEN;

public \DateTimeInterface $createdAt;

public \DateTimeInterface $updatedAt;
Expand Down
2 changes: 2 additions & 0 deletions tests/Platform/Github/GithubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Danger\Struct\Comment;
use Danger\Struct\Commit;
use Danger\Struct\File;
use Danger\Struct\PullRequest;
use Github\Client;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
Expand Down Expand Up @@ -46,6 +47,7 @@ public function testLoad(): void
static::assertSame(['Dependencies'], $github->pullRequest->labels);
static::assertSame(['shyim'], $github->pullRequest->assignees);
static::assertSame(['dangertestuser', 'dangertestuser2'], $github->pullRequest->reviewers);
static::assertSame(PullRequest::STATE_MERGED, $github->pullRequest->state);
static::assertSame(1_621_542_059, $github->pullRequest->createdAt->getTimestamp());
static::assertSame(1_621_547_349, $github->pullRequest->updatedAt->getTimestamp());

Expand Down
2 changes: 2 additions & 0 deletions tests/Platform/Gitlab/GitlabTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Danger\Struct\Comment;
use Danger\Struct\Commit;
use Danger\Struct\File;
use Danger\Struct\PullRequest;
use Gitlab\Client;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function testLoad(): void
static::assertSame(['Test'], $gitlab->pullRequest->labels);
static::assertSame(['shyim'], $gitlab->pullRequest->assignees);
static::assertSame(['dangertestuser', 'dangertestuser2'], $gitlab->pullRequest->reviewers);
static::assertSame(PullRequest::STATE_OPEN, $gitlab->pullRequest->state);
static::assertSame(1_621_638_766, $gitlab->pullRequest->createdAt->getTimestamp());
static::assertSame(1_621_672_778, $gitlab->pullRequest->updatedAt->getTimestamp());

Expand Down
Loading