Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F858901
CustomDifferentialRunPackageBuildsHeraldAction.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
epriestley
Oct 2 2015, 12:31 PM
2015-10-02 12:31:37 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
CustomDifferentialRunPackageBuildsHeraldAction.php
View Options
<?php
final
class
CustomDifferentialRunPackageBuildsHeraldAction
extends
HeraldAction
{
const
ACTIONCONST
=
'custom.differential.run-package-builds'
;
const
DO_BUILD
=
'do.custom-package-build'
;
public
function
getHeraldActionName
()
{
return
pht
(
'Run builds for affected packages'
);
}
public
function
getActionGroupKey
()
{
return
HeraldApplicationActionGroup
::
ACTIONGROUPKEY
;
}
public
function
supportsObject
(
$object
)
{
return
(
$object
instanceof
DifferentialRevision
);
}
public
function
supportsRuleType
(
$rule_type
)
{
return
(
$rule_type
==
HeraldRuleTypeConfig
::
RULE_TYPE_GLOBAL
);
}
public
function
applyEffect
(
$object
,
HeraldEffect
$effect
)
{
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
// Replace this with the full field key of the custom field you want to
// examine. Generally, "std:owners:" plus whatever you named the field.
$field_key
=
"std:owners:mycompany:lore"
;
// Replace this with the PHID of the build plan you want to execute.
$buildplan_phid
=
"PHID-HMCP-vadfbuqvdbx5gy65pfba"
;
$adapter
=
$this
->
getAdapter
();
$packages
=
$adapter
->
loadAffectedPackages
();
$package_phids
=
mpull
(
$packages
,
'getPHID'
);
$this
->
logEffect
(
self
::
DO_BUILD
,
$package_phids
);
$all
=
array
();
foreach
(
$packages
as
$package
)
{
$field_list
=
PhabricatorCustomField
::
getObjectFields
(
$package
,
PhabricatorCustomField
::
ROLE_VIEW
);
$field_list
->
setViewer
(
$viewer
)
->
readFieldsFromStorage
(
$package
);
foreach
(
$field_list
->
getFields
()
as
$field
)
{
$key
=
$field
->
getFieldKey
();
if
(
$key
==
$field_key
)
{
$all
[]
=
$field
->
getValueForStorage
();
}
}
}
$all
=
implode
(
"
\n
"
,
$all
);
$all
=
phutil_split_lines
(
$all
,
false
);
$all
=
array_filter
(
$all
);
$all
=
array_unique
(
$all
);
if
(!
$all
)
{
return
;
}
foreach
(
$all
as
$parameter
)
{
$request
=
id
(
new
HarbormasterBuildRequest
())
->
setBuildPlanPHID
(
$buildplan_phid
)
->
setBuildParameters
(
array
(
'build-name-from-owners'
=>
$parameter
,
));
$adapter
->
queueHarbormasterBuildRequest
(
$request
);
}
}
public
function
getHeraldActionStandardType
()
{
return
self
::
STANDARD_NONE
;
}
public
function
renderActionDescription
(
$value
)
{
return
pht
(
'Run builds for affected pakages.'
);
}
protected
function
getActionEffectMap
()
{
return
array
(
self
::
DO_BUILD
=>
array
(
'icon'
=>
'fa-play'
,
'color'
=>
'green'
,
'name'
=>
pht
(
'Ran Builds'
),
),
);
}
protected
function
renderActionEffectDescription
(
$type
,
$data
)
{
switch
(
$type
)
{
case
self
::
DO_BUILD
:
if
(!
$data
)
{
return
pht
(
'No affected packages.'
);
}
else
{
return
pht
(
'Ran builds for affected packages: %s.'
,
$this
->
renderHandleList
(
$data
));
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/ty/nd/webyxhmzu2w3gimz
Default Alt Text
CustomDifferentialRunPackageBuildsHeraldAction.php (2 KB)
Attached To
Mode
P1860 CustomDifferentialRunPackageBuildsHeraldAction.php
Attached
Detach File
Event Timeline
Log In to Comment