Differential D16846 Diff 40568 src/applications/differential/parser/DifferentialCommitMessageParser.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/parser/DifferentialCommitMessageParser.php
| Show All 21 Lines | |||||
| final class DifferentialCommitMessageParser extends Phobject { | final class DifferentialCommitMessageParser extends Phobject { | ||||
| private $labelMap; | private $labelMap; | ||||
| private $titleKey; | private $titleKey; | ||||
| private $summaryKey; | private $summaryKey; | ||||
| private $errors; | private $errors; | ||||
| public static function newStandardParser(PhabricatorUser $viewer) { | |||||
| $key_title = id(new DifferentialTitleField())->getFieldKeyForConduit(); | |||||
| $key_summary = id(new DifferentialSummaryField())->getFieldKeyForConduit(); | |||||
| $field_list = PhabricatorCustomField::getObjectFields( | |||||
| new DifferentialRevision(), | |||||
| DifferentialCustomField::ROLE_COMMITMESSAGE); | |||||
| $field_list->setViewer($viewer); | |||||
| $label_map = array(); | |||||
| foreach ($field_list->getFields() as $field) { | |||||
| $labels = $field->getCommitMessageLabels(); | |||||
| $key = $field->getFieldKeyForConduit(); | |||||
| foreach ($labels as $label) { | |||||
| $normal_label = self::normalizeFieldLabel( | |||||
| $label); | |||||
| if (!empty($label_map[$normal_label])) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Field label "%s" is parsed by two custom fields: "%s" and '. | |||||
| '"%s". Each label must be parsed by only one field.', | |||||
| $label, | |||||
| $key, | |||||
| $label_map[$normal_label])); | |||||
| } | |||||
| $label_map[$normal_label] = $key; | |||||
| } | |||||
| } | |||||
| return id(new self()) | |||||
| ->setLabelMap($label_map) | |||||
| ->setTitleKey($key_title) | |||||
| ->setSummaryKey($key_summary); | |||||
| } | |||||
| /* -( Configuring the Parser )--------------------------------------------- */ | /* -( Configuring the Parser )--------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function setLabelMap(array $label_map) { | public function setLabelMap(array $label_map) { | ||||
| $this->labelMap = $label_map; | $this->labelMap = $label_map; | ||||
| ▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines | |||||