public function processRequest()
 {
     if (!PhabricatorEnv::getEnvConfig('feed.public')) {
         return new Aphront404Response();
     }
     // TODO: Profile images won't render correctly for logged-out users.
     $request = $this->getRequest();
     $query = new PhabricatorFeedQuery();
     $stories = $query->execute();
     $handles = array();
     $objects = array();
     if ($stories) {
         $handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs'));
         $object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs'));
         $handles = id(new PhabricatorObjectHandleData($handle_phids))->loadHandles();
         $objects = id(new PhabricatorObjectHandleData($object_phids))->loadObjects();
     }
     // TODO: We need this for timezones but should develop some more general
     // solution for logged-out pages.
     $dummy_user = new PhabricatorUser();
     $views = array();
     foreach ($stories as $story) {
         $story->setHandles($handles);
         $story->setObjects($objects);
         $view = $story->renderView();
         $view->setViewer($dummy_user);
         $views[] = $view->render();
     }
     return $this->buildStandardPageResponse($views, array('title' => 'Public Feed', 'public' => true));
 }
 protected function renderResultList(array $builds, PhabricatorSavedQuery $query, array $handles)
 {
     assert_instances_of($builds, 'HarbormasterBuild');
     $viewer = $this->requireViewer();
     $buildables = mpull($builds, 'getBuildable');
     $object_phids = mpull($buildables, 'getBuildablePHID');
     $initiator_phids = mpull($builds, 'getInitiatorPHID');
     $phids = array_mergev(array($initiator_phids, $object_phids));
     $phids = array_unique(array_filter($phids));
     $handles = $viewer->loadHandles($phids);
     $list = new PHUIObjectItemListView();
     foreach ($builds as $build) {
         $id = $build->getID();
         $initiator = $handles[$build->getInitiatorPHID()];
         $buildable_object = $handles[$build->getBuildable()->getBuildablePHID()];
         $item = id(new PHUIObjectItemView())->setViewer($viewer)->setObject($build)->setObjectName(pht('Build %d', $build->getID()))->setHeader($build->getName())->setHref($build->getURI())->setEpoch($build->getDateCreated())->addAttribute($buildable_object->getName());
         if ($initiator) {
             $item->addHandleIcon($initiator, $initiator->getName());
         }
         $status = $build->getBuildStatus();
         $status_icon = HarbormasterBuildStatus::getBuildStatusIcon($status);
         $status_color = HarbormasterBuildStatus::getBuildStatusColor($status);
         $status_label = HarbormasterBuildStatus::getBuildStatusName($status);
         $item->setStatusIcon("{$status_icon} {$status_color}", $status_label);
         $list->addItem($item);
     }
     $result = new PhabricatorApplicationSearchResultView();
     $result->setObjectList($list);
     $result->setNoDataString(pht('No builds found.'));
     return $result;
 }
 public function buildSearchForm(AphrontFormView $form, PhabricatorSavedQuery $saved)
 {
     $backer_phids = $saved->getParameter('backerPHIDs', array());
     $all_phids = array_mergev(array($backer_phids));
     $handles = id(new PhabricatorHandleQuery())->setViewer($this->requireViewer())->withPHIDs($all_phids)->execute();
     $form->appendChild(id(new AphrontFormTokenizerControl())->setLabel(pht('Backers'))->setName('backers')->setDatasource(new PhabricatorPeopleDatasource())->setValue(array_select_keys($handles, $backer_phids)));
 }
 private function shouldShowStory($story)
 {
     $story_objectphid = $story['objectPHID'];
     $story_text = $story['text'];
     $show = $this->getConfig('notification.types');
     if ($show) {
         $obj_type = phid_get_type($story_objectphid);
         if (!in_array(strtolower($obj_type), $show)) {
             return false;
         }
     }
     $verbosity = $this->getConfig('notification.verbosity', 3);
     $verbs = array();
     switch ($verbosity) {
         case 2:
             $verbs[] = array('commented', 'added', 'changed', 'resigned', 'explained', 'modified', 'attached', 'edited', 'joined', 'left', 'removed');
             // fallthrough
         // fallthrough
         case 1:
             $verbs[] = array('updated', 'accepted', 'requested', 'planned', 'claimed', 'summarized', 'commandeered', 'assigned');
             // fallthrough
         // fallthrough
         case 0:
             $verbs[] = array('created', 'closed', 'raised', 'committed', 'abandoned', 'reclaimed', 'reopened', 'deleted');
             break;
         case 3:
         default:
             return true;
     }
     $verbs = '/(' . implode('|', array_mergev($verbs)) . ')/';
     if (preg_match($verbs, $story_text)) {
         return true;
     }
     return false;
 }
 private function buildPanels()
 {
     $panel_specs = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorSettingsPanel')->setConcreteOnly(true)->selectAndLoadSymbols();
     $panels = array();
     foreach ($panel_specs as $spec) {
         $class = newv($spec['name'], array());
         $panels[] = $class->buildPanels();
     }
     $panels = array_mergev($panels);
     $panels = mpull($panels, null, 'getPanelKey');
     $result = array();
     foreach ($panels as $key => $panel) {
         $panel->setUser($this->user);
         if (!$panel->isEnabled()) {
             continue;
         }
         if (!$this->isSelf()) {
             if (!$panel->isEditableByAdministrators()) {
                 continue;
             }
         }
         if (!empty($result[$key])) {
             throw new Exception(pht("Two settings panels share the same panel key ('%s'): %s, %s.", $key, get_class($panel), get_class($result[$key])));
         }
         $result[$key] = $panel;
     }
     $result = msort($result, 'getPanelSortKey');
     if (!$result) {
         throw new Exception(pht('No settings panels are available.'));
     }
     return $result;
 }
 public function buildView()
 {
     if (!$this->user) {
         throw new Exception('Call setUser() before buildView()!');
     }
     $user = $this->user;
     $stories = $this->stories;
     $handles = array();
     if ($stories) {
         $handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs'));
         $object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs'));
         $handles = id(new PhabricatorObjectHandleData($handle_phids))->loadHandles();
     }
     $null_view = new AphrontNullView();
     require_celerity_resource('phabricator-feed-css');
     $last_date = null;
     foreach ($stories as $story) {
         $story->setHandles($handles);
         $story->setFramed($this->framed);
         $date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
         if ($date !== $last_date) {
             if ($last_date !== null) {
                 $null_view->appendChild('<div class="phabricator-feed-story-date-separator"></div>');
             }
             $last_date = $date;
             $null_view->appendChild(phutil_render_tag('div', array('class' => 'phabricator-feed-story-date'), phutil_escape_html($date)));
         }
         $view = $story->renderView();
         $view->setViewer($user);
         $null_view->appendChild($view);
     }
     return id(new AphrontNullView())->appendChild('<div class="phabricator-feed-frame">' . $null_view->render() . '</div>');
 }
 protected function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     // Reload the commit to pull commit data and audit requests.
     $commit = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIDs(array($commit->getID()))->needCommitData(true)->needAuditRequests(true)->executeOne();
     $data = $commit->getCommitData();
     if (!$data) {
         throw new PhabricatorWorkerPermanentFailureException(pht('Unable to load commit data. The data for this task is invalid ' . 'or no longer exists.'));
     }
     $commit->attachRepository($repository);
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_DAEMON, array());
     $committer_phid = $data->getCommitDetail('committerPHID');
     $author_phid = $data->getCommitDetail('authorPHID');
     $acting_as_phid = nonempty($committer_phid, $author_phid, id(new PhabricatorDiffusionApplication())->getPHID());
     $editor = id(new PhabricatorAuditEditor())->setActor(PhabricatorUser::getOmnipotentUser())->setActingAsPHID($acting_as_phid)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true)->setContentSource($content_source);
     $xactions = array();
     $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorAuditTransaction::TYPE_COMMIT)->setDateCreated($commit->getEpoch())->setNewValue(array('description' => $data->getCommitMessage(), 'summary' => $data->getSummary(), 'authorName' => $data->getAuthorName(), 'authorPHID' => $commit->getAuthorPHID(), 'committerName' => $data->getCommitDetail('committer'), 'committerPHID' => $data->getCommitDetail('committerPHID')));
     $reverts_refs = id(new DifferentialCustomFieldRevertsParser())->parseCorpus($data->getCommitMessage());
     $reverts = array_mergev(ipull($reverts_refs, 'monograms'));
     if ($reverts) {
         $reverted_commits = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withRepository($repository)->withIdentifiers($reverts)->execute();
         $reverted_commit_phids = mpull($reverted_commits, 'getPHID', 'getPHID');
         // NOTE: Skip any write attempts if a user cleverly implies a commit
         // reverts itself.
         unset($reverted_commit_phids[$commit->getPHID()]);
         $reverts_edge = DiffusionCommitRevertsCommitEdgeType::EDGECONST;
         $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $reverts_edge)->setNewValue(array('+' => array_fuse($reverted_commit_phids)));
     }
     try {
         $raw_patch = $this->loadRawPatchText($repository, $commit);
     } catch (Exception $ex) {
         $raw_patch = pht('Unable to generate patch: %s', $ex->getMessage());
     }
     $editor->setRawPatch($raw_patch);
     return $editor->applyTransactions($commit, $xactions);
 }
