Skip to content

Commit 35bec43

Browse files
committed
bug #211 Improve Mismatch branch when there is markdown comment (alamirault)
This PR was squashed before being merged into the master branch. Discussion ---------- Improve Mismatch branch when there is markdown comment Sometime, contributors don't remove all the line and keep markdown comment (default in MR template) ``` | Q | A | ------------- | --- | Branch? | 6.2 <!-- see below --> | Bug fix? | yes/no ``` This PR take care of comments and no publish in this cas Examples: symfony/symfony#48451 (comment) symfony/symfony#48447 (comment) Commits ------- 75e3578 Improve Mismatch branch when there is markdown comment
2 parents b23ccdd + 75e3578 commit 35bec43

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/Subscriber/MismatchBranchDescriptionSubscriber.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ public static function getSubscribedEvents(): array
7272
private function extractDescriptionBranchFromBody(string $body): ?string
7373
{
7474
$s = new UnicodeString($body);
75+
$bodyWithoutComment = $s->replaceMatches('/<!--\s*.*\s*-->/', '');
7576

7677
// @see symfony/symfony/.github/PULL_REQUEST_TEMPLATE.md
77-
if (!$s->containsAny('Branch?')) {
78+
if (!$bodyWithoutComment->containsAny('Branch?')) {
7879
return null;
7980
}
8081

81-
$rowsDescriptionBranch = $s->match('/.*Branch.*/');
82+
$rowsDescriptionBranch = $bodyWithoutComment->match('/.*Branch.*/');
8283

8384
$rowDescriptionBranch = $rowsDescriptionBranch[0]; // row matching
8485

tests/Controller/WebhookControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getTests()
8787
'On pull request opened with target branch' => [
8888
'pull_request',
8989
'pull_request.opened_target_branch.json',
90-
['pull_request' => 3, 'status_change' => 'needs_review', 'pr_labels' => ['Bug'], 'milestone' => '4.4', 'approved_run' => true],
90+
['pull_request' => 3, 'status_change' => 'needs_review', 'pr_labels' => ['Bug'], 'milestone' => '4.4', 'unsupported_branch' => '4.4', 'approved_run' => true],
9191
],
9292
'On issue labeled bug' => [
9393
'issues',

tests/Subscriber/MismatchBranchDescriptionSubscriberTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ public function testOnPullRequestOpenMatch()
6969
$this->assertCount(0, $responseData);
7070
}
7171

72+
public function testOnPullRequestOpenMatchWithComment()
73+
{
74+
$this->issueApi->expects($this->never())
75+
->method('commentOnIssue');
76+
77+
$body = <<<TXT
78+
| Q | A
79+
| ------------- | ---
80+
| Branch? | 6.2 <!-- see below -->
81+
| Bug fix? | yes/no
82+
TXT;
83+
84+
$event = new GitHubEvent([
85+
'action' => 'opened',
86+
'pull_request' => [
87+
'number' => 1234,
88+
'body' => $body,
89+
'base' => [
90+
'ref' => '6.2',
91+
],
92+
],
93+
], $this->repository);
94+
95+
$this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST);
96+
$responseData = $event->getResponseData();
97+
98+
$this->assertCount(0, $responseData);
99+
}
100+
72101
public function testOnPullRequestOpenNotMatch()
73102
{
74103
$this->issueApi->expects($this->once())

0 commit comments

Comments
 (0)