Skip to content

Commit ae9cdec

Browse files
committed
Added regex to parse comment body
1 parent 6616cbc commit ae9cdec

File tree

5 files changed

+6
-20
lines changed

5 files changed

+6
-20
lines changed

.github/workflows/find-reviewer.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
--ignore-path "src/Symfony/Bundle/FrameworkBundle/*" \
7979
--ignore-path "src/**/Tests/*" \
8080
--ignore-path CHANGELOG*.md \
81+
--ignore-path UPGRADE*.md \
8182
--pretty-print > output.json
8283
8384
cat output.json

src/Command/SuggestReviewerCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function configure()
3939
{
4040
$this->addArgument('repository', InputArgument::REQUIRED, 'The full name to the repository, eg symfony/symfony-docs');
4141
$this->addArgument('number', InputArgument::REQUIRED, 'Pull request number');
42-
$this->addArgument('type', InputArgument::REQUIRED, 'Typ is ether "suggest" or "demand".');
42+
$this->addArgument('type', InputArgument::REQUIRED, 'Type is either "suggest" or "demand".');
4343
$this->addArgument('contributor_json', InputArgument::REQUIRED, 'The path to the issue body text file');
4444
}
4545

@@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080
return 0;
8181
}
8282

83-
$this->issueApi->commentOnIssue($repository, $pullRequestNumber, 'Im sorry. I could not find any suitable reviewer.');
83+
$this->issueApi->commentOnIssue($repository, $pullRequestNumber, 'I\'m sorry. I could not find any suitable reviewer.');
8484

8585
return 0;
8686
}

src/Subscriber/FindReviewerSubscriber.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,13 @@ public function onComment(GitHubEvent $event)
5555
}
5656

5757
// Search for "review"
58-
$lines = explode(PHP_EOL, $data['comment']['body'] ?? '');
59-
foreach ($lines as $line) {
60-
if (false === strpos($line, $this->botUsername)) {
61-
continue;
62-
}
63-
64-
if (false === strpos($line, 'review')) {
65-
continue;
66-
}
67-
58+
if (preg_match('~\@carsonbot(\W[^(status)].*|\W)(\breviewer\b|\breview\b)~i', $data['comment']['body'] ?? '')) {
6859
$number = $data['issue']['number'];
6960
$this->pullRequestApi->findReviewer($event->getRepository(), $number, SuggestReviewerCommand::TYPE_DEMAND);
7061
$event->setResponseData([
7162
'issue' => $number,
7263
'suggest-review' => true,
7364
]);
74-
75-
return;
7665
}
7766
}
7867

tests/Subscriber/FindReviewerSubscriberTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
namespace App\Tests\Subscriber;
44

5-
use App\Api\Milestone\GithubMilestoneApi;
65
use App\Api\PullRequest\NullPullRequestApi;
76
use App\Command\SuggestReviewerCommand;
87
use App\Event\GitHubEvent;
98
use App\GitHubEvents;
109
use App\Model\Repository;
11-
use App\Service\SymfonyVersionProvider;
1210
use App\Service\TaskScheduler;
1311
use App\Subscriber\FindReviewerSubscriber;
14-
use App\Subscriber\MilestoneNewPRSubscriber;
1512
use App\Tests\ValidCommandProvider;
1613
use PHPUnit\Framework\TestCase;
1714
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -87,10 +84,10 @@ public function commentProvider()
8784
yield ['Some random', false];
8885
yield ['@carsonbot foobar', false];
8986
yield ['See the review please', false];
87+
yield ["@carsonbot please\nfind a reviewer for me", false];
9088

9189
foreach (ValidCommandProvider::get() as $data) {
92-
yield [$data[0], $data[1] === FindReviewerSubscriber::class];
90+
yield [$data[0], FindReviewerSubscriber::class === $data[1]];
9391
}
9492
}
95-
9693
}

tests/ValidCommandProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\Subscriber\FindReviewerSubscriber;
66
use App\Subscriber\StatusChangeByCommentSubscriber;
7-
use App\Subscriber\StatusChangeByReviewSubscriber;
87

98
/**
109
* To be used in unit tests to make sure subscribers' commands don't conflict.

0 commit comments

Comments
 (0)