[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/conduit/work/ -> ReleephWorkGetCommitMessageConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class ReleephWorkGetCommitMessageConduitAPIMethod
   4    extends ReleephConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'releephwork.getcommitmessage';
   8    }
   9  
  10    public function getMethodStatus() {
  11      return self::METHOD_STATUS_UNSTABLE;
  12    }
  13  
  14    public function getMethodDescription() {
  15      return
  16        'Get commit message components for building '.
  17        'a ReleephRequest commit message.';
  18    }
  19  
  20    public function defineParamTypes() {
  21      $action_const = $this->formatStringConstants(array('pick', 'revert'));
  22  
  23      return array(
  24        'requestPHID' => 'required string',
  25        'action'      => 'required '.$action_const,
  26      );
  27    }
  28  
  29    public function defineReturnType() {
  30      return 'dict<string, string>';
  31    }
  32  
  33    public function defineErrorTypes() {
  34      return array();
  35    }
  36  
  37    protected function execute(ConduitAPIRequest $request) {
  38      $viewer = $request->getUser();
  39  
  40      $releeph_request = id(new ReleephRequestQuery())
  41        ->setViewer($viewer)
  42        ->withPHIDs(array($request->getValue('requestPHID')))
  43        ->executeOne();
  44  
  45      $action = $request->getValue('action');
  46  
  47      $title = $releeph_request->getSummaryForDisplay();
  48  
  49      $commit_message = array();
  50  
  51      $branch = $releeph_request->getBranch();
  52      $project = $branch->getProduct();
  53  
  54      $selector = $project->getReleephFieldSelector();
  55      $fields = $selector->getFieldSpecifications();
  56      $fields = $selector->sortFieldsForCommitMessage($fields);
  57  
  58      foreach ($fields as $field) {
  59        $field
  60          ->setUser($request->getUser())
  61          ->setReleephProject($project)
  62          ->setReleephBranch($branch)
  63          ->setReleephRequest($releeph_request);
  64  
  65        $label = null;
  66        $value = null;
  67  
  68        switch ($action) {
  69          case 'pick':
  70            if ($field->shouldAppearOnCommitMessage()) {
  71              $label = $field->renderLabelForCommitMessage();
  72              $value = $field->renderValueForCommitMessage();
  73            }
  74            break;
  75  
  76          case 'revert':
  77            if ($field->shouldAppearOnRevertMessage()) {
  78              $label = $field->renderLabelForRevertMessage();
  79              $value = $field->renderValueForRevertMessage();
  80            }
  81            break;
  82        }
  83  
  84        if ($label && $value) {
  85          if (strpos($value, "\n") !== false ||
  86              substr($value, 0, 2) === '  ') {
  87            $commit_message[] = "{$label}:\n{$value}";
  88          } else {
  89            $commit_message[] = "{$label}: {$value}";
  90          }
  91        }
  92      }
  93  
  94      return array(
  95        'title' => $title,
  96        'body'  => implode("\n\n", $commit_message),
  97      );
  98    }
  99  
 100  }


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