Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99652650
DifferentialRevisionIDFieldSpecification.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jan 26, 00:10
Size
2 KB
Mime Type
text/x-php
Expires
Tue, Jan 28, 00:10 (2 d)
Engine
blob
Format
Raw Data
Handle
23839117
Attached To
rPH Phabricator
DifferentialRevisionIDFieldSpecification.php
View Options
<?php
final
class
DifferentialRevisionIDFieldSpecification
extends
DifferentialFieldSpecification
{
private
$id
;
protected
function
didSetRevision
()
{
$this
->
id
=
$this
->
getRevision
()->
getID
();
}
public
function
shouldAppearOnCommitMessage
()
{
return
true
;
}
public
function
shouldAppearOnCommitMessageTemplate
()
{
return
false
;
}
public
function
getCommitMessageKey
()
{
return
'revisionID'
;
}
public
function
setValueFromParsedCommitMessage
(
$value
)
{
$this
->
id
=
$value
;
return
$this
;
}
public
function
renderLabelForCommitMessage
()
{
return
'Differential Revision'
;
}
public
function
renderValueForCommitMessage
(
$is_edit
)
{
if
(!
$this
->
id
)
{
return
null
;
}
return
PhabricatorEnv
::
getProductionURI
(
'/D'
.
$this
->
id
);
}
public
function
parseValueFromCommitMessage
(
$value
)
{
$rev
=
trim
(
head
(
explode
(
"
\n
"
,
$value
)));
if
(!
strlen
(
$rev
))
{
return
null
;
}
if
(
is_numeric
(
$rev
))
{
// TODO: Eventually, remove support for bare revision numbers.
return
(
int
)
$rev
;
}
$rev
=
self
::
parseRevisionIDFromURI
(
$rev
);
if
(
$rev
!==
null
)
{
return
$rev
;
}
$example_uri
=
PhabricatorEnv
::
getProductionURI
(
'/D123'
);
throw
new
DifferentialFieldParseException
(
"Commit references invalid 'Differential Revision'. Expected a "
.
"Phabricator URI like '{$example_uri}', got '{$value}'."
);
}
public
static
function
parseRevisionIDFromURI
(
$uri
)
{
$path
=
id
(
new
PhutilURI
(
$uri
))->
getPath
();
$matches
=
null
;
if
(
preg_match
(
'#^/D(
\d
+)$#'
,
$path
,
$matches
))
{
$id
=
(
int
)
$matches
[
1
];
// Make sure the URI is the same as our URI. Basically, we want to ignore
// commits from other Phabricator installs.
if
(
$uri
==
PhabricatorEnv
::
getProductionURI
(
'/D'
.
$id
))
{
return
$id
;
}
}
return
null
;
}
public
function
shouldAppearOnRevisionList
()
{
return
true
;
}
public
function
renderHeaderForRevisionList
()
{
return
'ID'
;
}
public
function
renderValueForRevisionList
(
DifferentialRevision
$revision
)
{
return
'D'
.
$revision
->
getID
();
}
public
function
renderValueForMail
(
$phase
)
{
$body
=
array
();
$body
[]
=
'REVISION DETAIL'
;
$body
[]
=
' '
.
PhabricatorEnv
::
getProductionURI
(
'/D'
.
$this
->
id
);
if
(
$phase
==
DifferentialMailPhase
::
UPDATE
)
{
$diffs
=
id
(
new
DifferentialDiff
())->
loadAllWhere
(
'revisionID = %d ORDER BY id DESC LIMIT 2'
,
$this
->
id
);
if
(
count
(
$diffs
)
==
2
)
{
list
(
$new
,
$old
)
=
array_values
(
mpull
(
$diffs
,
'getID'
));
$body
[]
=
null
;
$body
[]
=
'CHANGE SINCE LAST DIFF'
;
$body
[]
=
' '
.
PhabricatorEnv
::
getProductionURI
(
"/D{$this->id}?vs={$old}&id={$new}#toc"
);
}
}
return
implode
(
"
\n
"
,
$body
);
}
}
Event Timeline
Log In to Comment