コード例 #1
0
 protected function executeQuery()
 {
     $ref = $this->ref;
     $message = $ref->getMessage();
     $hashes = $ref->getHashes();
     $params = array('corpus' => $message, 'partial' => true);
     $result = id(new ConduitCall('differential.parsecommitmessage', $params))->setUser(PhabricatorUser::getOmnipotentUser())->execute();
     $fields = $result['fields'];
     $revision_id = idx($fields, 'revisionID');
     if ($revision_id) {
         $this->setRevisionMatchData('usedURI', true);
     } else {
         $this->setRevisionMatchData('usedURI', false);
     }
     $revision_id_info = $result['revisionIDFieldInfo'];
     $this->setRevisionMatchData('foundURI', $revision_id_info['value']);
     $this->setRevisionMatchData('validDomain', $revision_id_info['validDomain']);
     // If there is no "Differential Revision:" field in the message, try to
     // identify the revision by doing a hash lookup.
     if (!$revision_id && $hashes) {
         $hash_list = array();
         foreach ($hashes as $hash) {
             $hash_list[] = array($hash->getHashType(), $hash->getHashValue());
         }
         $revisions = id(new DifferentialRevisionQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->needHashes(true)->withCommitHashes($hash_list)->execute();
         if ($revisions) {
             $revision = $this->pickBestRevision($revisions);
             $fields['revisionID'] = $revision->getID();
             $revision_hashes = $revision->getHashes();
             $revision_hashes = DiffusionCommitHash::convertArrayToObjects($revision_hashes);
             $revision_hashes = mpull($revision_hashes, null, 'getHashType');
             // sort the hashes in the order the mighty
             // @{class:ArcanstDifferentialRevisionHash} does; probably unnecessary
             // but should future proof things nicely.
             $revision_hashes = array_select_keys($revision_hashes, ArcanistDifferentialRevisionHash::getTypes());
             foreach ($hashes as $hash) {
                 $revision_hash = idx($revision_hashes, $hash->getHashType());
                 if (!$revision_hash) {
                     continue;
                 }
                 if ($revision_hash->getHashValue() == $hash->getHashValue()) {
                     $this->setRevisionMatchData('matchHashType', $hash->getHashType());
                     $this->setRevisionMatchData('matchHashValue', $hash->getHashValue());
                     break;
                 }
             }
         }
     }
     return $fields;
 }
コード例 #2
0
 protected function execute(ConduitAPIRequest $request)
 {
     $authors = $request->getValue('authors');
     $ccs = $request->getValue('ccs');
     $reviewers = $request->getValue('reviewers');
     $status = $request->getValue('status');
     $order = $request->getValue('order');
     $path_pairs = $request->getValue('paths');
     $commit_hashes = $request->getValue('commitHashes');
     $limit = $request->getValue('limit');
     $offset = $request->getValue('offset');
     $ids = $request->getValue('ids');
     $phids = $request->getValue('phids');
     $subscribers = $request->getValue('subscribers');
     $responsible_users = $request->getValue('responsibleUsers');
     $branches = $request->getValue('branches');
     $query = id(new DifferentialRevisionQuery())->setViewer($request->getUser());
     if ($authors) {
         $query->withAuthors($authors);
     }
     if ($ccs) {
         $query->withCCs($ccs);
     }
     if ($reviewers) {
         $query->withReviewers($reviewers);
     }
     if ($path_pairs) {
         $paths = array();
         foreach ($path_pairs as $pair) {
             list($callsign, $path) = $pair;
             $paths[] = $path;
         }
         $path_map = id(new DiffusionPathIDQuery($paths))->loadPathIDs();
         if (count($path_map) != count($paths)) {
             $unknown_paths = array();
             foreach ($paths as $p) {
                 if (!idx($path_map, $p)) {
                     $unknown_paths[] = $p;
                 }
             }
             throw id(new ConduitException('ERR-INVALID-PARAMETER'))->setErrorDescription(pht('Unknown paths: %s', implode(', ', $unknown_paths)));
         }
         $repos = array();
         foreach ($path_pairs as $pair) {
             list($callsign, $path) = $pair;
             if (!idx($repos, $callsign)) {
                 $repos[$callsign] = id(new PhabricatorRepositoryQuery())->setViewer($request->getUser())->withCallsigns(array($callsign))->executeOne();
                 if (!$repos[$callsign]) {
                     throw id(new ConduitException('ERR-INVALID-PARAMETER'))->setErrorDescription(pht('Unknown repo callsign: %s', $callsign));
                 }
             }
             $repo = $repos[$callsign];
             $query->withPath($repo->getID(), idx($path_map, $path));
         }
     }
     if ($commit_hashes) {
         $hash_types = ArcanistDifferentialRevisionHash::getTypes();
         foreach ($commit_hashes as $info) {
             list($type, $hash) = $info;
             if (empty($type) || !in_array($type, $hash_types) || empty($hash)) {
                 throw new ConduitException('ERR-INVALID-PARAMETER');
             }
         }
         $query->withCommitHashes($commit_hashes);
     }
     if ($status) {
         $query->withStatus($status);
     }
     if ($order) {
         $query->setOrder($order);
     }
     if ($limit) {
         $query->setLimit($limit);
     }
     if ($offset) {
         $query->setOffset($offset);
     }
     if ($ids) {
         $query->withIDs($ids);
     }
     if ($phids) {
         $query->withPHIDs($phids);
     }
     if ($responsible_users) {
         $query->withResponsibleUsers($responsible_users);
     }
     if ($subscribers) {
         $query->withCCs($subscribers);
     }
     if ($branches) {
         $query->withBranches($branches);
     }
     $query->needRelationships(true);
     $query->needCommitPHIDs(true);
     $query->needDiffIDs(true);
     $query->needActiveDiffs(true);
     $query->needHashes(true);
     $revisions = $query->execute();
     $field_data = $this->loadCustomFieldsForRevisions($request->getUser(), $revisions);
     $results = array();
     foreach ($revisions as $revision) {
         $diff = $revision->getActiveDiff();
         if (!$diff) {
             continue;
         }
         $id = $revision->getID();
         $phid = $revision->getPHID();
         $result = array('id' => $id, 'phid' => $phid, 'title' => $revision->getTitle(), 'uri' => PhabricatorEnv::getProductionURI('/D' . $id), 'dateCreated' => $revision->getDateCreated(), 'dateModified' => $revision->getDateModified(), 'authorPHID' => $revision->getAuthorPHID(), 'status' => $revision->getStatus(), 'statusName' => ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($revision->getStatus()), 'properties' => $revision->getProperties(), 'branch' => $diff->getBranch(), 'summary' => $revision->getSummary(), 'testPlan' => $revision->getTestPlan(), 'lineCount' => $revision->getLineCount(), 'activeDiffPHID' => $diff->getPHID(), 'diffs' => $revision->getDiffIDs(), 'commits' => $revision->getCommitPHIDs(), 'reviewers' => array_values($revision->getReviewers()), 'ccs' => array_values($revision->getCCPHIDs()), 'hashes' => $revision->getHashes(), 'auxiliary' => idx($field_data, $phid, array()), 'repositoryPHID' => $diff->getRepositoryPHID());
         // TODO: This is a hacky way to put permissions on this field until we
         // have first-class support, see T838.
         if ($revision->getAuthorPHID() == $request->getUser()->getPHID()) {
             $result['sourcePath'] = $diff->getSourcePath();
         }
         $results[] = $result;
     }
     return $results;
 }
コード例 #3
0
 protected function execute(ConduitAPIRequest $request)
 {
     $authors = $request->getValue('authors');
     $ccs = $request->getValue('ccs');
     $reviewers = $request->getValue('reviewers');
     $status = $request->getValue('status');
     $order = $request->getValue('order');
     $commit_hashes = $request->getValue('commitHashes');
     $limit = $request->getValue('limit');
     $offset = $request->getValue('offset');
     $ids = $request->getValue('ids');
     $phids = $request->getValue('phids');
     $subscribers = $request->getValue('subscribers');
     $responsible_users = $request->getValue('responsibleUsers');
     $branches = $request->getValue('branches');
     $arc_projects = $request->getValue('arcanistProjects');
     $query = new DifferentialRevisionQuery();
     if ($authors) {
         $query->withAuthors($authors);
     }
     if ($ccs) {
         $query->withCCs($ccs);
     }
     if ($reviewers) {
         $query->withReviewers($reviewers);
     }
     /* TODO: Implement.
         $paths     = $request->getValue('paths');
         if ($paths) {
           foreach ($paths as $path) {
     
             // (Lookup the repository IDs.)
     
             $query->withPath($repository_id, $path);
           }
         }
      */
     if ($commit_hashes) {
         $hash_types = ArcanistDifferentialRevisionHash::getTypes();
         foreach ($commit_hashes as $info) {
             list($type, $hash) = $info;
             if (empty($type) || !in_array($type, $hash_types) || empty($hash)) {
                 throw new ConduitException('ERR-INVALID-PARAMETER');
             }
         }
         $query->withCommitHashes($commit_hashes);
     }
     if ($status) {
         $query->withStatus($status);
     }
     if ($order) {
         $query->setOrder($order);
     }
     if ($limit) {
         $query->setLimit($limit);
     }
     if ($offset) {
         $query->setOffset($offset);
     }
     if ($ids) {
         $query->withIDs($ids);
     }
     if ($phids) {
         $query->withPHIDs($phids);
     }
     if ($responsible_users) {
         $query->withResponsibleUsers($responsible_users);
     }
     if ($subscribers) {
         $query->withSubscribers($subscribers);
     }
     if ($branches) {
         $query->withBranches($branches);
     }
     if ($arc_projects) {
         // This is sort of special-cased, but don't make arc do an extra round
         // trip.
         $projects = id(new PhabricatorRepositoryArcanistProject())->loadAllWhere('name in (%Ls)', $arc_projects);
         if (!$projects) {
             return array();
         }
         $query->withArcanistProjectPHIDs(mpull($projects, 'getPHID'));
     }
     $query->needRelationships(true);
     $query->needCommitPHIDs(true);
     $query->needDiffIDs(true);
     $query->needActiveDiffs(true);
     $revisions = $query->execute();
     $results = array();
     foreach ($revisions as $revision) {
         $diff = $revision->getActiveDiff();
         if (!$diff) {
             continue;
         }
         $id = $revision->getID();
         $result = array('id' => $id, 'phid' => $revision->getPHID(), 'title' => $revision->getTitle(), 'uri' => PhabricatorEnv::getProductionURI('/D' . $id), 'dateCreated' => $revision->getDateCreated(), 'dateModified' => $revision->getDateModified(), 'authorPHID' => $revision->getAuthorPHID(), 'status' => $revision->getStatus(), 'statusName' => ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($revision->getStatus()), 'branch' => $diff->getBranch(), 'summary' => $revision->getSummary(), 'testPlan' => $revision->getTestPlan(), 'lineCount' => $revision->getLineCount(), 'diffs' => $revision->getDiffIDs(), 'commits' => $revision->getCommitPHIDs(), 'reviewers' => array_values($revision->getReviewers()), 'ccs' => array_values($revision->getCCPHIDs()));
         // TODO: This is a hacky way to put permissions on this field until we
         // have first-class support, see T838.
         if ($revision->getAuthorPHID() == $request->getUser()->getPHID()) {
             $result['sourcePath'] = $diff->getSourcePath();
         }
         $results[] = $result;
     }
     return $results;
 }