File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ public function onPullRequest(GitHubEvent $event)
4444 return ;
4545 }
4646
47+ $ repository = $ event ->getRepository ();
48+ $ number = $ data ['number ' ];
49+
50+ $ lock = $ this ->lockFactory ->createLock ($ repository ->getFullName ().'# ' .$ number );
51+ $ lock ->acquire (true ); // blocking. Lock will be released at __destruct
52+
4753 $ originalTitle = $ prTitle = trim ($ data ['pull_request ' ]['title ' ]);
4854 $ validLabels = [];
4955 foreach ($ data ['pull_request ' ]['labels ' ] as $ label ) {
@@ -59,6 +65,11 @@ public function onPullRequest(GitHubEvent $event)
5965 }
6066 }
6167
68+ // Remove any other labels in the title.
69+ foreach ($ this ->labelExtractor ->extractLabels ($ prTitle , $ repository ) as $ label ) {
70+ $ prTitle = str_ireplace ('[ ' .$ label .'] ' , '' , $ prTitle );
71+ }
72+
6273 sort ($ validLabels );
6374 $ prPrefix = '' ;
6475 foreach ($ validLabels as $ label ) {
@@ -71,12 +82,6 @@ public function onPullRequest(GitHubEvent $event)
7182 return ;
7283 }
7384
74- $ repository = $ event ->getRepository ();
75- $ number = $ data ['number ' ];
76-
77- $ lock = $ this ->lockFactory ->createLock ($ repository ->getFullName ().'# ' .$ number );
78- $ lock ->acquire (true ); // blocking. Lock will be released at __destruct
79-
8085 // Refetch the current title just to make sure it has not changed
8186 if ($ prTitle === ($ this ->pullRequestApi ->show ($ repository , $ number )['title ' ] ?? '' )) {
8287 return ;
Original file line number Diff line number Diff line change @@ -129,4 +129,24 @@ public function testOnPullRequestLabeledTwice()
129129 $ responseData = $ event ->getResponseData ();
130130 $ this ->assertEmpty ($ responseData );
131131 }
132+
133+ public function testRemoveLabel ()
134+ {
135+ $ event = new GitHubEvent ([
136+ 'action ' => 'labeled ' ,
137+ 'number ' => 1234 ,
138+ 'pull_request ' => [
139+ 'title ' => '[Console][FrameworkBundle] [Random] Foo normal title ' ,
140+ 'labels ' => [
141+ ['name ' => 'Console ' , 'color ' => 'dddddd ' ],
142+ ],
143+ ],
144+ ], $ this ->repository );
145+
146+ $ this ->dispatcher ->dispatch ($ event , GitHubEvents::PULL_REQUEST );
147+ $ responseData = $ event ->getResponseData ();
148+ $ this ->assertCount (2 , $ responseData );
149+ $ this ->assertSame (1234 , $ responseData ['pull_request ' ]);
150+ $ this ->assertSame ('[Console] [Random] Foo normal title ' , $ responseData ['new_title ' ]);
151+ }
132152}
You can’t perform that action at this time.
0 commit comments