Esempio n. 8
0
 public function runTests($test_paths, $source_path)
 {
     if (empty($test_paths)) {
         return array();
     }
     $futures = array();
     $tmpfiles = array();
     foreach ($test_paths as $test_path) {
         $xunit_tmp = new TempFile();
         $cover_tmp = new TempFile();
         $future = $this->buildTestFuture($test_path, $xunit_tmp, $cover_tmp);
         $futures[$test_path] = $future;
         $tmpfiles[$test_path] = array('xunit' => $xunit_tmp, 'cover' => $cover_tmp);
     }
     $results = array();
     $futures = id(new FutureIterator($futures))->limit(4);
     foreach ($futures as $test_path => $future) {
         try {
             list($stdout, $stderr) = $future->resolvex();
         } catch (CommandException $exc) {
             if ($exc->getError() > 1) {
                 // 'nose' returns 1 when tests are failing/broken.
                 throw $exc;
             }
         }
         $xunit_tmp = $tmpfiles[$test_path]['xunit'];
         $cover_tmp = $tmpfiles[$test_path]['cover'];
         $this->parser = new ArcanistXUnitTestResultParser();
         $results[] = $this->parseTestResults($source_path, $xunit_tmp, $cover_tmp);
     }
     return array_mergev($results);
 }
 protected function getRequiredHandlePHIDsForResultList(array $objects, PhabricatorSavedQuery $query)
 {
     $phids = array();
     foreach ($objects as $mail) {
         $phids[] = $mail->getExpandedRecipientPHIDs();
     }
     return array_mergev($phids);
 }
 public function getRequiredObjectPHIDs()
 {
     $phids = array();
     foreach ($this->getAggregateStories() as $story) {
         $phids[] = $story->getRequiredObjectPHIDs();
     }
     return array_mergev($phids);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $package = id(new PhabricatorOwnersPackageQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->needPaths(true)->executeOne();
     if (!$package) {
         return new Aphront404Response();
     }
     $paths = $package->getPaths();
     $repository_phids = array();
     foreach ($paths as $path) {
         $repository_phids[$path->getRepositoryPHID()] = true;
     }
     if ($repository_phids) {
         $repositories = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array_keys($repository_phids))->execute();
         $repositories = mpull($repositories, null, 'getPHID');
     } else {
         $repositories = array();
     }
     $actions = $this->buildPackageActionView($package);
     $properties = $this->buildPackagePropertyView($package);
     $properties->setActionList($actions);
     $header = id(new PHUIHeaderView())->setUser($viewer)->setHeader($package->getName())->setPolicyObject($package);
     $panel = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     $commit_views = array();
     $commit_uri = id(new PhutilURI('/audit/'))->setQueryParams(array('auditorPHIDs' => $package->getPHID()));
     $attention_commits = id(new DiffusionCommitQuery())->setViewer($request->getUser())->withAuditorPHIDs(array($package->getPHID()))->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN)->needCommitData(true)->setLimit(10)->execute();
     if ($attention_commits) {
         $view = id(new PhabricatorAuditListView())->setUser($viewer)->setCommits($attention_commits);
         $commit_views[] = array('view' => $view, 'header' => pht('Commits in this Package that Need Attention'), 'button' => id(new PHUIButtonView())->setTag('a')->setHref($commit_uri->alter('status', 'open'))->setText(pht('View All Problem Commits')));
     }
     $all_commits = id(new DiffusionCommitQuery())->setViewer($request->getUser())->withAuditorPHIDs(array($package->getPHID()))->needCommitData(true)->setLimit(100)->execute();
     $view = id(new PhabricatorAuditListView())->setUser($viewer)->setCommits($all_commits)->setNoDataString(pht('No commits in this package.'));
     $commit_views[] = array('view' => $view, 'header' => pht('Recent Commits in Package'), 'button' => id(new PHUIButtonView())->setTag('a')->setHref($commit_uri)->setText(pht('View All Package Commits')));
     $phids = array();
     foreach ($commit_views as $commit_view) {
         $phids[] = $commit_view['view']->getRequiredHandlePHIDs();
     }
     $phids = array_mergev($phids);
     $handles = $this->loadViewerHandles($phids);
     $commit_panels = array();
     foreach ($commit_views as $commit_view) {
         $commit_panel = new PHUIObjectBoxView();
         $header = new PHUIHeaderView();
         $header->setHeader($commit_view['header']);
         if (isset($commit_view['button'])) {
             $header->addActionLink($commit_view['button']);
         }
         $commit_view['view']->setHandles($handles);
         $commit_panel->setHeader($header);
         $commit_panel->appendChild($commit_view['view']);
         $commit_panels[] = $commit_panel;
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($package->getName());
     $timeline = $this->buildTransactionTimeline($package, new PhabricatorOwnersPackageTransactionQuery());
     $timeline->setShouldTerminate(true);
     return $this->buildApplicationPage(array($crumbs, $panel, $this->renderPathsTable($paths, $repositories), $commit_panels, $timeline), array('title' => $package->getName()));
 }
 private function extractPHIDs(PhabricatorPolicy $policy, array $rule_objects)
 {
     $phids = array();
     foreach ($policy->getRules() as $rule) {
         $rule_object = $rule_objects[$rule['rule']];
         $phids[] = $rule_object->getRequiredHandlePHIDsForSummary($rule['value']);
     }
     return array_filter(array_mergev($phids));
 }
 public function parseTestResults($path)
 {
     $results = array();
     foreach (glob($path . "/*.xml") as $filename) {
         $parser = new ArcanistXUnitTestResultParser();
         $results[] = $parser->parseTestResults(Filesystem::readFile($filename));
     }
     return array_mergev($results);
 }
 public function loadResults()
 {
     $results = array();
     foreach ($this->getUsableDatasources() as $source) {
         $source->setRawQuery($this->getRawQuery())->setQuery($this->getQuery())->setViewer($this->getViewer())->setLimit($this->getLimit());
         $results[] = $source->loadResults();
     }
     return array_mergev($results);
 }
 public function loadResults()
 {
     $offset = $this->getOffset();
     $limit = $this->getLimit();
     // If the input query is a function like `members(platy`, and we can
     // parse the function, we strip the function off and hand the stripped
     // query to child sources. This makes it easier to implement function
     // sources in terms of real object sources.
     $raw_query = $this->getRawQuery();
     $is_function = false;
     if (self::isFunctionToken($raw_query)) {
         $is_function = true;
     }
     $stack = $this->getFunctionStack();
     $is_browse = $this->getIsBrowse();
     $results = array();
     foreach ($this->getUsableDatasources() as $source) {
         $source_stack = $stack;
         $source_query = $raw_query;
         if ($is_function) {
             // If this source can't handle the function, skip it.
             $function = $source->parseFunction($raw_query, $allow_partial = true);
             if (!$function) {
                 continue;
             }
             // If this source handles the function directly, strip the function.
             // Otherwise, this is something like a composite source which has
             // some internal source which can evaluate the function, but will
             // perform stripping later.
             if ($source->shouldStripFunction($function['name'])) {
                 $source_query = head($function['argv']);
                 $source_stack[] = $function['name'];
             }
         }
         $source->setFunctionStack($source_stack)->setRawQuery($source_query)->setQuery($this->getQuery())->setViewer($this->getViewer());
         if ($limit) {
             $source->setLimit($offset + $limit);
         }
         if ($is_browse) {
             $source->setIsBrowse(true);
         }
         $source_results = $source->loadResults();
         $source_results = $source->didLoadResults($source_results);
         $results[] = $source_results;
     }
     $results = array_mergev($results);
     $results = msort($results, 'getSortKey');
     $count = count($results);
     if ($offset || $limit) {
         if (!$limit) {
             $limit = count($results);
         }
         $results = array_slice($results, $offset, $limit, $preserve_keys = true);
     }
     return $results;
 }
 public function getRequiredHandlePHIDs()
 {
     $phids = array();
     foreach ($this->fields as $field) {
         foreach ($this->revisions as $revision) {
             $phids[] = $field->getRequiredHandlePHIDsForRevisionList($revision);
         }
     }
     return array_mergev($phids);
 }
 public function buildSearchForm(AphrontFormView $form, PhabricatorSavedQuery $saved)
 {
     $auditor_phids = $saved->getParameter('auditorPHIDs', array());
     $commit_author_phids = $saved->getParameter('commitAuthorPHIDs', array());
     $audit_status = $saved->getParameter('auditStatus', null);
     $repository_phids = $saved->getParameter('repositoryPHIDs', array());
     $phids = array_mergev(array($auditor_phids, $commit_author_phids, $repository_phids));
     $handles = id(new PhabricatorHandleQuery())->setViewer($this->requireViewer())->withPHIDs($phids)->execute();
     $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource(new DiffusionAuditorDatasource())->setName('auditorPHIDs')->setLabel(pht('Auditors'))->setValue(array_select_keys($handles, $auditor_phids)))->appendChild(id(new AphrontFormTokenizerControl())->setDatasource(new PhabricatorPeopleDatasource())->setName('authors')->setLabel(pht('Commit Authors'))->setValue(array_select_keys($handles, $commit_author_phids)))->appendChild(id(new AphrontFormSelectControl())->setName('auditStatus')->setLabel(pht('Audit Status'))->setOptions($this->getAuditStatusOptions())->setValue($audit_status))->appendChild(id(new AphrontFormTokenizerControl())->setLabel(pht('Repositories'))->setName('repositoryPHIDs')->setDatasource(new DiffusionRepositoryDatasource())->setValue(array_select_keys($handles, $repository_phids)));
 }
