Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark committed Sep 16, 2024
1 parent d009c08 commit ccb608d
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/Api/PullRequest/GithubPullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function show(Repository $repository, $number): array
return (array) $this->pullRequest->show($repository->getVendor(), $repository->getName(), $number);
}

public function updateTitle(Repository $repository, $number, string $title, string $body = null): void
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void
{
$params = ['title' => $title];

Expand Down
2 changes: 1 addition & 1 deletion src/Api/PullRequest/NullPullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function show(Repository $repository, $number): array
return [];
}

public function updateTitle(Repository $repository, $number, string $title, string $body = null): void
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/PullRequest/PullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface PullRequestApi
{
public function show(Repository $repository, $number): array;

public function updateTitle(Repository $repository, $number, string $title, string $body = null): void;
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void;

public function getAuthorCount(Repository $repository, string $author): int;
}
53 changes: 19 additions & 34 deletions src/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
/**
* A "Task" is a scheduled job.
*
* @ORM\Table
*
* @ORM\Entity(repositoryClass="App\Repository\TaskRepository")
*
* @ORM\HasLifecycleCallbacks()
*
* @author Tobias Nyholm <[email protected]>
*/
#[ORM\Entity(repositoryClass: \App\Repository\TaskRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ORM\Table]
class Task
{
public const ACTION_CLOSE_STALE = 1;
Expand All @@ -23,42 +20,33 @@ class Task

/**
* @var int
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;

/**
* @var \DateTimeImmutable
*
* @ORM\Column(type="datetime_immutable")
*/
#[ORM\Column(type: 'datetime_immutable')]
private $createdAt;

/**
* @var \DateTimeImmutable
*
* @ORM\Column(type="datetime_immutable")
*/
#[ORM\Column(type: 'datetime_immutable')]
private $updatedAt;

public function __construct(/**
* @ORM\Column(type="string")
*/
private string $repositoryFullName, /**
* @ORM\Column(type="integer")
*/
private int $number, /**
* @ORM\Column(type="integer")
*/
private int $action, /**
* @ORM\Column(type="datetime_immutable")
*/
private \DateTimeImmutable $verifyAfter)
public function __construct(
#[ORM\Column(type: 'string')]
private readonly string $repositoryFullName,
#[ORM\Column(type: 'integer')]
private readonly int $number,
#[ORM\Column(type: 'integer')]
private readonly int $action,
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $verifyAfter)
{
$this->createdAt = new \DateTimeImmutable();
}
Expand Down Expand Up @@ -93,11 +81,8 @@ public function setVerifyAfter(\DateTimeImmutable $verifyAfter): void
$this->verifyAfter = $verifyAfter;
}

/**
* @ORM\PrePersist
*
* @ORM\PreUpdate
*/
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function updateUpdatedAt()
{
$this->updatedAt = new \DateTimeImmutable();
Expand Down
5 changes: 2 additions & 3 deletions src/Model/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public function __construct(
/**
* The webhook secret used by GitHub.
*/
private readonly ?string $secret = null
)
{
private readonly ?string $secret = null,
) {
}

public function getVendor(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Service/LabelNameExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getAliasesForLabel($label)
private function getLabels(Repository $repository)
{
$allLabels = $this->labelsApi->getAllLabelsForRepository($repository);
$closure = fn($s) => strtolower((string) $s);
$closure = fn ($s) => strtolower((string) $s);

return array_combine(array_map($closure, $allLabels), $allLabels);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Service/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public function __construct(
* @var iterable<TaskHandlerInterface>
*/
private readonly iterable $handlers,
private readonly LoggerInterface $logger
)
{
private readonly LoggerInterface $logger,
) {
}

public function run(Task $task)
Expand Down
2 changes: 1 addition & 1 deletion src/Subscriber/StatusChangeByReviewSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function onReview(GitHubEvent $event)
/**
* Sets the status to needs review when a review is requested.
*/
public function onReviewRequested(GithubEvent $event)
public function onReviewRequested(GitHubEvent $event)
{
$data = $event->getData();
if ('review_requested' !== $data['action']) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/Label/GithubLabelApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp(): void
->disableOriginalConstructor()
->setMethods(['fetchAll'])
->getMock();
$resultPager->method('fetchAll')->willReturnCallback(fn() => $this->backendApi->all('x', 'y'));
$resultPager->method('fetchAll')->willReturnCallback(fn () => $this->backendApi->all('x', 'y'));

$this->api = new GithubLabelApi($this->backendApi, $resultPager, new NullAdapter(), new NullLogger());
$this->repository = new Repository(
Expand Down
32 changes: 16 additions & 16 deletions tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public function testOnPullRequestLabeledWithExisting()
{
$event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository);
$this->pullRequestApi->method('show')->willReturn([
'title' => '[Messenger] Fix JSON',
'labels' => [
['name' => 'Status: Needs Review', 'color' => 'abcabc'],
['name' => 'Messenger', 'color' => 'dddddd'],
],
]);
'title' => '[Messenger] Fix JSON',
'labels' => [
['name' => 'Status: Needs Review', 'color' => 'abcabc'],
['name' => 'Messenger', 'color' => 'dddddd'],
],
]);

$this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST);
$responseData = $event->getResponseData();
Expand All @@ -100,11 +100,11 @@ public function testRemoveLabel()
{
$event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository);
$this->pullRequestApi->method('show')->willReturn([
'title' => '[Console][FrameworkBundle] [Random] Foo normal title',
'labels' => [
['name' => 'Console', 'color' => 'dddddd'],
],
]);
'title' => '[Console][FrameworkBundle] [Random] Foo normal title',
'labels' => [
['name' => 'Console', 'color' => 'dddddd'],
],
]);

$this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST);
$responseData = $event->getResponseData();
Expand All @@ -117,11 +117,11 @@ public function testExtraBlankSpace()
{
$event = new GitHubEvent(['action' => 'labeled', 'number' => 57753, 'pull_request' => []], $this->repository);
$this->pullRequestApi->method('show')->willReturn([
'title' => '[ErrorHandler]&nbsp;restrict the maximum length of the X-Debug-Exception header',
'labels' => [
['name' => 'ErrorHandler', 'color' => 'dddddd'],
],
]);
'title' => '[ErrorHandler]&nbsp;restrict the maximum length of the X-Debug-Exception header',
'labels' => [
['name' => 'ErrorHandler', 'color' => 'dddddd'],
],
]);

$this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST);
$responseData = $event->getResponseData();
Expand Down

0 comments on commit ccb608d

Please sign in to comment.