protected function execute(ConduitAPIRequest $conduit_request)
 {
     $revision_phids = $conduit_request->getValue('revisionPHIDs');
     $requested_commit_phids = $conduit_request->getValue('requestedCommitPHIDs');
     $result = array();
     if (!$revision_phids && !$requested_commit_phids) {
         return $result;
     }
     $query = new ReleephRequestQuery();
     $query->setViewer($conduit_request->getUser());
     if ($revision_phids) {
         $query->withRequestedObjectPHIDs($revision_phids);
     } else {
         if ($requested_commit_phids) {
             $query->withRequestedCommitPHIDs($requested_commit_phids);
         }
     }
     $releeph_requests = $query->execute();
     foreach ($releeph_requests as $releeph_request) {
         $branch = $releeph_request->getBranch();
         $request_commit_phid = $releeph_request->getRequestCommitPHID();
         $object = $releeph_request->getRequestedObject();
         if ($object instanceof DifferentialRevision) {
             $object_phid = $object->getPHID();
         } else {
             $object_phid = null;
         }
         $status = $releeph_request->getStatus();
         $status_name = ReleephRequestStatus::getStatusDescriptionFor($status);
         $url = PhabricatorEnv::getProductionURI('/RQ' . $releeph_request->getID());
         $result[] = array('branchBasename' => $branch->getBasename(), 'branchSymbolic' => $branch->getSymbolicName(), 'requestID' => $releeph_request->getID(), 'revisionPHID' => $object_phid, 'status' => $status, 'status_name' => $status_name, 'url' => $url);
     }
     return $result;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff_id = $request->getValue('diff_id');
     $name = $request->getValue('name');
     $data = json_decode($request->getValue('data'), true);
     self::updateDiffProperty($diff_id, $name, $data);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $phid = $request->getValue('objectPHID');
     // NOTE: We use withNames() to let monograms like "D123" work, which makes
     // this a little easier to test. Real PHIDs will still work as expected.
     $object = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames(array($phid))->executeOne();
     if (!$object) {
         throw new Exception(pht('No such object "%s" exists.', $phid));
     }
     if (!$object instanceof HarbormasterBuildableInterface) {
         throw new Exception(pht('Object "%s" does not implement interface "%s". Autotargets may ' . 'only be queried for buildable objects.', $phid, 'HarbormasterBuildableInterface'));
     }
     $autotargets = $request->getValue('targetKeys', array());
     if ($autotargets) {
         $targets = id(new HarbormasterTargetEngine())->setViewer($viewer)->setObject($object)->setAutoTargetKeys($autotargets)->buildTargets();
     } else {
         $targets = array();
     }
     // Reorder the results according to the request order so we can make test
     // assertions that subsequent calls return the same results.
     $map = mpull($targets, 'getPHID');
     $map = array_select_keys($map, $autotargets);
     return array('targetMap' => $map);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $name = $request->getValue('name');
     $name_prefix = $request->getValue('namePrefix');
     $language = $request->getValue('language');
     $type = $request->getValue('type');
     $query = new DiffusionSymbolQuery();
     if ($name !== null) {
         $query->setName($name);
     }
     if ($name_prefix !== null) {
         $query->setNamePrefix($name_prefix);
     }
     if ($language !== null) {
         $query->setLanguage($language);
     }
     if ($type !== null) {
         $query->setType($type);
     }
     $query->needPaths(true);
     $query->needArcanistProjects(true);
     $query->needRepositories(true);
     $results = $query->execute();
     $response = array();
     foreach ($results as $result) {
         $response[] = array('name' => $result->getSymbolName(), 'type' => $result->getSymbolType(), 'language' => $result->getSymbolLanguage(), 'path' => $result->getPath(), 'line' => $result->getLineNumber(), 'uri' => PhabricatorEnv::getProductionURI($result->getURI()));
     }
     return $response;
 }
 protected function getResult(ConduitAPIRequest $request)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     if (!$repository->isGit()) {
         throw new Exception(pht('This API method can only be called on Git repositories.'));
     }
     // Check if the commit has parents. We're testing to see whether it is the
     // first commit in history (in which case we must use "git log") or some
     // other commit (in which case we can use "git diff"). We'd rather use
     // "git diff" because it has the right behavior for merge commits, but
     // it requires the commit to have a parent that we can diff against. The
     // first commit doesn't, so "commit^" is not a valid ref.
     list($parents) = $repository->execxLocalCommand('log -n1 --format=%s %s', '%P', $request->getValue('commit'));
     $use_log = !strlen(trim($parents));
     if ($use_log) {
         // This is the first commit so we need to use "log". We know it's not a
         // merge commit because it couldn't be merging anything, so this is safe.
         // NOTE: "--pretty=format: " is to disable diff output, we only want the
         // part we get from "--raw".
         list($raw) = $repository->execxLocalCommand('log -n1 -M -C -B --find-copies-harder --raw -t ' . '--pretty=format: --abbrev=40 %s', $request->getValue('commit'));
     } else {
         // Otherwise, we can use "diff", which will give us output for merges.
         // We diff against the first parent, as this is generally the expectation
         // and results in sensible behavior.
         list($raw) = $repository->execxLocalCommand('diff -n1 -M -C -B --find-copies-harder --raw -t ' . '--abbrev=40 %s^1 %s', $request->getValue('commit'), $request->getValue('commit'));
     }
     return $raw;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $id = $request->getValue('id');
     $object = $request->getValue('objectPHID');
     if ($id) {
         $flag = id(new PhabricatorFlag())->load($id);
         if (!$flag) {
             throw new ConduitException('ERR_NOT_FOUND');
         }
         if ($flag->getOwnerPHID() != $request->getUser()->getPHID()) {
             throw new ConduitException('ERR_WRONG_USER');
         }
     } elseif ($object) {
         $flag = id(new PhabricatorFlag())->loadOneWhere('objectPHID = %s AND ownerPHID = %s', $object, $request->getUser()->getPHID());
         if (!$flag) {
             return null;
         }
     } else {
         throw new ConduitException('ERR_NEED_PARAM');
     }
     $this->attachHandleToFlag($flag);
     $ret = $this->buildFlagInfoDictionary($flag);
     $flag->delete();
     return $ret;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $results = array();
     $revision_ids = $request->getValue('ids');
     if (!$revision_ids) {
         return $results;
     }
     $revisions = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs($revision_ids)->execute();
     if (!$revisions) {
         return $results;
     }
     $xactions = id(new DifferentialTransactionQuery())->setViewer($viewer)->withObjectPHIDs(mpull($revisions, 'getPHID'))->execute();
     $revisions = mpull($revisions, null, 'getPHID');
     foreach ($xactions as $xaction) {
         $revision = idx($revisions, $xaction->getObjectPHID());
         if (!$revision) {
             continue;
         }
         $type = $xaction->getTransactionType();
         if ($type == DifferentialTransaction::TYPE_ACTION) {
             $action = $xaction->getNewValue();
         } else {
             if ($type == PhabricatorTransactions::TYPE_COMMENT) {
                 $action = 'comment';
             } else {
                 $action = 'none';
             }
         }
         $result = array('revisionID' => $revision->getID(), 'action' => $action, 'authorPHID' => $xaction->getAuthorPHID(), 'dateCreated' => $xaction->getDateCreated(), 'content' => $xaction->hasComment() ? $xaction->getComment()->getContent() : null);
         $results[$revision->getID()][] = $result;
     }
     return $results;
 }
 protected function getMercurialResult(ConduitAPIRequest $request)
 {
     $drequest = $this->getDiffusionRequest();
     $path = $drequest->getPath();
     $grep = $request->getValue('grep');
     $repository = $drequest->getRepository();
     $limit = $request->getValue('limit');
     $offset = $request->getValue('offset');
     $results = array();
     $future = $repository->getLocalCommandFuture('grep --rev %s --print0 --line-number %s %s', hgsprintf('ancestors(%s)', $drequest->getStableCommit()), $grep, $path);
     $lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("");
     $parts = array();
     foreach ($lines as $line) {
         $parts[] = $line;
         if (count($parts) == 4) {
             list($path, $char_offset, $line, $string) = $parts;
             $results[] = array($path, $line, $string);
             if (count($results) >= $offset + $limit) {
                 break;
             }
             $parts = array();
         }
     }
     unset($lines);
     return $results;
 }
 /**
  * This method is final because most queries will need to construct a
  * @{class:DiffusionRequest} and use it. Consolidating this codepath and
  * enforcing @{method:getDiffusionRequest} works when we need it is good.
  *
  * @{method:getResult} should be overridden by subclasses as necessary, e.g.
  * there is a common operation across all version control systems that
  * should occur after @{method:getResult}, like formatting a timestamp.
  */
 protected final function execute(ConduitAPIRequest $request)
 {
     $identifier = $request->getValue('repository');
     if ($identifier === null) {
         $identifier = $request->getValue('callsign');
     }
     $drequest = DiffusionRequest::newFromDictionary(array('user' => $request->getUser(), 'repository' => $identifier, 'branch' => $request->getValue('branch'), 'path' => $request->getValue('path'), 'commit' => $request->getValue('commit')));
     if (!$drequest) {
         throw new Exception(pht('Repository "%s" is not a valid repository.', $identifier));
     }
     // Figure out whether we're going to handle this request on this device,
     // or proxy it to another node in the cluster.
     // If this is a cluster request and we need to proxy, we'll explode here
     // to prevent infinite recursion.
     $is_cluster_request = $request->getIsClusterRequest();
     $repository = $drequest->getRepository();
     $client = $repository->newConduitClient($request->getUser(), $is_cluster_request);
     if ($client) {
         // We're proxying, so just make an intracluster call.
         return $client->callMethodSynchronous($this->getAPIMethodName(), $request->getAllParameters());
     } else {
         // We pass this flag on to prevent proxying of any other Conduit calls
         // which we need to make in order to respond to this one. Although we
         // could safely proxy them, we take a big performance hit in the common
         // case, and doing more proxying wouldn't exercise any additional code so
         // we wouldn't gain a testability/predictability benefit.
         $drequest->setIsClusterRequest($is_cluster_request);
         $this->setDiffusionRequest($drequest);
         return $this->getResult($request);
     }
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $raw_diff = $request->getValue('diff');
     $repository_phid = $request->getValue('repositoryPHID');
     if ($repository_phid) {
         $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne();
         if (!$repository) {
             throw new Exception(pht('No such repository "%s"!', $repository_phid));
         }
     } else {
         $repository = null;
     }
     $parser = new ArcanistDiffParser();
     $changes = $parser->parseDiff($raw_diff);
     $diff = DifferentialDiff::newFromRawChanges($changes);
     $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
     $diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP);
     $diff->setAuthorPHID($viewer->getPHID());
     $diff->setCreationMethod('web');
     if ($repository) {
         $diff->setRepositoryPHID($repository->getPHID());
     }
     id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromConduitRequest($request))->saveDiff($diff);
     return $this->buildDiffInfoDictionary($diff);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff = null;
     $revision_id = $request->getValue('revision_id');
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if (!$revision) {
             throw new ConduitException('ERR_BAD_REVISION');
         }
         $diff = id(new DifferentialDiff())->loadOneWhere('revisionID = %d ORDER BY id DESC LIMIT 1', $revision->getID());
     } else {
         $diff_id = $request->getValue('diff_id');
         if ($diff_id) {
             $diff = id(new DifferentialDiff())->load($diff_id);
         }
     }
     if (!$diff) {
         throw new ConduitException('ERR_BAD_DIFF');
     }
     $diff->attachChangesets($diff->loadRelatives(new DifferentialChangeset(), 'diffID'));
     foreach ($diff->getChangesets() as $changeset) {
         $changeset->attachHunks($changeset->loadRelatives(new DifferentialHunk(), 'changesetID'));
     }
     $basic_dict = $diff->getDiffDict();
     // for conduit calls, the basic dict is not enough
     // we also need to include the arcanist project
     $project = $diff->loadArcanistProject();
     if ($project) {
         $project_name = $project->getName();
     } else {
         $project_name = null;
     }
     $basic_dict['projectName'] = $project_name;
     return $basic_dict;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $user_phid = $request->getUser()->getPHID();
     $from = $request->getValue('fromEpoch');
     $to = $request->getValue('toEpoch');
     if ($to <= $from) {
         throw new ConduitException('ERR-BAD-EPOCH');
     }
     $table = new PhabricatorCalendarEvent();
     $table->openTransaction();
     $table->beginReadLocking();
     $overlap = $table->loadAllWhere('userPHID = %s AND dateFrom < %d AND dateTo > %d', $user_phid, $to, $from);
     foreach ($overlap as $status) {
         if ($status->getDateFrom() < $from) {
             if ($status->getDateTo() > $to) {
                 // Split the interval.
                 id(new PhabricatorCalendarEvent())->setUserPHID($user_phid)->setDateFrom($to)->setDateTo($status->getDateTo())->setStatus($status->getStatus())->setDescription($status->getDescription())->save();
             }
             $status->setDateTo($from);
             $status->save();
         } else {
             if ($status->getDateTo() > $to) {
                 $status->setDateFrom($to);
                 $status->save();
             } else {
                 $status->delete();
             }
         }
     }
     $table->endReadLocking();
     $table->saveTransaction();
     return count($overlap);
 }
 private function processBranchRefs(ConduitAPIRequest $request, array $refs)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $offset = $request->getValue('offset');
     $limit = $request->getValue('limit');
     foreach ($refs as $key => $ref) {
         if (!$repository->shouldTrackBranch($ref->getShortName())) {
             unset($refs[$key]);
         }
     }
     $with_closed = $request->getValue('closed');
     if ($with_closed !== null) {
         foreach ($refs as $key => $ref) {
             $fields = $ref->getRawFields();
             if (idx($fields, 'closed') != $with_closed) {
                 unset($refs[$key]);
             }
         }
     }
     // NOTE: We can't apply the offset or limit until here, because we may have
     // filtered untrackable branches out of the result set.
     if ($offset) {
         $refs = array_slice($refs, $offset);
     }
     if ($limit) {
         $refs = array_slice($refs, 0, $limit);
     }
     return mpull($refs, 'toDictionary');
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $results = array();
     $revision_ids = $request->getValue('ids');
     if (!$revision_ids) {
         return $results;
     }
     $comments = id(new DifferentialComment())->loadAllWhere('revisionID IN (%Ld)', $revision_ids);
     $with_inlines = $request->getValue('inlines');
     if ($with_inlines) {
         $inlines = id(new DifferentialInlineComment())->loadAllWhere('revisionID IN (%Ld)', $revision_ids);
         $changesets = array();
         if ($inlines) {
             $changesets = id(new DifferentialChangeset())->loadAllWhere('id IN (%Ld)', array_unique(mpull($inlines, 'getChangesetID')));
             $inlines = mgroup($inlines, 'getCommentID');
         }
     }
     foreach ($comments as $comment) {
         $revision_id = $comment->getRevisionID();
         $result = array('revisionID' => $revision_id, 'action' => $comment->getAction(), 'authorPHID' => $comment->getAuthorPHID(), 'dateCreated' => $comment->getDateCreated(), 'content' => $comment->getContent());
         if ($with_inlines) {
             $result['inlines'] = array();
             foreach (idx($inlines, $comment->getID(), array()) as $inline) {
                 $changeset = idx($changesets, $inline->getChangesetID());
                 $result['inlines'][] = $this->buildInlineInfoDictionary($inline, $changeset);
             }
             // TODO: Put synthetic inlines without an attached comment somewhere.
         }
         $results[$revision_id][] = $result;
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $paths = $request->getValue('paths');
     $fragments = id(new PhragmentFragmentQuery())->setViewer($request->getUser())->withPaths($paths)->execute();
     $fragments = mpull($fragments, null, 'getPath');
     foreach ($paths as $path) {
         if (!array_key_exists($path, $fragments)) {
             throw new ConduitException('ERR_BAD_FRAGMENT');
         }
     }
     $results = array();
     foreach ($fragments as $path => $fragment) {
         $mappings = $fragment->getFragmentMappings($request->getUser(), $fragment->getPath());
         $file_phids = mpull(mpull($mappings, 'getLatestVersion'), 'getFilePHID');
         $files = id(new PhabricatorFileQuery())->setViewer($request->getUser())->withPHIDs($file_phids)->execute();
         $files = mpull($files, null, 'getPHID');
         $result = array();
         foreach ($mappings as $cpath => $child) {
             $file_phid = $child->getLatestVersion()->getFilePHID();
             if (!isset($files[$file_phid])) {
                 // Skip any files we don't have permission to access.
                 continue;
             }
             $file = $files[$file_phid];
             $cpath = substr($child->getPath(), strlen($fragment->getPath()) + 1);
             $result[] = array('phid' => $child->getPHID(), 'phidVersion' => $child->getLatestVersionPHID(), 'path' => $cpath, 'hash' => $file->getContentHash(), 'version' => $child->getLatestVersion()->getSequence(), 'uri' => $file->getViewURI());
         }
         $results[$path] = $result;
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $user = $request->getUser();
     $this->requireApplicationCapability(ProjectCreateProjectsCapability::CAPABILITY, $user);
     $history = id(new SprintQuery())->setViewer($user)->getTaskHistory($request->getValue('project'));
     return $history;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $logs = $request->getValue('logs');
     if (!is_array($logs)) {
         $logs = array();
     }
     $template = new PhabricatorChatLogEvent();
     $template->setLoggedByPHID($request->getUser()->getPHID());
     $objs = array();
     foreach ($logs as $log) {
         $channel_name = idx($log, 'channel');
         $service_name = idx($log, 'serviceName');
         $service_type = idx($log, 'serviceType');
         $channel = id(new PhabricatorChatLogChannel())->loadOneWhere('channelName = %s AND serviceName = %s AND serviceType = %s', $channel_name, $service_name, $service_type);
         if (!$channel) {
             $channel = id(new PhabricatorChatLogChannel())->setChannelName($channel_name)->setserviceName($service_name)->setServiceType($service_type)->setViewPolicy(PhabricatorPolicies::POLICY_USER)->setEditPolicy(PhabricatorPolicies::POLICY_USER)->save();
         }
         $obj = clone $template;
         $obj->setChannelID($channel->getID());
         $obj->setType(idx($log, 'type'));
         $obj->setAuthor(idx($log, 'author'));
         $obj->setEpoch(idx($log, 'epoch'));
         $obj->setMessage(idx($log, 'message'));
         $obj->save();
         $objs[] = $obj;
     }
     return array_values(mpull($objs, 'getID'));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $source = $request->getValue('code');
     $future = xhpast_get_parser_future($source);
     list($stdout) = $future->resolvex();
     return json_decode($stdout, true);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $corpus = $request->getValue('corpus');
     $is_partial = $request->getValue('partial');
     $revision = new DifferentialRevision();
     $field_list = PhabricatorCustomField::getObjectFields($revision, DifferentialCustomField::ROLE_COMMITMESSAGE);
     $field_list->setViewer($viewer);
     $field_map = mpull($field_list->getFields(), null, 'getFieldKeyForConduit');
     $this->errors = array();
     $label_map = $this->buildLabelMap($field_list);
     $corpus_map = $this->parseCommitMessage($corpus, $label_map);
     $values = array();
     foreach ($corpus_map as $field_key => $text_value) {
         $field = idx($field_map, $field_key);
         if (!$field) {
             throw new Exception(pht('Parser emitted text value for field key "%s", but no such ' . 'field exists.', $field_key));
         }
         try {
             $values[$field_key] = $field->parseValueFromCommitMessage($text_value);
         } catch (DifferentialFieldParseException $ex) {
             $this->errors[] = pht('Error parsing field "%s": %s', $field->renderCommitMessageLabel(), $ex->getMessage());
         }
     }
     if (!$is_partial) {
         foreach ($field_map as $key => $field) {
             try {
                 $field->validateCommitMessageValue(idx($values, $key));
             } catch (DifferentialFieldValidationException $ex) {
                 $this->errors[] = pht('Invalid or missing field "%s": %s', $field->renderCommitMessageLabel(), $ex->getMessage());
             }
         }
     }
     return array('errors' => $this->errors, 'fields' => $values);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $corpus = $request->getValue('corpus');
     $aux_fields = DifferentialFieldSelector::newSelector()->getFieldSpecifications();
     foreach ($aux_fields as $key => $aux_field) {
         if (!$aux_field->shouldAppearOnCommitMessage()) {
             unset($aux_fields[$key]);
         }
     }
     $aux_fields = mpull($aux_fields, null, 'getCommitMessageKey');
     // Build a map from labels (like "Test Plan") to field keys
     // (like "testPlan").
     $label_map = $this->buildLabelMap($aux_fields);
     $field_map = $this->parseCommitMessage($corpus, $label_map);
     $fields = array();
     $errors = array();
     foreach ($field_map as $field_key => $field_value) {
         $field = $aux_fields[$field_key];
         try {
             $fields[$field_key] = $field->parseValueFromCommitMessage($field_value);
         } catch (DifferentialFieldParseException $ex) {
             $field_label = $field->renderLabelForCommitMessage();
             $errors[] = "Error parsing field '{$field_label}': " . $ex->getMessage();
         }
     }
     // TODO: This is for backcompat only, remove once Arcanist gets updated.
     $error = head($errors);
     return array('error' => $error, 'errors' => $errors, 'fields' => $fields);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $arc_project_name = $request->getValue('arcProjectName');
     if ($arc_project_name) {
         $arc_project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere('name = %s', $arc_project_name);
         if (!$arc_project) {
             throw id(new ConduitException('ERR_UNKNOWN_ARC'))->setErrorDescription("Unknown Arcanist project '{$arc_project_name}': " . "are you using the correct Conduit URI?");
         }
         $releeph_projects = id(new ReleephProject())->loadAllWhere('arcanistProjectID = %d', $arc_project->getID());
     } else {
         $releeph_projects = id(new ReleephProject())->loadAll();
     }
     $releeph_projects = mfilter($releeph_projects, 'getIsActive');
     $result = array();
     foreach ($releeph_projects as $releeph_project) {
         $selector = $releeph_project->getReleephFieldSelector();
         $fields = $selector->getFieldSpecifications();
         $fields_info = array();
         foreach ($fields as $field) {
             $field->setReleephProject($releeph_project);
             if ($field->isEditable()) {
                 $key = $field->getKeyForConduit();
                 $fields_info[$key] = array('class' => get_class($field), 'name' => $field->getName(), 'key' => $key, 'arcHelp' => $field->renderHelpForArcanist());
             }
         }
         $releeph_branches = mfilter(id(new ReleephBranch())->loadAllWhere('releephProjectID = %d', $releeph_project->getID()), 'getIsActive');
         $releeph_branches_struct = array();
         foreach ($releeph_branches as $branch) {
             $releeph_branches_struct[] = array('branchName' => $branch->getName(), 'projectName' => $releeph_project->getName(), 'projectPHID' => $releeph_project->getPHID(), 'branchPHID' => $branch->getPHID());
         }
         $result[] = array('projectName' => $releeph_project->getName(), 'projectPHID' => $releeph_project->getPHID(), 'branches' => $releeph_branches_struct, 'fields' => $fields_info);
     }
     return $result;
 }
 protected function getResult(ConduitAPIRequest $request)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $commit = $request->getValue('commit');
     if (!$repository->isGit()) {
         throw new Exception(pht('This API method can only be called on Git repositories.'));
     }
     // Check if the commit has parents. We're testing to see whether it is the
     // first commit in history (in which case we must use "git log") or some
     // other commit (in which case we can use "git diff"). We'd rather use
     // "git diff" because it has the right behavior for merge commits, but
     // it requires the commit to have a parent that we can diff against. The
     // first commit doesn't, so "commit^" is not a valid ref.
     list($parents) = $repository->execxLocalCommand('log -n1 --format=%s %s', '%P', $commit);
     $use_log = !strlen(trim($parents));
     // First, get a fast raw diff without "--find-copies-harder". This flag
     // produces better results for moves and copies, but is explosively slow
     // for large changes to large repositories. See T10423.
     $raw = $this->getRawDiff($repository, $commit, $use_log, false);
     // If we got a normal-sized diff (no more than 100 modified files), we'll
     // try using "--find-copies-harder" to improve the output. This improved
     // output is mostly useful for small changes anyway.
     $try_harder = substr_count($raw, "\n") <= 100;
     if ($try_harder) {
         try {
             $raw = $this->getRawDiff($repository, $commit, $use_log, true);
         } catch (Exception $ex) {
             // Just ignore any exception we hit, we'll use the fast output
             // instead.
         }
     }
     return $raw;
 }
 protected function getMercurialResult(ConduitAPIRequest $request)
 {
     $repository = $this->getDiffusionRequest()->getRepository();
     $commit = $request->getValue('commit');
     list($err, $stdout) = $repository->execLocalCommand('id --rev %s', $commit);
     return !$err;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff = null;
     $revision_id = $request->getValue('revision_id');
     $revision = id(new DifferentialRevision())->load($revision_id);
     if (!$revision) {
         throw new ConduitException('ERR_BAD_REVISION');
     }
     $revision->loadRelationships();
     $reviewer_phids = array_values($revision->getReviewers());
     $diffs = $revision->loadDiffs();
     $diff_dicts = array();
     foreach ($diffs as $diff) {
         $diff->attachChangesets($diff->loadChangesets());
         // TODO: We could batch this to improve performance.
         foreach ($diff->getChangesets() as $changeset) {
             $changeset->attachHunks($changeset->loadHunks());
         }
         $diff_dicts[] = $diff->getDiffDict();
     }
     $commit_dicts = array();
     $commit_phids = $revision->loadCommitPHIDs();
     $handles = id(new PhabricatorObjectHandleData($commit_phids))->loadHandles();
     foreach ($commit_phids as $commit_phid) {
         $commit_dicts[] = array('fullname' => $handles[$commit_phid]->getFullName(), 'dateCommitted' => $handles[$commit_phid]->getTimestamp());
     }
     $auxiliary_fields = $this->loadAuxiliaryFields($revision);
     $dict = array('id' => $revision->getID(), 'phid' => $revision->getPHID(), 'authorPHID' => $revision->getAuthorPHID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID()), 'title' => $revision->getTitle(), 'status' => $revision->getStatus(), 'statusName' => ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($revision->getStatus()), 'summary' => $revision->getSummary(), 'testPlan' => $revision->getTestPlan(), 'lineCount' => $revision->getLineCount(), 'reviewerPHIDs' => $reviewer_phids, 'diffs' => $diff_dicts, 'commits' => $commit_dicts, 'auxiliary' => $auxiliary_fields);
     return $dict;
 }
 protected function getGitResult(ConduitAPIRequest $request)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $commit = $drequest->getSymbolicCommit();
     $commit_filter = null;
     if ($commit) {
         $commit_filter = $this->loadTagNamesForCommit($commit);
     }
     $name_filter = $request->getValue('names', null);
     $all_tags = $this->loadGitTagList();
     $all_tags = mpull($all_tags, null, 'getName');
     if ($name_filter !== null) {
         $all_tags = array_intersect_key($all_tags, array_fuse($name_filter));
     }
     if ($commit_filter !== null) {
         $all_tags = array_intersect_key($all_tags, $commit_filter);
     }
     $tags = array_values($all_tags);
     $offset = $request->getValue('offset');
     $limit = $request->getValue('limit');
     if ($offset) {
         $tags = array_slice($tags, $offset);
     }
     if ($limit) {
         $tags = array_slice($tags, 0, $limit);
     }
     if ($request->getValue('needMessages')) {
         $this->loadMessagesForTags($all_tags);
     }
     return mpull($tags, 'toDictionary');
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff = null;
     $revision_id = $request->getValue('revision_id');
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if (!$revision) {
             throw new ConduitException('ERR_BAD_REVISION');
         }
         $diff = id(new DifferentialDiff())->loadOneWhere('revisionID = %d ORDER BY id DESC LIMIT 1', $revision->getID());
     } else {
         $diff_id = $request->getValue('diff_id');
         if ($diff_id) {
             $diff = id(new DifferentialDiff())->load($diff_id);
         }
     }
     if (!$diff) {
         throw new ConduitException('ERR_BAD_DIFF');
     }
     $diff->attachChangesets($diff->loadChangesets());
     // TODO: We could batch this to improve performance.
     foreach ($diff->getChangesets() as $changeset) {
         $changeset->attachHunks($changeset->loadHunks());
     }
     return $this->createDiffDict($diff);
 }
 public final function respondToConduitRequest(ConduitAPIRequest $request)
 {
     $drequest = $this->getRequest();
     $timeout = $request->getValue('timeout');
     if ($timeout) {
         $this->setTimeout($timeout);
     }
     $byte_limit = $request->getValue('byteLimit');
     if ($byte_limit) {
         $this->setByteLimit($byte_limit);
     }
     $file = $this->execute();
     $too_slow = (bool) $this->getExceededTimeLimit();
     $too_huge = (bool) $this->getExceededByteLimit();
     $file_phid = null;
     if (!$too_slow && !$too_huge) {
         $repository = $drequest->getRepository();
         $repository_phid = $repository->getPHID();
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         $file->attachToObject($repository_phid);
         unset($unguarded);
         $file_phid = $file->getPHID();
     }
     return array('tooSlow' => $too_slow, 'tooHuge' => $too_huge, 'filePHID' => $file_phid);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $results = array();
     $task_ids = $request->getValue('ids');
     if (!$task_ids) {
         return $results;
     }
     $tasks = id(new ManiphestTaskQuery())->setViewer($request->getUser())->withIDs($task_ids)->execute();
     $tasks = mpull($tasks, null, 'getPHID');
     $transactions = array();
     if ($tasks) {
         $transactions = id(new ManiphestTransactionQuery())->setViewer($request->getUser())->withObjectPHIDs(mpull($tasks, 'getPHID'))->needComments(true)->execute();
     }
     foreach ($transactions as $transaction) {
         $task_phid = $transaction->getObjectPHID();
         if (empty($tasks[$task_phid])) {
             continue;
         }
         $task_id = $tasks[$task_phid]->getID();
         $comments = null;
         if ($transaction->hasComment()) {
             $comments = $transaction->getComment()->getContent();
         }
         $results[$task_id][] = array('taskID' => $task_id, 'transactionPHID' => $transaction->getPHID(), 'transactionType' => $transaction->getTransactionType(), 'oldValue' => $transaction->getOldValue(), 'newValue' => $transaction->getNewValue(), 'comments' => $comments, 'authorPHID' => $transaction->getAuthorPHID(), 'dateCreated' => $transaction->getDateCreated());
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $need_messages = $request->getValue('needMessages');
     $bypass_cache = $request->getValue('bypassCache');
     $query = id(new DiffusionCommitQuery())->setViewer($request->getUser())->needCommitData(true);
     $repository_phid = $request->getValue('repositoryPHID');
     if ($repository_phid) {
         $repository = id(new PhabricatorRepositoryQuery())->setViewer($request->getUser())->withPHIDs(array($repository_phid))->executeOne();
         if ($repository) {
             $query->withRepository($repository);
         }
     }
     $names = $request->getValue('names');
     if ($names) {
         $query->withIdentifiers($names);
     }
     $ids = $request->getValue('ids');
     if ($ids) {
         $query->withIDs($ids);
     }
     $phids = $request->getValue('phids');
     if ($phids) {
         $query->withPHIDs($phids);
     }
     $pager = $this->newPager($request);
     $commits = $query->executeWithCursorPager($pager);
     $map = $query->getIdentifierMap();
     $map = mpull($map, 'getPHID');
     $data = array();
     foreach ($commits as $commit) {
         $commit_data = $commit->getCommitData();
         $callsign = $commit->getRepository()->getCallsign();
         $identifier = $commit->getCommitIdentifier();
         $uri = '/r' . $callsign . $identifier;
         $uri = PhabricatorEnv::getProductionURI($uri);
         $dict = array('id' => $commit->getID(), 'phid' => $commit->getPHID(), 'repositoryPHID' => $commit->getRepository()->getPHID(), 'identifier' => $identifier, 'epoch' => $commit->getEpoch(), 'uri' => $uri, 'isImporting' => !$commit->isImported(), 'summary' => $commit->getSummary(), 'authorPHID' => $commit->getAuthorPHID(), 'committerPHID' => $commit_data->getCommitDetail('committerPHID'), 'author' => $commit_data->getAuthorName(), 'authorName' => $commit_data->getCommitDetail('authorName'), 'authorEmail' => $commit_data->getCommitDetail('authorEmail'), 'committer' => $commit_data->getCommitDetail('committer'), 'committerName' => $commit_data->getCommitDetail('committerName'), 'committerEmail' => $commit_data->getCommitDetail('committerEmail'), 'hashes' => array());
         if ($bypass_cache) {
             $lowlevel_commitref = id(new DiffusionLowLevelCommitQuery())->setRepository($commit->getRepository())->withIdentifier($commit->getCommitIdentifier())->execute();
             $dict['author'] = $lowlevel_commitref->getAuthor();
             $dict['authorName'] = $lowlevel_commitref->getAuthorName();
             $dict['authorEmail'] = $lowlevel_commitref->getAuthorEmail();
             $dict['committer'] = $lowlevel_commitref->getCommitter();
             $dict['committerName'] = $lowlevel_commitref->getCommitterName();
             $dict['committerEmail'] = $lowlevel_commitref->getCommitterEmail();
             if ($need_messages) {
                 $dict['message'] = $lowlevel_commitref->getMessage();
             }
             foreach ($lowlevel_commitref->getHashes() as $hash) {
                 $dict['hashes'][] = array('type' => $hash->getHashType(), 'value' => $hash->getHashValue());
             }
         }
         if ($need_messages && !$bypass_cache) {
             $dict['message'] = $commit_data->getCommitMessage();
         }
         $data[$commit->getPHID()] = $dict;
     }
     $result = array('data' => $data, 'identifierMap' => nonempty($map, (object) array()));
     return $this->addPagerResults($result, $pager);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $user = $request->getUser();
     $times = id(new PhrequentUserTimeQuery())->setViewer($user)->needPreemptingEvents(true)->withEnded(PhrequentUserTimeQuery::ENDED_NO)->withUserPHIDs(array($user->getPHID()))->execute();
     $now = time();
     $results = id(new PhrequentTimeBlock($times))->getCurrentWorkStack($now);
     return array('data' => $results);
 }