@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support Herald rules for new Differential edits

Summary:
Ref T2222. Ref T4484. See D8404 for discussion.

When a revision is updated with the new Editor, apply Herald rules. Additionally, apply them in a modern way which generates transactions.

Test Plan: {F122299}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, chad

Maniphest Tasks: T2222, T4484

Differential Revision: https://secure.phabricator.com/D8405

+156
+137
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 3 3 final class DifferentialTransactionEditor 4 4 extends PhabricatorApplicationTransactionEditor { 5 5 6 + private $heraldEmailPHIDs; 7 + 6 8 public function getTransactionTypes() { 7 9 $types = parent::getTransactionTypes(); 8 10 ··· 851 853 return $phids; 852 854 } 853 855 856 + protected function getMailCC(PhabricatorLiskDAO $object) { 857 + $phids = parent::getMailCC($object); 858 + 859 + if ($this->heraldEmailPHIDs) { 860 + foreach ($this->heraldEmailPHIDs as $phid) { 861 + $phids[] = $phid; 862 + } 863 + } 864 + 865 + return $phids; 866 + } 867 + 854 868 protected function getMailSubjectPrefix() { 855 869 return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix'); 856 870 } ··· 1072 1086 ->executeOne(); 1073 1087 } 1074 1088 1089 + /* -( Herald Integration )------------------------------------------------- */ 1090 + 1091 + protected function shouldApplyHeraldRules( 1092 + PhabricatorLiskDAO $object, 1093 + array $xactions) { 1094 + 1095 + if ($this->getIsNewObject()) { 1096 + return true; 1097 + } 1098 + 1099 + foreach ($xactions as $xaction) { 1100 + switch ($xaction->getTransactionType()) { 1101 + case DifferentialTransaction::TYPE_UPDATE: 1102 + return true; 1103 + } 1104 + } 1105 + 1106 + return parent::shouldApplyHeraldRules($object, $xactions); 1107 + } 1108 + 1109 + protected function buildHeraldAdapter( 1110 + PhabricatorLiskDAO $object, 1111 + array $xactions) { 1112 + 1113 + $unsubscribed_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 1114 + $object->getPHID(), 1115 + PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER); 1116 + 1117 + $subscribed_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID( 1118 + $object->getPHID()); 1119 + 1120 + $revision = id(new DifferentialRevisionQuery()) 1121 + ->setViewer($this->getActor()) 1122 + ->withPHIDs(array($object->getPHID())) 1123 + ->needActiveDiffs(true) 1124 + ->needReviewerStatus(true) 1125 + ->executeOne(); 1126 + if (!$revision) { 1127 + throw new Exception( 1128 + pht( 1129 + 'Failed to load revision for Herald adapter construction!')); 1130 + } 1131 + 1132 + $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( 1133 + $object, 1134 + $object->getActiveDiff()); 1135 + 1136 + $reviewers = $revision->getReviewerStatus(); 1137 + $reviewer_phids = mpull($reviewers, 'getReviewerPHID'); 1138 + 1139 + $adapter->setExplicitCCs($subscribed_phids); 1140 + $adapter->setExplicitReviewers($reviewer_phids); 1141 + $adapter->setForbiddenCCs($unsubscribed_phids); 1142 + 1143 + $adapter->setIsNewObject($this->getIsNewObject()); 1144 + 1145 + return $adapter; 1146 + } 1147 + 1148 + protected function didApplyHeraldRules( 1149 + PhabricatorLiskDAO $object, 1150 + HeraldAdapter $adapter, 1151 + HeraldTranscript $transcript) { 1152 + 1153 + $xactions = array(); 1154 + 1155 + // Build a transaction to adjust CCs. 1156 + $ccs = array( 1157 + '+' => array_keys($adapter->getCCsAddedByHerald()), 1158 + '-' => array_keys($adapter->getCCsRemovedByHerald()), 1159 + ); 1160 + $value = array(); 1161 + foreach ($ccs as $type => $phids) { 1162 + foreach ($phids as $phid) { 1163 + $value[$type][$phid] = $phid; 1164 + } 1165 + } 1166 + 1167 + if ($value) { 1168 + $xactions[] = id(new DifferentialTransaction()) 1169 + ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 1170 + ->setNewValue($value); 1171 + } 1172 + 1173 + // Build a transaction to adjust reviewers. 1174 + $reviewers = array( 1175 + DifferentialReviewerStatus::STATUS_ADDED => 1176 + array_keys($adapter->getReviewersAddedByHerald()), 1177 + DifferentialReviewerStatus::STATUS_BLOCKING => 1178 + array_keys($adapter->getBlockingReviewersAddedByHerald()), 1179 + ); 1180 + 1181 + $value = array(); 1182 + foreach ($reviewers as $status => $phids) { 1183 + foreach ($phids as $phid) { 1184 + $value['+'][$phid] = array( 1185 + 'data' => array( 1186 + 'status' => $status, 1187 + ), 1188 + ); 1189 + } 1190 + } 1191 + 1192 + if ($value) { 1193 + $edge_reviewer = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER; 1194 + 1195 + $xactions[] = id(new DifferentialTransaction()) 1196 + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 1197 + ->setMetadataValue('edge:type', $edge_reviewer) 1198 + ->setNewValue($value); 1199 + } 1200 + 1201 + // Save extra email PHIDs for later. 1202 + $this->heraldEmailPHIDs = $adapter->getEmailPHIDsAddedByHerald(); 1203 + 1204 + // Apply build plans. 1205 + HarbormasterBuildable::applyBuildPlans( 1206 + $adapter->getDiff(), 1207 + $adapter->getPHID(), 1208 + $adapter->getBuildPlans()); 1209 + 1210 + return $xactions; 1211 + } 1075 1212 1076 1213 }
+4
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 28 28 return $this->revision; 29 29 } 30 30 31 + public function getDiff() { 32 + return $this->diff; 33 + } 34 + 31 35 public function getAdapterContentType() { 32 36 return 'differential'; 33 37 }
+15
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 1634 1634 ->setIsBulk(true) 1635 1635 ->setBody($body->render()); 1636 1636 1637 + $herald_xscript = $this->getHeraldTranscript(); 1638 + if ($herald_xscript) { 1639 + $herald_header = $herald_xscript->getXHeraldRulesHeader(); 1640 + $herald_header = HeraldTranscript::saveXHeraldRulesHeader( 1641 + $object->getPHID(), 1642 + $herald_header); 1643 + } else { 1644 + $herald_header = HeraldTranscript::loadXHeraldRulesHeader( 1645 + $object->getPHID()); 1646 + } 1647 + 1648 + if ($herald_header) { 1649 + $template->addHeader('X-Herald-Rules', $herald_header); 1650 + } 1651 + 1637 1652 if ($this->getParentMessageID()) { 1638 1653 $template->setParentMessageID($this->getParentMessageID()); 1639 1654 }