Skip to content

Commit ea11d31

Browse files
committed
[#52] Adding a test and fixing a few small bugs with the new aliases
1 parent 79e5f33 commit ea11d31

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/AppBundle/Subscriber/AutoLabelPRFromContentSubscriber.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class AutoLabelPRFromContentSubscriber implements EventSubscriberInterface
1414
{
1515
private $labelsApi;
1616

17+
private static $labelAliases = [
18+
'di' => 'DependencyInjection',
19+
'bridge\twig' => 'TwigBridge',
20+
'router' => 'Routing',
21+
'translation' => 'Translator',
22+
'twig bridge' => 'TwigBridge',
23+
];
24+
1725
public function __construct(CachedLabelsApi $labelsApi)
1826
{
1927
$this->labelsApi = $labelsApi;
@@ -95,7 +103,7 @@ private function extractLabels($prTitle)
95103
*/
96104
private function getValidLabels()
97105
{
98-
return array(
106+
$realLabels = array(
99107
'Asset', 'BC Break', 'BrowserKit', 'Bug', 'Cache', 'ClassLoader',
100108
'Config', 'Console', 'Critical', 'CssSelector', 'Debug', 'DebugBundle',
101109
'DependencyInjection', 'Deprecation', 'Doctrine', 'DoctrineBridge',
@@ -109,6 +117,12 @@ private function getValidLabels()
109117
'Unconfirmed', 'Validator', 'VarDumper', 'WebProfilerBundle', 'Workflow',
110118
'Yaml',
111119
);
120+
121+
return array_merge(
122+
$realLabels,
123+
// also consider the "aliases" as valid, so they are used
124+
array_keys(self::$labelAliases)
125+
);
112126
}
113127

114128
/**
@@ -117,15 +131,9 @@ private function getValidLabels()
117131
*/
118132
private function fixLabelName($label)
119133
{
120-
$labelAliases = array(
121-
'di' => 'DependencyInjection',
122-
'bridge\twig' => 'TwigBridge',
123-
'router' => 'Routing',
124-
'translation' => 'Translator',
125-
'twig bridge' => 'TwigBridge',
126-
);
134+
$labelAliases = self::$labelAliases;
127135

128-
if (in_array(strtolower($label), $labelAliases)) {
136+
if (isset($labelAliases[strtolower($label)])) {
129137
return $labelAliases[strtolower($label)];
130138
}
131139

src/AppBundle/Tests/Subscriber/AutoLabelPRFromContentSubscriberTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ public function getPRTests()
150150
['Asset', 'BC Break', 'Bug'],
151151
];
152152

153+
// testing the fixLabelName: di -> DependencyInjection
154+
$tests[] = [
155+
'[di][Fake] Extracting from title [Bug]',
156+
<<<EOF
157+
EOF
158+
,
159+
['DependencyInjection', 'Bug'],
160+
];
161+
153162
return $tests;
154163
}
155164
}

0 commit comments

Comments
 (0)