@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.

Implement "Auto Review" in packages with a "Subscribe" option

Summary:
Ref T10939. Ref T8887. This moves toward letting packages automatically become reviewers or blocking reviewers of owned code.

This change adds an "Auto Review" option to packages. Because adding reviewers/blocking reviewers is a little tricky, it doesn't actually have these options yet -- just a "subscribe" option. I'll do the reviewer work in the next update.

Test Plan:
Created a revision in a package with "Auto Review: Subscribe to Changes". The package got subscribed.

{F1311677}

{F1311678}

{F1311679}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8887, T10939

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

+182 -9
+2
resources/sql/autopatches/20160513.owners.01.autoreview.sql
··· 1 + ALTER TABLE {$NAMESPACE}_owners.owners_package 2 + ADD autoReview VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
+2
resources/sql/autopatches/20160513.owners.02.autoreviewnone.sql
··· 1 + UPDATE {$NAMESPACE}_owners.owners_package 2 + SET autoReview = 'none' WHERE autoReview = '';
+1 -1
src/applications/differential/customfield/DifferentialProjectReviewersField.php
··· 8 8 } 9 9 10 10 public function getFieldName() { 11 - return pht('Coalition Reviewers'); 11 + return pht('Group Reviewers'); 12 12 } 13 13 14 14 public function getFieldDescription() {
+73
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 7 7 private $isCloseByCommit; 8 8 private $repositoryPHIDOverride = false; 9 9 private $didExpandInlineState = false; 10 + private $affectedPaths; 10 11 11 12 public function getEditorApplicationClass() { 12 13 return 'PhabricatorDifferentialApplication'; ··· 1481 1482 return parent::shouldApplyHeraldRules($object, $xactions); 1482 1483 } 1483 1484 1485 + protected function didApplyHeraldRules( 1486 + PhabricatorLiskDAO $object, 1487 + HeraldAdapter $adapter, 1488 + HeraldTranscript $transcript) { 1489 + 1490 + $repository = $object->getRepository(); 1491 + if (!$repository) { 1492 + return array(); 1493 + } 1494 + 1495 + if (!$this->affectedPaths) { 1496 + return array(); 1497 + } 1498 + 1499 + $packages = PhabricatorOwnersPackage::loadAffectedPackages( 1500 + $repository, 1501 + $this->affectedPaths); 1502 + 1503 + foreach ($packages as $key => $package) { 1504 + if ($package->isArchived()) { 1505 + unset($packages[$key]); 1506 + } 1507 + } 1508 + 1509 + if (!$packages) { 1510 + return array(); 1511 + } 1512 + 1513 + $auto_subscribe = array(); 1514 + $auto_review = array(); 1515 + $auto_block = array(); 1516 + 1517 + foreach ($packages as $package) { 1518 + switch ($package->getAutoReview()) { 1519 + case PhabricatorOwnersPackage::AUTOREVIEW_SUBSCRIBE: 1520 + $auto_subscribe[] = $package; 1521 + break; 1522 + case PhabricatorOwnersPackage::AUTOREVIEW_REVIEW: 1523 + $auto_review[] = $package; 1524 + break; 1525 + case PhabricatorOwnersPackage::AUTOREVIEW_BLOCK: 1526 + $auto_block[] = $package; 1527 + break; 1528 + case PhabricatorOwnersPackage::AUTOREVIEW_NONE: 1529 + default: 1530 + break; 1531 + } 1532 + } 1533 + 1534 + $owners_phid = id(new PhabricatorOwnersApplication()) 1535 + ->getPHID(); 1536 + 1537 + $xactions = array(); 1538 + if ($auto_subscribe) { 1539 + 1540 + $xactions[] = $object->getApplicationTransactionTemplate() 1541 + ->setAuthorPHID($owners_phid) 1542 + ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 1543 + ->setNewValue( 1544 + array( 1545 + '+' => mpull($auto_subscribe, 'getPHID'), 1546 + )); 1547 + } 1548 + 1549 + // TODO: Implement autoreview and autoblock, but these are more invovled. 1550 + 1551 + return $xactions; 1552 + } 1553 + 1484 1554 protected function buildHeraldAdapter( 1485 1555 PhabricatorLiskDAO $object, 1486 1556 array $xactions) { ··· 1556 1626 } 1557 1627 } 1558 1628 $all_paths = array_keys($all_paths); 1629 + 1630 + // Save the affected paths; we'll use them later to query Owners. 1631 + $this->affectedPaths = $all_paths; 1559 1632 1560 1633 $path_ids = 1561 1634 PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths(
+6
src/applications/owners/controller/PhabricatorOwnersDetailController.php
··· 184 184 } 185 185 $view->addProperty(pht('Owners'), $owner_list); 186 186 187 + $auto = $package->getAutoReview(); 188 + $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); 189 + $spec = idx($autoreview_map, $auto, array()); 190 + $name = idx($spec, 'name', $auto); 191 + $view->addProperty(pht('Auto Review'), $name); 192 + 187 193 if ($package->getAuditingEnabled()) { 188 194 $auditing = pht('Enabled'); 189 195 } else {
+15
src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php
··· 84 84 EOTEXT 85 85 ); 86 86 87 + $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); 88 + $autoreview_map = ipull($autoreview_map, 'name'); 89 + 87 90 return array( 88 91 id(new PhabricatorTextEditField()) 89 92 ->setKey('name') ··· 100 103 ->setDatasource(new PhabricatorProjectOrUserDatasource()) 101 104 ->setIsCopyable(true) 102 105 ->setValue($object->getOwnerPHIDs()), 106 + id(new PhabricatorSelectEditField()) 107 + ->setKey('autoReview') 108 + ->setLabel(pht('Auto Review')) 109 + ->setDescription( 110 + pht( 111 + 'Automatically trigger reviews for commits affecting files in '. 112 + 'this package.')) 113 + ->setTransactionType( 114 + PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW) 115 + ->setIsCopyable(true) 116 + ->setValue($object->getAutoReview()) 117 + ->setOptions($autoreview_map), 103 118 id(new PhabricatorSelectEditField()) 104 119 ->setKey('auditing') 105 120 ->setLabel(pht('Auditing'))
+28
src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php
··· 20 20 $types[] = PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION; 21 21 $types[] = PhabricatorOwnersPackageTransaction::TYPE_PATHS; 22 22 $types[] = PhabricatorOwnersPackageTransaction::TYPE_STATUS; 23 + $types[] = PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW; 23 24 24 25 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 25 26 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; ··· 47 48 return mpull($paths, 'getRef'); 48 49 case PhabricatorOwnersPackageTransaction::TYPE_STATUS: 49 50 return $object->getStatus(); 51 + case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW: 52 + return $object->getAutoReview(); 50 53 } 51 54 } 52 55 ··· 58 61 case PhabricatorOwnersPackageTransaction::TYPE_NAME: 59 62 case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION: 60 63 case PhabricatorOwnersPackageTransaction::TYPE_STATUS: 64 + case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW: 61 65 return $xaction->getNewValue(); 62 66 case PhabricatorOwnersPackageTransaction::TYPE_PATHS: 63 67 $new = $xaction->getNewValue(); ··· 112 116 return; 113 117 case PhabricatorOwnersPackageTransaction::TYPE_STATUS: 114 118 $object->setStatus($xaction->getNewValue()); 119 + return; 120 + case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW: 121 + $object->setAutoReview($xaction->getNewValue()); 115 122 return; 116 123 } 117 124 ··· 127 134 case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION: 128 135 case PhabricatorOwnersPackageTransaction::TYPE_AUDITING: 129 136 case PhabricatorOwnersPackageTransaction::TYPE_STATUS: 137 + case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW: 130 138 return; 131 139 case PhabricatorOwnersPackageTransaction::TYPE_OWNERS: 132 140 $old = $xaction->getOldValue(); ··· 220 228 } 221 229 } 222 230 231 + break; 232 + case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW: 233 + $map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); 234 + foreach ($xactions as $xaction) { 235 + $new = $xaction->getNewValue(); 236 + 237 + if (empty($map[$new])) { 238 + $valid = array_keys($map); 239 + 240 + $errors[] = new PhabricatorApplicationTransactionValidationError( 241 + $type, 242 + pht('Invalid'), 243 + pht( 244 + 'Autoreview setting "%s" is not valid. '. 245 + 'Valid settings are: %s.', 246 + $new, 247 + implode(', ', $valid)), 248 + $xaction); 249 + } 250 + } 223 251 break; 224 252 case PhabricatorOwnersPackageTransaction::TYPE_PATHS: 225 253 if (!$xactions) {
+26
src/applications/owners/storage/PhabricatorOwnersPackage.php
··· 14 14 protected $name; 15 15 protected $originalName; 16 16 protected $auditingEnabled; 17 + protected $autoReview; 17 18 protected $description; 18 19 protected $primaryOwnerPHID; 19 20 protected $mailKey; ··· 28 29 const STATUS_ACTIVE = 'active'; 29 30 const STATUS_ARCHIVED = 'archived'; 30 31 32 + const AUTOREVIEW_NONE = 'none'; 33 + const AUTOREVIEW_SUBSCRIBE = 'subscribe'; 34 + const AUTOREVIEW_REVIEW = 'review'; 35 + const AUTOREVIEW_BLOCK = 'block'; 36 + 31 37 public static function initializeNewPackage(PhabricatorUser $actor) { 32 38 $app = id(new PhabricatorApplicationQuery()) 33 39 ->setViewer($actor) ··· 41 47 42 48 return id(new PhabricatorOwnersPackage()) 43 49 ->setAuditingEnabled(0) 50 + ->setAutoReview(self::AUTOREVIEW_NONE) 44 51 ->setViewPolicy($view_policy) 45 52 ->setEditPolicy($edit_policy) 46 53 ->attachPaths(array()) ··· 56 63 ); 57 64 } 58 65 66 + public static function getAutoreviewOptionsMap() { 67 + return array( 68 + self::AUTOREVIEW_NONE => array( 69 + 'name' => pht('No Autoreview'), 70 + ), 71 + self::AUTOREVIEW_SUBSCRIBE => array( 72 + 'name' => pht('Subscribe to Changes'), 73 + ), 74 + // TODO: Implement these. 75 + // self::AUTOREVIEW_REVIEW => array( 76 + // 'name' => pht('Review Changes'), 77 + // ), 78 + // self::AUTOREVIEW_BLOCK => array( 79 + // 'name' => pht('Review Changes (Blocking)'), 80 + // ), 81 + ); 82 + } 83 + 59 84 protected function getConfiguration() { 60 85 return array( 61 86 // This information is better available from the history table. ··· 69 94 'auditingEnabled' => 'bool', 70 95 'mailKey' => 'bytes20', 71 96 'status' => 'text32', 97 + 'autoReview' => 'text32', 72 98 ), 73 99 ) + parent::getConfiguration(); 74 100 }
+13
src/applications/owners/storage/PhabricatorOwnersPackageTransaction.php
··· 10 10 const TYPE_DESCRIPTION = 'owners.description'; 11 11 const TYPE_PATHS = 'owners.paths'; 12 12 const TYPE_STATUS = 'owners.status'; 13 + const TYPE_AUTOREVIEW = 'owners.autoreview'; 13 14 14 15 public function getApplicationName() { 15 16 return 'owners'; ··· 143 144 '%s archived this package.', 144 145 $this->renderHandleLink($author_phid)); 145 146 } 147 + case self::TYPE_AUTOREVIEW: 148 + $map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); 149 + $map = ipull($map, 'name'); 150 + 151 + $old = idx($map, $old, $old); 152 + $new = idx($map, $new, $new); 153 + 154 + return pht( 155 + '%s adjusted autoreview from "%s" to "%s".', 156 + $this->renderHandleLink($author_phid), 157 + $old, 158 + $new); 146 159 } 147 160 148 161 return parent::getTitle();
+16 -8
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 703 703 $xaction->setEditPolicy($this->getActingAsPHID()); 704 704 } 705 705 706 - $xaction->setAuthorPHID($this->getActingAsPHID()); 706 + // If the transaction already has an explicit author PHID, allow it to 707 + // stand. This is used by applications like Owners that hook into the 708 + // post-apply change pipeline. 709 + if (!$xaction->getAuthorPHID()) { 710 + $xaction->setAuthorPHID($this->getActingAsPHID()); 711 + } 712 + 707 713 $xaction->setContentSource($this->getContentSource()); 708 714 $xaction->attachViewer($actor); 709 715 $xaction->attachObject($object); ··· 957 963 if ($herald_xactions) { 958 964 $xscript_id = $this->getHeraldTranscript()->getID(); 959 965 foreach ($herald_xactions as $herald_xaction) { 966 + // Don't set a transcript ID if this is a transaction from another 967 + // application or source, like Owners. 968 + if ($herald_xaction->getAuthorPHID()) { 969 + continue; 970 + } 971 + 960 972 $herald_xaction->setMetadataValue('herald:transcriptID', $xscript_id); 961 973 } 962 974 ··· 1217 1229 $xaction, 1218 1230 pht('You can not apply transactions which already have IDs/PHIDs!')); 1219 1231 } 1232 + 1220 1233 if ($xaction->getObjectPHID()) { 1221 1234 throw new PhabricatorApplicationTransactionStructureException( 1222 1235 $xaction, ··· 1224 1237 'You can not apply transactions which already have %s!', 1225 1238 'objectPHIDs')); 1226 1239 } 1227 - if ($xaction->getAuthorPHID()) { 1228 - throw new PhabricatorApplicationTransactionStructureException( 1229 - $xaction, 1230 - pht( 1231 - 'You can not apply transactions which already have %s!', 1232 - 'authorPHIDs')); 1233 - } 1240 + 1234 1241 if ($xaction->getCommentPHID()) { 1235 1242 throw new PhabricatorApplicationTransactionStructureException( 1236 1243 $xaction, ··· 1238 1245 'You can not apply transactions which already have %s!', 1239 1246 'commentPHIDs')); 1240 1247 } 1248 + 1241 1249 if ($xaction->getCommentVersion() !== 0) { 1242 1250 throw new PhabricatorApplicationTransactionStructureException( 1243 1251 $xaction,