private function buildRepositoryMap(HarbormasterBuildTarget $build_target) { $viewer = PhabricatorUser::getOmnipotentUser(); $variables = $build_target->getVariables(); $repository_phid = idx($variables, 'repository.phid'); if (!$repository_phid) { throw new Exception(pht('Unable to determine how to clone the repository for this ' . 'buildable: it is not associated with a tracked repository.')); } $also_phids = $build_target->getFieldValue('repositoryPHIDs'); if (!is_array($also_phids)) { $also_phids = array(); } $all_phids = $also_phids; $all_phids[] = $repository_phid; $repositories = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs($all_phids)->execute(); $repositories = mpull($repositories, null, 'getPHID'); foreach ($all_phids as $phid) { if (empty($repositories[$phid])) { throw new PhabricatorWorkerPermanentFailureException(pht('Unable to load repository with PHID "%s".', $phid)); } } $map = array(); foreach ($also_phids as $also_phid) { $also_repo = $repositories[$also_phid]; $map[$also_repo->getCloneName()] = array('phid' => $also_repo->getPHID(), 'branch' => 'master'); } $repository = $repositories[$repository_phid]; $commit = idx($variables, 'buildable.commit'); $ref_uri = idx($variables, 'repository.staging.uri'); $ref_ref = idx($variables, 'repository.staging.ref'); if ($commit) { $spec = array('commit' => $commit); } else { if ($ref_uri && $ref_ref) { $spec = array('ref' => array('uri' => $ref_uri, 'ref' => $ref_ref)); } else { throw new Exception(pht('Unable to determine how to fetch changes: this buildable does not ' . 'identify a commit or a staging ref. You may need to configure a ' . 'repository staging area.')); } } $directory = $repository->getCloneName(); $map[$directory] = array('phid' => $repository->getPHID(), 'default' => true) + $spec; return $map; }