Esempio n. 18
0
 public function run()
 {
     $this->projectRoot = $this->getWorkingCopy()->getProjectRoot();
     $this->affectedTests = array();
     foreach ($this->getPaths() as $path) {
         $path = Filesystem::resolvePath($path, $this->projectRoot);
         // TODO: add support for directories
         // Users can call phpunit on the directory themselves
         if (is_dir($path)) {
             continue;
         }
         // Not sure if it would make sense to go further if
         // it is not a .php file
         if (substr($path, -4) != '.php') {
             continue;
         }
         if (substr($path, -8) == 'Test.php') {
             // Looks like a valid test file name.
             $this->affectedTests[$path] = $path;
             continue;
         }
         if ($test = $this->findTestFile($path)) {
             $this->affectedTests[$path] = $test;
         }
     }
     if (empty($this->affectedTests)) {
         throw new ArcanistNoEffectException(pht('No tests to run.'));
     }
     $this->prepareConfigFile();
     $futures = array();
     $tmpfiles = array();
     foreach ($this->affectedTests as $class_path => $test_path) {
         if (!Filesystem::pathExists($test_path)) {
             continue;
         }
         $json_tmp = new TempFile();
         $clover_tmp = null;
         $clover = null;
         if ($this->getEnableCoverage() !== false) {
             $clover_tmp = new TempFile();
             $clover = csprintf('--coverage-clover %s', $clover_tmp);
         }
         $config = $this->configFile ? csprintf('-c %s', $this->configFile) : null;
         $stderr = '-d display_errors=stderr';
         $futures[$test_path] = new ExecFuture('%C %C %C --log-json %s %C %s', $this->phpunitBinary, $config, $stderr, $json_tmp, $clover, $test_path);
         $tmpfiles[$test_path] = array('json' => $json_tmp, 'clover' => $clover_tmp);
     }
     $results = array();
     $futures = id(new FutureIterator($futures))->limit(4);
     foreach ($futures as $test => $future) {
         list($err, $stdout, $stderr) = $future->resolve();
         $results[] = $this->parseTestResults($test, $tmpfiles[$test]['json'], $tmpfiles[$test]['clover'], $stderr);
     }
     return array_mergev($results);
 }
