Skip to content

Commit 712f669

Browse files
committed
Making two recomenndations from Bernhard at sha: 668496b
The combination of the two work perfectly
1 parent d86c9f5 commit 712f669

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/AppBundle/GitHub/StatusManager.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,12 @@ public function getStatusChangeFromComment($comment)
4242
return null;
4343
}
4444

45-
// get what comes *after* status:, with spaces trimmed
46-
// now, the status string "needs review" should be at the 0 character
47-
$statusString = trim(substr($comment, $statusPosition));
48-
49-
$newStatus = null;
5045
foreach (self::$triggerWords as $status => $triggerWord) {
5146
// status should be right at the beginning of the string
52-
if (stripos($statusString, $triggerWord) === 0) {
53-
// don't return immediately - we use the last status
54-
// in the rare case there are multiple
55-
$newStatus = $status;
47+
if ($triggerWord === strtolower(substr($comment, $statusPosition, strlen($triggerWord)))) {
48+
return $status;
5649
}
5750
}
58-
59-
return $newStatus;
6051
}
6152

6253
/**
@@ -99,14 +90,16 @@ public static function getLabelToStatusMap()
9990
*/
10091
private function findStatusPosition($comment)
10192
{
102-
$formats = ['status:', '*status*:', '**status**:'];
93+
// Match first character after "status:"
94+
// Case insensitive ("i"), ignores formatting with "*" before or after the ":"
95+
$pattern = '~status(\*+:\s*|:[\s\*]*)(\w)~i';
10396

104-
foreach ($formats as $format) {
105-
$lastStatusPosition = strripos($comment, $format);
97+
if (preg_match_all($pattern, $comment, $matches, PREG_OFFSET_CAPTURE)) {
98+
// Second subpattern = first status character
99+
$lastMatch = end($matches[2]);
106100

107-
if ($lastStatusPosition !== false) {
108-
return $lastStatusPosition + strlen($format);
109-
}
101+
// [matched string, offset]
102+
return $lastMatch[1];
110103
}
111104

112105
return false;

0 commit comments

Comments
 (0)