Path: blob/master/src/applications/differential/field/DifferentialRevisionIDCommitMessageField.php
12256 views
<?php12final class DifferentialRevisionIDCommitMessageField3extends DifferentialCommitMessageField {45const FIELDKEY = 'revisionID';67public function getFieldName() {8return pht('Differential Revision');9}1011public function getFieldOrder() {12return 200000;13}1415public function isTemplateField() {16return false;17}1819public function parseFieldValue($value) {20// If the complete commit message we are parsing has unrecognized custom21// fields at the end, they can end up parsed into the field value for this22// field. For example, if the message looks like this:2324// Differential Revision: xyz25// Some-Other-Field: abc2627// ...we will receive "xyz\nSome-Other-Field: abc" as the field value for28// this field. Ideally, the install would define these fields so they can29// parse formally, but we can reasonably assume that only the first line30// of any value we encounter actually contains a revision identifier, so31// start by throwing away any other lines.3233$value = trim($value);34$value = phutil_split_lines($value, false);35$value = head($value);36$value = trim($value);3738// If the value is just "D123" or similar, parse the ID from it directly.39$matches = null;40if (preg_match('/^[dD]([1-9]\d*)\z/', $value, $matches)) {41return (int)$matches[1];42}4344// Otherwise, try to extract a URI value.45return self::parseRevisionIDFromURI($value);46}4748private static function parseRevisionIDFromURI($uri_string) {49$uri = new PhutilURI($uri_string);50$path = $uri->getPath();5152if (PhabricatorEnv::isSelfURI($uri_string)) {53$matches = null;54if (preg_match('#^/D(\d+)$#', $path, $matches)) {55return (int)$matches[1];56}57}5859return null;60}6162public function readFieldValueFromObject(DifferentialRevision $revision) {63return $revision->getID();64}6566public function readFieldValueFromConduit($value) {67if (is_int($value)) {68$value = (string)$value;69}70return $this->readStringFieldValueFromConduit($value);71}7273public function renderFieldValue($value) {74if ($value === null || !strlen($value)) {75return null;76}7778return PhabricatorEnv::getProductionURI('/D'.$value);79}8081public function getFieldTransactions($value) {82return array();83}8485}868788