From 9c7dac869f4d975bca4655875de4c8662099e794 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 8 Aug 2025 12:34:08 +0200 Subject: [PATCH 1/8] Add comprehensive test cases for label spacing in PR titles Added multiple test cases to ensure labels are always concatenated without spaces between brackets. These tests verify the correct behavior in various scenarios including incremental label additions and empty titles. --- ...AutoUpdateTitleWithLabelSubscriberTest.php | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php index 6a935f4..6d1ae4a 100644 --- a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php +++ b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php @@ -129,4 +129,200 @@ public function testExtraBlankSpace() $this->assertSame(57753, $responseData['pull_request']); $this->assertSame('[ErrorHandler] restrict the maximum length of the X-Debug-Exception header', $responseData['new_title']); } + + public function testMultipleLabelsWithoutSpaceBetweenBrackets() + { + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => 'Foo Bar', + 'labels' => [ + ['name' => 'Platform', 'color' => 'dddddd'], + ['name' => 'Agent', 'color' => 'dddddd'], + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + $this->assertSame('[Agent][Platform] Foo Bar', $responseData['new_title']); + } + + public function testMultipleLabelsUpdateRemovesSpaceBetweenBrackets() + { + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => '[Platform] [Agent] Foo Bar', // Title already has labels with space + 'labels' => [ + ['name' => 'Platform', 'color' => 'dddddd'], + ['name' => 'Agent', 'color' => 'dddddd'], + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + $this->assertSame('[Agent][Platform] Foo Bar', $responseData['new_title']); + } + + public function testAddingLabelToExistingLabeledTitle() + { + // Simulating when we already have [Platform] and are adding Agent label + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => '[Platform] Foo Bar', // Title already has one label + 'labels' => [ + ['name' => 'Platform', 'color' => 'dddddd'], + ['name' => 'Agent', 'color' => 'dddddd'], // New label added + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + $this->assertSame('[Agent][Platform] Foo Bar', $responseData['new_title']); + } + + public function testLabelsNotRecognizedAsValidLabels() + { + // This test simulates what happens when [Platform] and [Agent] are in the title + // but they're NOT recognized as valid labels (wrong case or not in label list) + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => '[Platform] [Agent] Foo Bar', // These are in title but not recognized + 'labels' => [ + ['name' => 'Bug', 'color' => 'dddddd'], // Different valid label + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + // Since Platform and Agent are not recognized labels, they stay in the title with the space + $this->assertSame('[Bug] [Platform] [Agent] Foo Bar', $responseData['new_title']); + } + + /** + * This test reproduces the actual bug: when labels are attached to the PR + * but are not in the repository's configured label list, they won't be + * removed from the title, causing spacing issues. + */ + public function testBugWithLabelsNotInRepositoryLabelList() + { + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => 'Foo Bar', + 'labels' => [ + // These labels are attached to PR but not in the StaticLabelApi list + ['name' => 'Platform', 'color' => 'dddddd'], + ['name' => 'Agent', 'color' => 'dddddd'], + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + + // The bug would cause this to be '[Platform] [Agent] Foo Bar' + // because the labels are added with concatenation but not recognized + // for removal from the title + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + + // This is what SHOULD happen (labels concatenated without spaces) + $this->assertSame('[Agent][Platform] Foo Bar', $responseData['new_title']); + } + + /** + * Test simulating incremental label additions as would happen with multiple webhooks + */ + public function testIncrementalLabelAdditions() + { + // Need to create a new mock for each test to avoid expectations interference + $pullRequestApi1 = $this->getMockBuilder(NullPullRequestApi::class) + ->disableOriginalConstructor() + ->setMethods(['show']) + ->getMock(); + + $pullRequestApi1->expects($this->once())->method('show')->willReturn([ + 'title' => 'Foo Bar', + 'labels' => [ + ['name' => 'FrameworkBundle', 'color' => 'dddddd'], + ], + ]); + + $store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); + $store->method('exists')->willReturn(false); + + $labelsApi = new StaticLabelApi(); + $subscriber1 = new AutoUpdateTitleWithLabelSubscriber( + new LabelNameExtractor($labelsApi, new NullLogger()), + $pullRequestApi1, + new LockFactory($store) + ); + + $dispatcher1 = new EventDispatcher(); + $dispatcher1->addSubscriber($subscriber1); + + // First webhook: FrameworkBundle label added + $event1 = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $dispatcher1->dispatch($event1, GitHubEvents::PULL_REQUEST); + $responseData1 = $event1->getResponseData(); + $this->assertSame('[FrameworkBundle] Foo Bar', $responseData1['new_title']); + + // Second webhook: Console label added (title now has [FrameworkBundle] in it) + $pullRequestApi2 = $this->getMockBuilder(NullPullRequestApi::class) + ->disableOriginalConstructor() + ->setMethods(['show']) + ->getMock(); + + $pullRequestApi2->expects($this->once())->method('show')->willReturn([ + 'title' => '[FrameworkBundle] Foo Bar', // Title from first update + 'labels' => [ + ['name' => 'FrameworkBundle', 'color' => 'dddddd'], + ['name' => 'Console', 'color' => 'dddddd'], + ], + ]); + + $subscriber2 = new AutoUpdateTitleWithLabelSubscriber( + new LabelNameExtractor($labelsApi, new NullLogger()), + $pullRequestApi2, + new LockFactory($store) + ); + + $dispatcher2 = new EventDispatcher(); + $dispatcher2->addSubscriber($subscriber2); + + $event2 = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $dispatcher2->dispatch($event2, GitHubEvents::PULL_REQUEST); + $responseData2 = $event2->getResponseData(); + // Should produce [Console][FrameworkBundle] without space + $this->assertSame('[Console][FrameworkBundle] Foo Bar', $responseData2['new_title']); + } + + /** + * Test that ensures no spaces are ever added between label brackets + */ + public function testNoSpacesBetweenLabelBrackets() + { + // Test with empty title after label removal + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => '[Console] [FrameworkBundle]', // Only labels, no other text + 'labels' => [ + ['name' => 'Console', 'color' => 'dddddd'], + ['name' => 'FrameworkBundle', 'color' => 'dddddd'], + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + + // Should produce labels without spaces and no trailing space + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + $this->assertSame('[Console][FrameworkBundle]', $responseData['new_title']); + } } From afea77da29401c5d63b3b40267b2a99c43f6900d Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 8 Aug 2025 12:59:13 +0200 Subject: [PATCH 2/8] Remove redundant testIncrementalLabelAdditions test This test was overly complex and didn't test anything that wasn't already covered by other simpler tests. --- ...AutoUpdateTitleWithLabelSubscriberTest.php | 67 ------------------- 1 file changed, 67 deletions(-) diff --git a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php index 6d1ae4a..fde29ec 100644 --- a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php +++ b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php @@ -235,73 +235,6 @@ public function testBugWithLabelsNotInRepositoryLabelList() $this->assertSame('[Agent][Platform] Foo Bar', $responseData['new_title']); } - /** - * Test simulating incremental label additions as would happen with multiple webhooks - */ - public function testIncrementalLabelAdditions() - { - // Need to create a new mock for each test to avoid expectations interference - $pullRequestApi1 = $this->getMockBuilder(NullPullRequestApi::class) - ->disableOriginalConstructor() - ->setMethods(['show']) - ->getMock(); - - $pullRequestApi1->expects($this->once())->method('show')->willReturn([ - 'title' => 'Foo Bar', - 'labels' => [ - ['name' => 'FrameworkBundle', 'color' => 'dddddd'], - ], - ]); - - $store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); - $store->method('exists')->willReturn(false); - - $labelsApi = new StaticLabelApi(); - $subscriber1 = new AutoUpdateTitleWithLabelSubscriber( - new LabelNameExtractor($labelsApi, new NullLogger()), - $pullRequestApi1, - new LockFactory($store) - ); - - $dispatcher1 = new EventDispatcher(); - $dispatcher1->addSubscriber($subscriber1); - - // First webhook: FrameworkBundle label added - $event1 = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); - $dispatcher1->dispatch($event1, GitHubEvents::PULL_REQUEST); - $responseData1 = $event1->getResponseData(); - $this->assertSame('[FrameworkBundle] Foo Bar', $responseData1['new_title']); - - // Second webhook: Console label added (title now has [FrameworkBundle] in it) - $pullRequestApi2 = $this->getMockBuilder(NullPullRequestApi::class) - ->disableOriginalConstructor() - ->setMethods(['show']) - ->getMock(); - - $pullRequestApi2->expects($this->once())->method('show')->willReturn([ - 'title' => '[FrameworkBundle] Foo Bar', // Title from first update - 'labels' => [ - ['name' => 'FrameworkBundle', 'color' => 'dddddd'], - ['name' => 'Console', 'color' => 'dddddd'], - ], - ]); - - $subscriber2 = new AutoUpdateTitleWithLabelSubscriber( - new LabelNameExtractor($labelsApi, new NullLogger()), - $pullRequestApi2, - new LockFactory($store) - ); - - $dispatcher2 = new EventDispatcher(); - $dispatcher2->addSubscriber($subscriber2); - - $event2 = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); - $dispatcher2->dispatch($event2, GitHubEvents::PULL_REQUEST); - $responseData2 = $event2->getResponseData(); - // Should produce [Console][FrameworkBundle] without space - $this->assertSame('[Console][FrameworkBundle] Foo Bar', $responseData2['new_title']); - } - /** * Test that ensures no spaces are ever added between label brackets */ From 08b3f765d02e1cd32065f3ab0f5f6b21498c32b3 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 8 Aug 2025 13:18:37 +0200 Subject: [PATCH 3/8] Fix label spacing when title contains unrecognized bracketed text When a title contains bracketed text like [Foo] that isn't a recognized label, and a real label is added, ensure all brackets are concatenated without spaces. For example, adding 'Platform' label to '[Foo] Bar' now produces '[Platform][Foo] Bar' instead of '[Platform] [Foo] Bar'. - Extract and preserve bracketed text at the beginning of titles - Concatenate all brackets (labels and non-labels) without spaces - Add comprehensive test cases for mixed recognized/unrecognized brackets --- .../AutoUpdateTitleWithLabelSubscriber.php | 18 ++++++- ...AutoUpdateTitleWithLabelSubscriberTest.php | 54 +++++++++++++++++-- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php b/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php index 9965d8a..a8d5816 100644 --- a/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php +++ b/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php @@ -75,8 +75,22 @@ public function onPullRequest(GitHubEvent $event): void // Clean string from all HTML chars and remove whitespace at the beginning $prTitle = (string) preg_replace('@^[\h\s]+@u', '', html_entity_decode($prTitle)); - // Add back labels - $prTitle = trim($prPrefix.' '.trim($prTitle)); + // Extract any bracketed text at the beginning of the title + $leadingBrackets = ''; + $remainingTitle = $prTitle; + + // Match all consecutive bracketed items at the start of the title + while (preg_match('/^\[([^\]]+)\]\s*/', $remainingTitle, $matches)) { + $leadingBrackets .= '['.$matches[1].']'; + $remainingTitle = substr($remainingTitle, strlen($matches[0])); + } + + // Combine: valid labels + any unrecognized brackets + remaining title + if ('' !== trim($remainingTitle)) { + $prTitle = $prPrefix.$leadingBrackets.' '.trim($remainingTitle); + } else { + $prTitle = $prPrefix.$leadingBrackets; + } if ($originalTitle === $prTitle) { return; } diff --git a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php index fde29ec..47d143c 100644 --- a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php +++ b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php @@ -59,7 +59,7 @@ public function testOnPullRequestLabeled() $this->assertCount(2, $responseData); $this->assertSame(1234, $responseData['pull_request']); - $this->assertSame('[Console][FrameworkBundle] [bar] Foo', $responseData['new_title']); + $this->assertSame('[Console][FrameworkBundle][bar] Foo', $responseData['new_title']); } public function testOnPullRequestLabeledCaseInsensitive() @@ -110,7 +110,7 @@ public function testRemoveLabel() $responseData = $event->getResponseData(); $this->assertCount(2, $responseData); $this->assertSame(1234, $responseData['pull_request']); - $this->assertSame('[Console] [Random] Foo normal title', $responseData['new_title']); + $this->assertSame('[Console][Random] Foo normal title', $responseData['new_title']); } public function testExtraBlankSpace() @@ -201,8 +201,8 @@ public function testLabelsNotRecognizedAsValidLabels() $responseData = $event->getResponseData(); $this->assertCount(2, $responseData); $this->assertSame(1234, $responseData['pull_request']); - // Since Platform and Agent are not recognized labels, they stay in the title with the space - $this->assertSame('[Bug] [Platform] [Agent] Foo Bar', $responseData['new_title']); + // Since Platform and Agent are not recognized labels, they stay in the title without spaces + $this->assertSame('[Bug][Platform][Agent] Foo Bar', $responseData['new_title']); } /** @@ -258,4 +258,50 @@ public function testNoSpacesBetweenLabelBrackets() $this->assertSame(1234, $responseData['pull_request']); $this->assertSame('[Console][FrameworkBundle]', $responseData['new_title']); } + + /** + * Test when title has unrecognized bracketed text like [Foo] that isn't a label + */ + public function testUnrecognizedBracketedTextWithNewLabel() + { + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => '[Foo] Bar', // [Foo] is not a recognized label + 'labels' => [ + ['name' => 'Console', 'color' => 'dddddd'], // Adding Console label + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + + // Currently produces: [Console] [Foo] Bar (with space) + // Should produce: [Console][Foo] Bar (no space between brackets) + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + $this->assertSame('[Console][Foo] Bar', $responseData['new_title']); + } + + /** + * Test multiple unrecognized bracketed texts with real labels + */ + public function testMultipleUnrecognizedBracketsWithRealLabels() + { + $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); + $this->pullRequestApi->method('show')->willReturn([ + 'title' => '[TODO] [WIP] [Foo] Some title', // [TODO], [WIP], [Foo] are not recognized labels + 'labels' => [ + ['name' => 'Console', 'color' => 'dddddd'], + ['name' => 'FrameworkBundle', 'color' => 'dddddd'], + ], + ]); + + $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); + $responseData = $event->getResponseData(); + + // Should keep unrecognized brackets but without spaces between any brackets + $this->assertCount(2, $responseData); + $this->assertSame(1234, $responseData['pull_request']); + $this->assertSame('[Console][FrameworkBundle][TODO][WIP][Foo] Some title', $responseData['new_title']); + } } From 183f3bb7d6237b1c0bc20322e21d8766a6c6bcc6 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 8 Aug 2025 14:43:29 +0200 Subject: [PATCH 4/8] Update src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php Co-authored-by: Tobias Nyholm --- src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php b/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php index a8d5816..7e3fe17 100644 --- a/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php +++ b/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php @@ -80,7 +80,7 @@ public function onPullRequest(GitHubEvent $event): void $remainingTitle = $prTitle; // Match all consecutive bracketed items at the start of the title - while (preg_match('/^\[([^\]]+)\]\s*/', $remainingTitle, $matches)) { + while (preg_match('/^\[([^]]+)]\s*/', $remainingTitle, $matches)) { $leadingBrackets .= '['.$matches[1].']'; $remainingTitle = substr($remainingTitle, strlen($matches[0])); } From 67b516222141114d1fabc03da855b49595eb163f Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Sat, 9 Aug 2025 08:38:49 +0200 Subject: [PATCH 5/8] Update tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php --- tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php index 47d143c..11f363b 100644 --- a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php +++ b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php @@ -205,11 +205,6 @@ public function testLabelsNotRecognizedAsValidLabels() $this->assertSame('[Bug][Platform][Agent] Foo Bar', $responseData['new_title']); } - /** - * This test reproduces the actual bug: when labels are attached to the PR - * but are not in the repository's configured label list, they won't be - * removed from the title, causing spacing issues. - */ public function testBugWithLabelsNotInRepositoryLabelList() { $event = new GitHubEvent(['action' => 'labeled', 'number' => 1234, 'pull_request' => []], $this->repository); From f06e5c50f3c5f21c3cd05ba4648879eede5dc929 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Sat, 9 Aug 2025 10:17:34 +0200 Subject: [PATCH 6/8] Update AutoUpdateTitleWithLabelSubscriberTest.php --- tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php index 11f363b..10dc26f 100644 --- a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php +++ b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php @@ -220,7 +220,6 @@ public function testBugWithLabelsNotInRepositoryLabelList() $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); $responseData = $event->getResponseData(); - // The bug would cause this to be '[Platform] [Agent] Foo Bar' // because the labels are added with concatenation but not recognized // for removal from the title $this->assertCount(2, $responseData); From eb21d527850267c428cfe55b22c8ddce5562d2a8 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 8 Aug 2025 14:48:00 +0200 Subject: [PATCH 7/8] Fix code style issues - Remove trailing whitespace on blank lines - Add periods to PHPDoc summaries --- .../AutoUpdateTitleWithLabelSubscriber.php | 4 ++-- .../AutoUpdateTitleWithLabelSubscriberTest.php | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php b/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php index 7e3fe17..eea7726 100644 --- a/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php +++ b/src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php @@ -78,13 +78,13 @@ public function onPullRequest(GitHubEvent $event): void // Extract any bracketed text at the beginning of the title $leadingBrackets = ''; $remainingTitle = $prTitle; - + // Match all consecutive bracketed items at the start of the title while (preg_match('/^\[([^]]+)]\s*/', $remainingTitle, $matches)) { $leadingBrackets .= '['.$matches[1].']'; $remainingTitle = substr($remainingTitle, strlen($matches[0])); } - + // Combine: valid labels + any unrecognized brackets + remaining title if ('' !== trim($remainingTitle)) { $prTitle = $prPrefix.$leadingBrackets.' '.trim($remainingTitle); diff --git a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php index 10dc26f..6078ca7 100644 --- a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php +++ b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php @@ -219,18 +219,19 @@ public function testBugWithLabelsNotInRepositoryLabelList() $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); $responseData = $event->getResponseData(); - + + // The bug would cause this to be '[Platform] [Agent] Foo Bar' // because the labels are added with concatenation but not recognized // for removal from the title $this->assertCount(2, $responseData); $this->assertSame(1234, $responseData['pull_request']); - + // This is what SHOULD happen (labels concatenated without spaces) $this->assertSame('[Agent][Platform] Foo Bar', $responseData['new_title']); } /** - * Test that ensures no spaces are ever added between label brackets + * Test that ensures no spaces are ever added between label brackets. */ public function testNoSpacesBetweenLabelBrackets() { @@ -246,7 +247,7 @@ public function testNoSpacesBetweenLabelBrackets() $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); $responseData = $event->getResponseData(); - + // Should produce labels without spaces and no trailing space $this->assertCount(2, $responseData); $this->assertSame(1234, $responseData['pull_request']); @@ -254,7 +255,7 @@ public function testNoSpacesBetweenLabelBrackets() } /** - * Test when title has unrecognized bracketed text like [Foo] that isn't a label + * Test when title has unrecognized bracketed text like [Foo] that isn't a label. */ public function testUnrecognizedBracketedTextWithNewLabel() { @@ -268,7 +269,7 @@ public function testUnrecognizedBracketedTextWithNewLabel() $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); $responseData = $event->getResponseData(); - + // Currently produces: [Console] [Foo] Bar (with space) // Should produce: [Console][Foo] Bar (no space between brackets) $this->assertCount(2, $responseData); @@ -277,7 +278,7 @@ public function testUnrecognizedBracketedTextWithNewLabel() } /** - * Test multiple unrecognized bracketed texts with real labels + * Test multiple unrecognized bracketed texts with real labels. */ public function testMultipleUnrecognizedBracketsWithRealLabels() { @@ -292,7 +293,7 @@ public function testMultipleUnrecognizedBracketsWithRealLabels() $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); $responseData = $event->getResponseData(); - + // Should keep unrecognized brackets but without spaces between any brackets $this->assertCount(2, $responseData); $this->assertSame(1234, $responseData['pull_request']); From f0f67f58351a686711ba695a1b6a931fa3c70159 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Sat, 9 Aug 2025 14:08:31 +0200 Subject: [PATCH 8/8] Remove explanatory comment from test --- tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php index 6078ca7..174fd01 100644 --- a/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php +++ b/tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php @@ -220,13 +220,8 @@ public function testBugWithLabelsNotInRepositoryLabelList() $this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST); $responseData = $event->getResponseData(); - // The bug would cause this to be '[Platform] [Agent] Foo Bar' - // because the labels are added with concatenation but not recognized - // for removal from the title $this->assertCount(2, $responseData); $this->assertSame(1234, $responseData['pull_request']); - - // This is what SHOULD happen (labels concatenated without spaces) $this->assertSame('[Agent][Platform] Foo Bar', $responseData['new_title']); }