2016-12-14 17:14:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialRevisionIDCommitMessageField
|
|
|
|
extends DifferentialCommitMessageField {
|
|
|
|
|
|
|
|
const FIELDKEY = 'revisionID';
|
|
|
|
|
|
|
|
public function getFieldName() {
|
|
|
|
return pht('Differential Revision');
|
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
public function getFieldOrder() {
|
|
|
|
return 200000;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isTemplateField() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-14 17:14:52 +01:00
|
|
|
public function parseFieldValue($value) {
|
2017-01-01 16:34:15 +01:00
|
|
|
// If the complete commit message we are parsing has unrecognized custom
|
|
|
|
// fields at the end, they can end up parsed into the field value for this
|
|
|
|
// field. For example, if the message looks like this:
|
|
|
|
|
|
|
|
// Differential Revision: xyz
|
|
|
|
// Some-Other-Field: abc
|
|
|
|
|
|
|
|
// ...we will receive "xyz\nSome-Other-Field: abc" as the field value for
|
|
|
|
// this field. Ideally, the install would define these fields so they can
|
|
|
|
// parse formally, but we can reasonably assume that only the first line
|
|
|
|
// of any value we encounter actually contains a revision identifier, so
|
|
|
|
// start by throwing away any other lines.
|
|
|
|
|
2016-12-14 17:14:52 +01:00
|
|
|
$value = trim($value);
|
2017-01-01 16:34:15 +01:00
|
|
|
$value = phutil_split_lines($value, false);
|
|
|
|
$value = head($value);
|
|
|
|
$value = trim($value);
|
|
|
|
|
|
|
|
// If the value is just "D123" or similar, parse the ID from it directly.
|
2016-12-14 17:14:52 +01:00
|
|
|
$matches = null;
|
|
|
|
if (preg_match('/^[dD]([1-9]\d*)\z/', $value, $matches)) {
|
|
|
|
return (int)$matches[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, try to extract a URI value.
|
|
|
|
return self::parseRevisionIDFromURI($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function parseRevisionIDFromURI($uri_string) {
|
|
|
|
$uri = new PhutilURI($uri_string);
|
|
|
|
$path = $uri->getPath();
|
|
|
|
|
2017-03-16 02:49:03 +01:00
|
|
|
if (PhabricatorEnv::isSelfURI($uri_string)) {
|
|
|
|
$matches = null;
|
|
|
|
if (preg_match('#^/D(\d+)$#', $path, $matches)) {
|
|
|
|
return (int)$matches[1];
|
2016-12-14 17:14:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
public function readFieldValueFromObject(DifferentialRevision $revision) {
|
|
|
|
return $revision->getID();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function readFieldValueFromConduit($value) {
|
|
|
|
if (is_int($value)) {
|
|
|
|
$value = (string)$value;
|
|
|
|
}
|
|
|
|
return $this->readStringFieldValueFromConduit($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderFieldValue($value) {
|
|
|
|
if (!strlen($value)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PhabricatorEnv::getProductionURI('/D'.$value);
|
|
|
|
}
|
|
|
|
|
2016-12-16 13:45:55 +01:00
|
|
|
public function getFieldTransactions($value) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2016-12-14 17:14:52 +01:00
|
|
|
}
|