3 final class HarbormasterQueryAutotargetsConduitAPIMethod
4 extends HarbormasterConduitAPIMethod
{
6 public function getAPIMethodName() {
7 return 'harbormaster.queryautotargets';
10 public function getMethodDescription() {
11 return pht('Load or create build autotargets.');
14 protected function defineParamTypes() {
16 'objectPHID' => 'phid',
17 'targetKeys' => 'list<string>',
21 protected function defineReturnType() {
22 return 'map<string, phid>';
25 protected function execute(ConduitAPIRequest
$request) {
26 $viewer = $request->getUser();
28 $phid = $request->getValue('objectPHID');
30 // NOTE: We use withNames() to let monograms like "D123" work, which makes
31 // this a little easier to test. Real PHIDs will still work as expected.
33 $object = id(new PhabricatorObjectQuery())
35 ->withNames(array($phid))
40 'No such object "%s" exists.',
44 if (!($object instanceof HarbormasterBuildableInterface
)) {
47 'Object "%s" does not implement interface "%s". Autotargets may '.
48 'only be queried for buildable objects.',
50 'HarbormasterBuildableInterface'));
53 $autotargets = $request->getValue('targetKeys', array());
56 $targets = id(new HarbormasterTargetEngine())
59 ->setAutoTargetKeys($autotargets)
65 // Reorder the results according to the request order so we can make test
66 // assertions that subsequent calls return the same results.
68 $map = mpull($targets, 'getPHID');
69 $map = array_select_keys($map, $autotargets);