Esempio n. 19
0
 private function computeRawFacts(PhabricatorLiskDAO $object)
 {
     $facts = array();
     foreach ($this->engines as $engine) {
         if (!$engine->shouldComputeRawFactsForObject($object)) {
             continue;
         }
         $facts[] = $engine->computeRawFactsForObject($object);
     }
     return array_mergev($facts);
 }
 public function getRequiredHandlePHIDs()
 {
     $phids = array();
     foreach ($this->revisions as $revision) {
         $phids[] = array($revision->getAuthorPHID());
         // TODO: Switch to getReviewerStatus(), but not all callers pass us
         // revisions with this data loaded.
         $phids[] = $revision->getReviewers();
     }
     return array_mergev($phids);
 }
 public function willApplyRules(PhabricatorUser $viewer, array $values, array $objects)
 {
     $values = array_unique(array_filter(array_mergev($values)));
     if (!$values) {
         return;
     }
     $projects = id(new PhabricatorProjectQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withMemberPHIDs(array($viewer->getPHID()))->withPHIDs($values)->execute();
     foreach ($projects as $project) {
         $this->memberships[$viewer->getPHID()][$project->getPHID()] = true;
     }
 }
 protected final function loadRunningDaemons()
 {
     $daemons = array();
     $pid_dir = $this->getPIDDirectory();
     $pid_files = Filesystem::listDirectory($pid_dir);
     foreach ($pid_files as $pid_file) {
         $path = $pid_dir . '/' . $pid_file;
         $daemons[] = PhabricatorDaemonReference::loadReferencesFromFile($path);
     }
     return array_mergev($daemons);
 }
 public function willApplyRules(PhabricatorUser $viewer, array $values, array $objects)
 {
     $values = array_unique(array_filter(array_mergev($values)));
     if (!$values) {
         return;
     }
     // TODO: This accepts signature of any version of the document, even an
     // older version.
     $documents = id(new LegalpadDocumentQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs($values)->withSignerPHIDs(array($viewer->getPHID()))->execute();
     $this->signatures = mpull($documents, 'getPHID', 'getPHID');
 }
Esempio n. 24
0
 public function run()
 {
     $paths = $this->getPaths();
     $affected_tests = array();
     foreach ($paths as $path) {
         $absolute_path = Filesystem::resolvePath($path);
         if (is_dir($absolute_path)) {
             $absolute_test_path = Filesystem::resolvePath("tests/" . $path);
             if (is_readable($absolute_test_path)) {
                 $affected_tests[] = $absolute_test_path;
             }
         }
         if (is_readable($absolute_path)) {
             $filename = basename($path);
             $directory = dirname($path);
             // assumes directory layout: tests/<package>/test_<module>.py
             $relative_test_path = "tests/" . $directory . "/test_" . $filename;
             $absolute_test_path = Filesystem::resolvePath($relative_test_path);
             if (is_readable($absolute_test_path)) {
                 $affected_tests[] = $absolute_test_path;
             }
         }
     }
     if (empty($affected_tests)) {
         return array();
     }
     $futures = array();
     $tmpfiles = array();
     foreach ($affected_tests as $test_path) {
         $xunit_tmp = new TempFile();
         $cover_tmp = new TempFile();
         $future = $this->buildTestFuture($test_path, $xunit_tmp, $cover_tmp);
         $futures[$test_path] = $future;
         $tmpfiles[$test_path] = array('xunit' => $xunit_tmp, 'cover' => $cover_tmp);
     }
     $results = array();
     foreach (Futures($futures)->limit(4) as $test_path => $future) {
         try {
             list($stdout, $stderr) = $future->resolvex();
         } catch (CommandException $exc) {
             if ($exc->getError() > 1) {
                 // 'nose' returns 1 when tests are failing/broken.
                 throw $exc;
             }
         }
         $xunit_tmp = $tmpfiles[$test_path]['xunit'];
         $cover_tmp = $tmpfiles[$test_path]['cover'];
         $results[] = $this->parseTestResults($test_path, $xunit_tmp, $cover_tmp);
     }
     return array_mergev($results);
 }
 public function buildSearchForm(AphrontFormView $form, PhabricatorSavedQuery $saved)
 {
     $statuses = $saved->getParameter('statuses', array());
     $statuses = array_fuse($statuses);
     $owner_phids = $saved->getParameter('ownerPHIDs', array());
     $all_phids = array_mergev(array($owner_phids));
     $handles = id(new PhabricatorHandleQuery())->setViewer($this->requireViewer())->withPHIDs($all_phids)->execute();
     $status_map = FundInitiative::getStatusNameMap();
     $status_control = id(new AphrontFormCheckboxControl())->setLabel(pht('Statuses'));
     foreach ($status_map as $status => $name) {
         $status_control->addCheckbox('statuses[]', $status, $name, isset($statuses[$status]));
     }
     $form->appendChild(id(new AphrontFormTokenizerControl())->setLabel(pht('Owners'))->setName('owners')->setDatasource(new PhabricatorPeopleDatasource())->setValue(array_select_keys($handles, $owner_phids)))->appendChild($status_control);
 }
Esempio n. 26
0
 public function run()
 {
     $this->projectRoot = $this->getWorkingCopy()->getProjectRoot();
     // If called with --everything, grab all tests in /spec/
     if ($this->getRunAllTests()) {
         $files = (new FileFinder($this->projectRoot . '/spec/'))->withType('f')->withSuffix('rb')->find();
         foreach ($files as $file) {
             if ('_spec.rb' == substr($file, -8)) {
                 $tests[] = 'spec/' . $file;
             }
         }
         $this->setPaths($tests);
     }
     foreach ($this->getPaths() as $path) {
         $path = Filesystem::resolvePath($path, $this->projectRoot);
         if (is_dir($path)) {
             continue;
         }
         if (substr($path, -3) != '.rb') {
             continue;
         }
         if (substr($path, -8) == '_spec.rb') {
             $this->affectedTests[$path] = $path;
             continue;
         }
         if ($test = $this->findTestForFile($path)) {
             $this->affectedTests[$path] = $test;
         }
     }
     if (!$this->affectedTests) {
         throw new ArcanistNoEffectException("No tests to run.");
     }
     $futures = [];
     $tempfiles = [];
     foreach ($this->affectedTests as $class_path => $test_path) {
         $json_tmp = new TempFile();
         $tempfiles[$test_path] = ['json' => $json_tmp];
         $futures[$test_path] = new ExecFuture('%C %C %C -o %s %s', 'rspec', '-f json', '--failure-exit-code 2', $json_tmp, $test_path);
     }
     $results = [];
     $cwd = getcwd();
     chdir($this->projectRoot);
     foreach ((new FutureIterator($futures))->limit(4) as $test => $future) {
         list($err, $stdout, $stderr) = $future->resolve();
         $json = file_get_contents($tempfiles[$test]['json']);
         $results[] = $this->parseTestResults($test, $json, $stderr, $err);
     }
     chdir($cwd);
     return array_mergev($results);
 }
 private function groupTasks(array $tasks, $group, array $handles)
 {
     assert_instances_of($tasks, 'ManiphestTask');
     assert_instances_of($handles, 'PhabricatorObjectHandle');
     $groups = $this->getTaskGrouping($tasks, $group);
     $results = array();
     foreach ($groups as $label_key => $tasks) {
         $label = $this->getTaskLabelName($group, $label_key, $handles);
         $results[$label][] = $tasks;
     }
     foreach ($results as $label => $task_groups) {
         $results[$label] = array_mergev($task_groups);
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $results = array();
     $user = $request->getUser();
     $view_type = $request->getValue('view');
     if (!$view_type) {
         $view_type = 'data';
     }
     $limit = $request->getValue('limit');
     if (!$limit) {
         $limit = $this->getDefaultLimit();
     }
     $filter_phids = $request->getValue('filter_phids');
     if (!$filter_phids) {
         $filter_phids = array();
     }
     $after = $request->getValue('after');
     $query = id(new PhabricatorFeedQuery())->setLimit($limit)->setFilterPHIDs($filter_phids)->setAfter($after);
     $stories = $query->execute();
     if ($stories) {
         $handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs'));
         $handles = id(new PhabricatorObjectHandleData($handle_phids))->loadHandles();
         foreach ($stories as $story) {
             $story->setHandles($handles);
             $story_data = $story->getStoryData();
             $data = null;
             $view = $story->renderView();
             $view->setEpoch($story->getEpoch());
             $view->setViewer($user);
             switch ($view_type) {
                 case 'html':
                     $data = $view->render();
                     break;
                 case 'html-summary':
                     $view->setOneLineStory(true);
                     $data = $view->render();
                     break;
                 case 'data':
                     $data = array('class' => $story_data->getStoryType(), 'epoch' => $story_data->getEpoch(), 'authorPHID' => $story_data->getAuthorPHID(), 'chronologicalKey' => $story_data->getChronologicalKey(), 'data' => $story_data->getStoryData());
                     break;
                 default:
                     throw new ConduitException('ERR-UNKNOWN-TYPE');
             }
             $results[$story_data->getPHID()] = $data;
         }
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $call = new ConduitCall('harbormaster.build.search', array_filter(array('constraints' => array_filter(array('ids' => $request->getValue('ids'), 'phids' => $request->getValue('phids'), 'statuses' => $request->getValue('buildStatuses'), 'buildables' => $request->getValue('buildablePHIDs'), 'plans' => $request->getValue('buildPlanPHIDs'))), 'attachments' => array('querybuilds' => true), 'limit' => $request->getValue('limit'), 'before' => $request->getValue('before'), 'after' => $request->getValue('after'))));
     $subsumption = $call->setUser($viewer)->execute();
     $data = array();
     foreach ($subsumption['data'] as $build_data) {
         $querybuilds = idxv($build_data, array('attachments', 'querybuilds'), array());
         $fields = idx($build_data, 'fields', array());
         unset($build_data['fields']);
         unset($build_data['attachments']);
         $data[] = array_mergev(array($build_data, $querybuilds, $fields));
     }
     $subsumption['data'] = $data;
     return $subsumption;
 }
Esempio n. 30
0
 public function testmergevMergingBasicallyWorksCorrectly()
 {
     $this->assertEqual(array(), array_mergev(array()));
     $this->assertEqual(array(), array_mergev(array(array(), array(), array())));
     $this->assertEqual(array(1, 2, 3, 4, 5), array_mergev(array(array(1, 2), array(3), array(), array(4, 5))));
     $not_valid = array('scalar' => array(1), 'array plus scalar' => array(array(), 1), 'null' => array(null));
     foreach ($not_valid as $key => $invalid_input) {
         $caught = null;
         try {
             array_mergev($invalid_input);
         } catch (InvalidArgumentException $ex) {
             $caught = $ex;
         }
         $this->assertTrue($caught instanceof InvalidArgumentException, "array_mergev() invalid on {$key}");
     }
 }