Differential D8263 Diff 19662 src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
<?php | <?php | ||||
abstract class DifferentialFreeformFieldSpecification | abstract class DifferentialFreeformFieldSpecification | ||||
extends DifferentialFieldSpecification { | extends DifferentialFieldSpecification { | ||||
private function findMentionedTasks($message) { | private function findMentionedTasks($message) { | ||||
$maniphest = 'PhabricatorApplicationManiphest'; | $maniphest = 'PhabricatorApplicationManiphest'; | ||||
if (!PhabricatorApplication::isClassInstalled($maniphest)) { | if (!PhabricatorApplication::isClassInstalled($maniphest)) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$prefixes = array( | $prefixes = array( | ||||
'resolve' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'resolve' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'resolves' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'resolves' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'resolved' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'resolved' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'fix' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'fix' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'fixes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'fixes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'fixed' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'fixed' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'wontfix' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | 'wontfix' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | ||||
'wontfixes' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | 'wontfixes' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | ||||
'wontfixed' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | 'wontfixed' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | ||||
'spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | 'spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | ||||
'spites' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | 'spites' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | ||||
'spited' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | 'spited' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | ||||
'invalidate' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | 'invalidate' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | ||||
'invaldiates' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | 'invaldiates' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | ||||
'invalidated' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | 'invalidated' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | ||||
'close' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'close' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'closes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'closes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'closed' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'closed' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'ref' => null, | 'ref' => null, | ||||
'refs' => null, | 'refs' => null, | ||||
'references' => null, | 'references' => null, | ||||
'cf.' => null, | 'cf.' => null, | ||||
); | ); | ||||
$suffixes = array( | $suffixes = array( | ||||
'as resolved' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'as resolved' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'as fixed' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | 'as fixed' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
'as wontfix' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | 'as wontfix' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | ||||
'as spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | 'as spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | ||||
'out of spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | 'out of spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | ||||
'as invalid' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | 'as invalid' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | ||||
'' => null, | '' => null, | ||||
); | ); | ||||
epriestley: This duplicated stuff is going away soon. | |||||
$prefix_regex = array(); | $matches = id(new ManiphestCustomFieldStatusParser()) | ||||
foreach ($prefixes as $prefix => $resolution) { | ->parseCorpus($message); | ||||
$prefix_regex[] = preg_quote($prefix, '/'); | |||||
} | $task_statuses = array(); | ||||
$prefix_regex = implode('|', $prefix_regex); | foreach ($matches as $match) { | ||||
$prefix = phutil_utf8_strtolower($match['prefix']); | |||||
$suffix_regex = array(); | $suffix = phutil_utf8_strtolower($match['suffix']); | ||||
foreach ($suffixes as $suffix => $resolution) { | |||||
$suffix_regex[] = preg_quote($suffix, '/'); | |||||
} | |||||
$suffix_regex = implode('|', $suffix_regex); | |||||
$matches = null; | |||||
preg_match_all( | |||||
"/({$prefix_regex})\s+T(\d+)\s*({$suffix_regex})/i", | |||||
$message, | |||||
$matches, | |||||
PREG_SET_ORDER); | |||||
$tasks_statuses = array(); | |||||
foreach ($matches as $set) { | |||||
$prefix = strtolower($set[1]); | |||||
$task_id = (int)$set[2]; | |||||
$suffix = strtolower($set[3]); | |||||
$status = idx($suffixes, $suffix); | $status = idx($suffixes, $suffix); | ||||
if (!$status) { | if (!$status) { | ||||
$status = idx($prefixes, $prefix); | $status = idx($prefixes, $prefix); | ||||
} | } | ||||
$tasks_statuses[$task_id] = $status; | foreach ($match['monograms'] as $task_monogram) { | ||||
$task_id = (int)trim($task_monogram, 'tT'); | |||||
$task_statuses[$task_id] = $status; | |||||
} | |||||
} | } | ||||
return $tasks_statuses; | return $task_statuses; | ||||
} | } | ||||
private function findDependentRevisions($message) { | private function findDependentRevisions($message) { | ||||
$dependents = array(); | $matches = id(new DifferentialCustomFieldDependsOnParser()) | ||||
->parseCorpus($message); | |||||
$matches = null; | |||||
preg_match_all( | |||||
'/\b(?i:depends\s+on):?\s+D(\d+(,\s+D\d++)*)\b/', | |||||
$message, | |||||
$matches); | |||||
foreach ($matches[1] as $revisions) { | $dependents = array(); | ||||
foreach (preg_split('/,\s+D/', $revisions) as $id) { | foreach ($matches as $match) { | ||||
foreach ($match['monograms'] as $monogram) { | |||||
$id = (int)trim($monogram, 'dD'); | |||||
$dependents[$id] = $id; | $dependents[$id] = $id; | ||||
} | } | ||||
} | } | ||||
return $dependents; | return $dependents; | ||||
} | } | ||||
public static function findRevertedCommits($message) { | public static function findRevertedCommits($message) { | ||||
$reverts = array(); | $matches = id(new DifferentialCustomFieldRevertsParser()) | ||||
$matches = null; | ->parseCorpus($message); | ||||
// NOTE: Git language is "This reverts commit X." | |||||
// NOTE: Mercurial language is "Backed out changeset Y". | |||||
$prefixes = array( | |||||
'revert' => true, | |||||
'reverts' => true, | |||||
'back\s*out' => true, | |||||
'backs\s*out' => true, | |||||
'backed\s*out' => true, | |||||
'undo' => true, | |||||
'undoes' => true, | |||||
); | |||||
$optional = array( | |||||
'commit' => true, | |||||
'changeset' => true, | |||||
'rev' => true, | |||||
'revision' => true, | |||||
'change' => true, | |||||
'diff' => true, | |||||
); | |||||
$pre_re = implode('|', array_keys($prefixes)); | |||||
$opt_re = implode('|', array_keys($optional)); | |||||
$matches = null; | |||||
preg_match_all( | |||||
'/\b(?i:'.$pre_re.')(?:\s+(?i:'.$opt_re.'))?([rA-Z0-9a-f,\s]+)\b/', | |||||
$message, | |||||
$matches); | |||||
$result = array(); | $result = array(); | ||||
foreach ($matches[1] as $commits) { | foreach ($matches as $match) { | ||||
$commits = preg_split('/[,\s]+/', $commits); | foreach ($match['monograms'] as $monogram) { | ||||
$commits = array_filter($commits); | $result[$monogram] = $monogram; | ||||
foreach ($commits as $commit) { | |||||
$result[$commit] = $commit; | |||||
} | } | ||||
} | } | ||||
return $result; | return $result; | ||||
} | } | ||||
public function didWriteRevision(DifferentialRevisionEditor $editor) { | public function didWriteRevision(DifferentialRevisionEditor $editor) { | ||||
$message = $this->renderValueForCommitMessage(false); | $message = $this->renderValueForCommitMessage(false); | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |
This duplicated stuff is going away soon.