Skip to content

Commit a41de63

Browse files
committed
Better trim and add a test
1 parent 97f6487 commit a41de63

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function onPullRequest(GitHubEvent $event)
6161
}
6262

6363
// Add back labels
64-
$prTitle = trim($prPrefix.' '.$prTitle);
64+
$prTitle = trim($prPrefix.' '.trim($prTitle));
6565
if ($originalTitle === $prTitle) {
6666
return;
6767
}

tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp()
4242
$this->dispatcher->addSubscriber($this->subscriber);
4343
}
4444

45-
public function testOnPullRequestOpen()
45+
public function testOnPullRequestLabeled()
4646
{
4747
$event = new GitHubEvent([
4848
'action' => 'labeled',
@@ -63,4 +63,23 @@ public function testOnPullRequestOpen()
6363
$this->assertSame(1234, $responseData['pull_request']);
6464
$this->assertSame('[Console][FrameworkBundle] [bar] Foo', $responseData['new_title']);
6565
}
66+
67+
public function testOnPullRequestLabeledWithExisting()
68+
{
69+
$event = new GitHubEvent([
70+
'action' => 'labeled',
71+
'number' => 1234,
72+
'pull_request' => [
73+
'title' => '[Messenger] Fix JSON',
74+
'labels' => [
75+
['name' => 'Status: Needs Review', 'color' => 'abcabc'],
76+
['name' => 'Messenger', 'color' => 'dddddd'],
77+
],
78+
],
79+
], $this->repository);
80+
81+
$this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST);
82+
$responseData = $event->getResponseData();
83+
$this->assertEmpty($responseData);
84+
}
6685
}

0 commit comments

Comments
 (0)