[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/controller/ -> DifferentialRevisionCloseDetailsController.php (source)

   1  <?php
   2  
   3  final class DifferentialRevisionCloseDetailsController
   4    extends DifferentialController {
   5  
   6    private $phid;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->phid = idx($data, 'phid');
  10    }
  11  
  12    public function processRequest() {
  13      $request = $this->getRequest();
  14  
  15      $viewer = $request->getUser();
  16      $xaction_phid = $this->phid;
  17  
  18      $xaction = id(new PhabricatorObjectQuery())
  19        ->withPHIDs(array($xaction_phid))
  20        ->setViewer($viewer)
  21        ->executeOne();
  22      if (!$xaction) {
  23        return new Aphront404Response();
  24      }
  25  
  26      $obj_phid = $xaction->getObjectPHID();
  27      $obj_handle = id(new PhabricatorHandleQuery())
  28        ->setViewer($viewer)
  29        ->withPHIDs(array($obj_phid))
  30        ->executeOne();
  31  
  32      $body = $this->getRevisionMatchExplanation(
  33        $xaction->getMetadataValue('revisionMatchData'),
  34        $obj_handle);
  35  
  36      $dialog = id(new AphrontDialogView())
  37        ->setUser($viewer)
  38        ->setTitle(pht('Commit Close Explanation'))
  39        ->appendParagraph($body)
  40        ->addCancelButton($obj_handle->getURI());
  41  
  42      return id(new AphrontDialogResponse())->setDialog($dialog);
  43    }
  44  
  45    private function getRevisionMatchExplanation(
  46      $revision_match_data,
  47      PhabricatorObjectHandle $obj_handle) {
  48  
  49      if (!$revision_match_data) {
  50        return pht(
  51          'This commit was made before this feature was built and thus this '.
  52          'information is unavailable.');
  53      }
  54  
  55      $body_why = array();
  56      if ($revision_match_data['usedURI']) {
  57        return pht(
  58          'We found a "Differential Revision" field with value "%s" in the '.
  59          'commit message, and the domain on the URI matches this install, so '.
  60          'we linked this commit to %s.',
  61          $revision_match_data['foundURI'],
  62          phutil_tag(
  63            'a',
  64            array(
  65              'href' => $obj_handle->getURI(),),
  66            $obj_handle->getName()));
  67      } else if ($revision_match_data['foundURI']) {
  68        $body_why[] = pht(
  69          'We found a "Differential Revision" field with value "%s" in the '.
  70          'commit message, but the domain on this URI did not match the '.
  71          'configured domain for this install, "%s", so we ignored it under '.
  72          'the assumption that it refers to some third-party revision.',
  73          $revision_match_data['foundURI'],
  74          $revision_match_data['validDomain']);
  75      } else {
  76        $body_why[] = pht(
  77          'We didn\'t find a "Differential Revision" field in the commit '.
  78          'message.');
  79      }
  80  
  81      switch ($revision_match_data['matchHashType']) {
  82        case ArcanistDifferentialRevisionHash::HASH_GIT_TREE:
  83          $hash_info = true;
  84          $hash_type = 'tree';
  85          break;
  86        case ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT:
  87        case ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT:
  88          $hash_info = true;
  89          $hash_type = 'commit';
  90          break;
  91        default:
  92          $hash_info = false;
  93          break;
  94      }
  95      if ($hash_info) {
  96        $diff_link = phutil_tag(
  97          'a',
  98          array(
  99            'href' => $obj_handle->getURI(),),
 100          $obj_handle->getName());
 101        $body_why = pht(
 102          'This commit and the active diff of %s had the same %s hash '.
 103          '(%s) so we linked this commit to %s.',
 104          $diff_link,
 105          $hash_type,
 106          $revision_match_data['matchHashValue'],
 107          $diff_link);
 108      }
 109  
 110      return phutil_implode_html("\n", $body_why);
 111  
 112    }
 113  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1