Skip to content

Commit 3da3003

Browse files
committed
Improved the way we extract labels from PR titles
1 parent 32b8076 commit 3da3003

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/AppBundle/Issues/IssueListener.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public function handlePullRequestCreatedEvent($prNumber, $prTitle, $prBody)
7171
$newStatus = Status::NEEDS_REVIEW;
7272
$prLabels[] = $newStatus;
7373

74-
// the PR title usually indicates the affected component
75-
if (preg_match('/^\[(?P<component>.*)\] .*/$', $prTitle, $matches)) {
76-
$prLabels[] = $matches['component'];
74+
// the PR title usually contains one or more labels
75+
foreach ($this->extractLabels($prTitle) as $label) {
76+
$prLabels[] = $label;
7777
}
7878

7979
// the PR body usually indicates if this is a Bug, Feature, BC Break or Deprecation
@@ -123,4 +123,40 @@ public function handleLabelAddedEvent($issueNumber, $label)
123123

124124
return $newStatus;
125125
}
126+
127+
private function extractLabels($prTitle)
128+
{
129+
$labels = array();
130+
131+
// e.g. "[PropertyAccess] [RFC] [WIP] Allow custom methods on property accesses"
132+
if (preg_match_all('/\[(?P<tags>.+)\]/U', $prTitle, $matches)) {
133+
foreach ($matches['tags'] as $tag) {
134+
if (in_array($tag, $this->getValidTags())) {
135+
$labels[] = $tag;
136+
}
137+
}
138+
}
139+
140+
return $labels;
141+
}
142+
143+
/**
144+
* TODO: get valid tags from the repository via GitHub API
145+
*/
146+
private function getValidTags()
147+
{
148+
return array(
149+
'Asset', 'BC Break', 'BrowserKit', 'Bug', 'Cache', 'ClassLoader',
150+
'Config', 'Console', 'Critical', 'CssSelector', 'Debug', 'DebugBundle',
151+
'DependencyInjection', 'Deprecation', 'Doctrine', 'DoctrineBridge',
152+
'DomCrawler', 'Drupal related', 'DX', 'Easy Pick', 'Enhancement',
153+
'EventDispatcher', 'ExpressionLanguage', 'Feature', 'Filesystem',
154+
'Finder', 'Form', 'FrameworkBundle', 'HttpFoundation', 'HttpKernel',
155+
'Intl', 'Ldap', 'Locale', 'MonologBridge', 'OptionsResolver',
156+
'PhpUnitBridge', 'Process', 'PropertyAccess', 'PropertyInfo', 'Ready',
157+
'RFC', 'Routing', 'Security', 'SecurityBundle', 'Serializer',
158+
'Stopwatch', 'Templating', 'Translator', 'TwigBridge', 'TwigBundle',
159+
'Unconfirmed', 'Validator', 'VarDumper', 'WebProfilerBundle', 'Yaml',
160+
);
161+
}
126162
}

0 commit comments

Comments
 (0)