Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F456715
DifferentialRevisionIDField.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
DifferentialRevisionIDField.php
View Options
<?php
final
class
DifferentialRevisionIDField
extends
DifferentialCustomField
{
private
$revisionID
;
public
function
getFieldKey
()
{
return
'differential:revision-id'
;
}
public
function
getFieldKeyForConduit
()
{
return
'revisionID'
;
}
public
function
getFieldName
()
{
return
pht
(
'Differential Revision'
);
}
public
function
getFieldDescription
()
{
return
pht
(
'Ties commits to revisions and provides a permanent link between them.'
);
}
public
function
canDisableField
()
{
return
false
;
}
public
function
shouldAppearInCommitMessage
()
{
return
true
;
}
public
function
parseValueFromCommitMessage
(
$value
)
{
// If the value is just "D123" or similar, parse the ID from it directly.
$value
=
trim
(
$value
);
$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
);
}
public
function
renderCommitMessageValue
(
array
$handles
)
{
$id
=
coalesce
(
$this
->
revisionID
,
$this
->
getObject
()->
getID
());
if
(!
$id
)
{
return
null
;
}
return
PhabricatorEnv
::
getProductionURI
(
'/D'
.
$id
);
}
public
function
readValueFromCommitMessage
(
$value
)
{
$this
->
revisionID
=
$value
;
}
private
static
function
parseRevisionIDFromURI
(
$uri_string
)
{
$uri
=
new
PhutilURI
(
$uri_string
);
$path
=
$uri
->
getPath
();
$matches
=
null
;
if
(
preg_match
(
'#^/D(
\d
+)$#'
,
$path
,
$matches
))
{
$id
=
(
int
)
$matches
[
1
];
$prod_uri
=
new
PhutilURI
(
PhabricatorEnv
::
getProductionURI
(
'/D'
.
$id
));
// Make sure the URI is the same as our URI. Basically, we want to ignore
// commits from other Phabricator installs.
if
(
$uri
->
getDomain
()
==
$prod_uri
->
getDomain
())
{
return
$id
;
}
$allowed_uris
=
PhabricatorEnv
::
getAllowedURIs
(
'/D'
.
$id
);
foreach
(
$allowed_uris
as
$allowed_uri
)
{
if
(
$uri_string
==
$allowed_uri
)
{
return
$id
;
}
}
}
return
null
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 5, 8:42 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70930
Default Alt Text
DifferentialRevisionIDField.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment