From 5ad8eb589ded24371e792aea3861cd8cd5b5708f Mon Sep 17 00:00:00 2001 From: boherm Date: Mon, 3 Jun 2024 09:08:58 +0200 Subject: [PATCH] Ignore dependabot PR for Welcoming new contributors --- .../WelcomeNewContributorCommandHandler.php | 5 +++++ ...elcomeNewContributorCommandHandlerTest.php | 20 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandler.php b/src/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandler.php index 4e1baa9..311d7bb 100644 --- a/src/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandler.php +++ b/src/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandler.php @@ -19,6 +19,11 @@ public function __construct( public function __invoke(WelcomeNewContributorCommand $command): void { + // We ignore dependabot PRs. + if ('dependabot[bot]' === $command->contributor) { + return; + } + // We check if the committer is a new contributor. if ($this->committerRepository->isNewContributor($command->repositoryOwner, $command->repositoryName, $command->contributor)) { // If it is, we add a comment to the PR. diff --git a/tests/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandlerTest.php b/tests/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandlerTest.php index 8e07ebb..82d4ae6 100644 --- a/tests/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandlerTest.php +++ b/tests/PullRequest/Application/CommandHandler/WelcomeNewContributorCommandHandlerTest.php @@ -34,7 +34,7 @@ protected function setUp(): void /** * @dataProvider provideTestHandle */ - public function testHandle(PullRequestId $pullRequestId, bool $newContributor, bool $expectedComment): void + public function testHandle(PullRequestId $pullRequestId, string $contributor, bool $newContributor, bool $expectedComment): void { $this->prRepository->feed([ PullRequest::create( @@ -60,12 +60,12 @@ public function testHandle(PullRequestId $pullRequestId, bool $newContributor, b repositoryOwner: $pullRequestId->repositoryOwner, repositoryName: $pullRequestId->repositoryName, pullRequestNumber: $pullRequestId->pullRequestNumber, - contributor: 'fakeContributor', + contributor: $contributor, )); } /** - * @return array> + * @return array> */ public static function provideTestHandle(): array { @@ -76,6 +76,7 @@ public static function provideTestHandle(): array repositoryName: 'fake', pullRequestNumber: 'fake' ), + 'fakeContributor', false, false, ], @@ -85,6 +86,7 @@ public static function provideTestHandle(): array repositoryName: 'fake', pullRequestNumber: 'fake' ), + 'fakeContributor', true, true, ], @@ -94,6 +96,7 @@ public static function provideTestHandle(): array repositoryName: 'PrestaShop', pullRequestNumber: 'pullRequestNumber' ), + 'fakeContributor', false, false, ], @@ -103,9 +106,20 @@ public static function provideTestHandle(): array repositoryName: 'PrestaShop', pullRequestNumber: 'pullRequestNumber' ), + 'fakeContributor', true, true, ], + [ + new PullRequestId( + repositoryOwner: 'PrestaShop', + repositoryName: 'PrestaShop', + pullRequestNumber: 'pullRequestNumber' + ), + 'dependabot[bot]', + true, + false, + ], ]; } }