Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/field/DifferentialRevisionIDCommitMessageField.php
12256 views
1
<?php
2
3
final class DifferentialRevisionIDCommitMessageField
4
extends DifferentialCommitMessageField {
5
6
const FIELDKEY = 'revisionID';
7
8
public function getFieldName() {
9
return pht('Differential Revision');
10
}
11
12
public function getFieldOrder() {
13
return 200000;
14
}
15
16
public function isTemplateField() {
17
return false;
18
}
19
20
public function parseFieldValue($value) {
21
// If the complete commit message we are parsing has unrecognized custom
22
// fields at the end, they can end up parsed into the field value for this
23
// field. For example, if the message looks like this:
24
25
// Differential Revision: xyz
26
// Some-Other-Field: abc
27
28
// ...we will receive "xyz\nSome-Other-Field: abc" as the field value for
29
// this field. Ideally, the install would define these fields so they can
30
// parse formally, but we can reasonably assume that only the first line
31
// of any value we encounter actually contains a revision identifier, so
32
// start by throwing away any other lines.
33
34
$value = trim($value);
35
$value = phutil_split_lines($value, false);
36
$value = head($value);
37
$value = trim($value);
38
39
// If the value is just "D123" or similar, parse the ID from it directly.
40
$matches = null;
41
if (preg_match('/^[dD]([1-9]\d*)\z/', $value, $matches)) {
42
return (int)$matches[1];
43
}
44
45
// Otherwise, try to extract a URI value.
46
return self::parseRevisionIDFromURI($value);
47
}
48
49
private static function parseRevisionIDFromURI($uri_string) {
50
$uri = new PhutilURI($uri_string);
51
$path = $uri->getPath();
52
53
if (PhabricatorEnv::isSelfURI($uri_string)) {
54
$matches = null;
55
if (preg_match('#^/D(\d+)$#', $path, $matches)) {
56
return (int)$matches[1];
57
}
58
}
59
60
return null;
61
}
62
63
public function readFieldValueFromObject(DifferentialRevision $revision) {
64
return $revision->getID();
65
}
66
67
public function readFieldValueFromConduit($value) {
68
if (is_int($value)) {
69
$value = (string)$value;
70
}
71
return $this->readStringFieldValueFromConduit($value);
72
}
73
74
public function renderFieldValue($value) {
75
if ($value === null || !strlen($value)) {
76
return null;
77
}
78
79
return PhabricatorEnv::getProductionURI('/D'.$value);
80
}
81
82
public function getFieldTransactions($value) {
83
return array();
84
}
85
86
}
87
88