Ejemplo n.º 1
0
 protected function pruneUserComments(Issue $issue, DoBrowser $browser, $comment_words, InputInterface $input, OutputInterface $output)
 {
     $deleted_comments = 0;
     /** @var \DOMElement $comment */
     foreach ($issue->getCrawler()->filter('section.comments div.comment') as $comment) {
         $words = 0;
         $crawler = new Crawler($comment);
         if ($crawler->filter('.nodechanges-file-changes')->count() > 0) {
             // Has a file attached ignore.
             continue;
         }
         $comment_body = $crawler->filter('.field-name-comment-body div.field-item');
         if ($comment_body->count()) {
             $text = $comment_body->text();
             $words = str_word_count(trim($text));
         }
         // Zero word comments are often issue summary updates extra - ignore them
         // for now.
         if ($words <= $comment_words) {
             $changes = $crawler->filter('.field-name-field-issue-changes div.field-item');
             if ($changes->count()) {
                 $output->writeln("Comment issue changes: " . trim($changes->text()));
             }
             $output->writeln("Comment text: " . trim($text));
             if ($this->askConfirmation($input, $output, 'Delete this comment (yes/NO)? ')) {
                 $delete_link = $crawler->filter('li.comment-delete a, div.system-message.queued-retesting li.comment-delete a')->extract(array('href'));
                 $delete_link = $delete_link[0];
                 $this->deleteComment($delete_link, $browser, $output);
                 $deleted_comments++;
             }
             $output->writeln('');
         }
     }
     $output->writeln("Deleted {$deleted_comments} user comments.");
 }
Ejemplo n.º 2
0
 /**
  * @param Issue $issue
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return string|bool
  */
 protected function choosePatch(Issue $issue, InputInterface $input, OutputInterface $output)
 {
     $patch = FALSE;
     $patches_to_search = $issue->getLatestPatch();
     if (count($patches_to_search) > 1) {
         // Need to choose patch.
         $question_helper = new QuestionHelper();
         $output->writeln('Multiple patches detected:');
         $output->writeln($this->getChoices($patches_to_search));
         $question = new Question('Choose patch to search: ', 1);
         $question->setValidator(function ($patch_key) use($patches_to_search) {
             if (!in_array($patch_key, range(0, count($patches_to_search)))) {
                 throw new \InvalidArgumentException(sprintf('Choice "%s" is invalid.', $patch_key));
             }
             return $patch_key;
         });
         $patch_key = $question_helper->ask($input, $output, $question);
         $patch = $patches_to_search[$patch_key - 1];
     } elseif (count($patches_to_search) == 1) {
         $patch = $patches_to_search[0];
     } else {
         // Nothing to do.
         $output->writeln("No patches available on " . $issue->getUri());
     }
     return $patch;
 }