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

Differential - change "closed by commit" comment to real transaction

Summary:
Implements a new transaction - still TYPE_ACTION - but using a new DifferentialAction::ACTION_COMMIT_CLOSE. Augment rendering as necessary to display this new transaction. Saves enough information so T3686 is possible but stops short of implementing a popup to display this information. Fixes T5875. Ref T3686.

One small display oddity - this new transaction now renders at the top of the transaction group whereas when it was a comment it was on the bottom. I think this is basically okay but if not how fix? (Playing with the "strength" of these actions will mess up the email too?)

Test Plan: made a diff X that fixed task Y. committed. checked diff X, task Y, and the commit pages for proper transactions and all looked good.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T3686, T5875

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

+180 -114
+59 -59
src/applications/differential/constants/DifferentialAction.php
··· 22 22 23 23 public static function getBasicStoryText($action, $author_name) { 24 24 switch ($action) { 25 - case DifferentialAction::ACTION_COMMENT: 26 - $title = pht('%s commented on this revision.', 27 - $author_name); 25 + case DifferentialAction::ACTION_COMMENT: 26 + $title = pht('%s commented on this revision.', 27 + $author_name); 28 28 break; 29 - case DifferentialAction::ACTION_ACCEPT: 30 - $title = pht('%s accepted this revision.', 31 - $author_name); 29 + case DifferentialAction::ACTION_ACCEPT: 30 + $title = pht('%s accepted this revision.', 31 + $author_name); 32 32 break; 33 - case DifferentialAction::ACTION_REJECT: 34 - $title = pht('%s requested changes to this revision.', 35 - $author_name); 33 + case DifferentialAction::ACTION_REJECT: 34 + $title = pht('%s requested changes to this revision.', 35 + $author_name); 36 36 break; 37 - case DifferentialAction::ACTION_RETHINK: 38 - $title = pht('%s planned changes to this revision.', 39 - $author_name); 37 + case DifferentialAction::ACTION_RETHINK: 38 + $title = pht('%s planned changes to this revision.', 39 + $author_name); 40 40 break; 41 - case DifferentialAction::ACTION_ABANDON: 42 - $title = pht('%s abandoned this revision.', 43 - $author_name); 41 + case DifferentialAction::ACTION_ABANDON: 42 + $title = pht('%s abandoned this revision.', 43 + $author_name); 44 44 break; 45 - case DifferentialAction::ACTION_CLOSE: 46 - $title = pht('%s closed this revision.', 47 - $author_name); 45 + case DifferentialAction::ACTION_CLOSE: 46 + $title = pht('%s closed this revision.', 47 + $author_name); 48 48 break; 49 - case DifferentialAction::ACTION_REQUEST: 50 - $title = pht('%s requested a review of this revision.', 51 - $author_name); 49 + case DifferentialAction::ACTION_REQUEST: 50 + $title = pht('%s requested a review of this revision.', 51 + $author_name); 52 52 break; 53 - case DifferentialAction::ACTION_RECLAIM: 54 - $title = pht('%s reclaimed this revision.', 55 - $author_name); 53 + case DifferentialAction::ACTION_RECLAIM: 54 + $title = pht('%s reclaimed this revision.', 55 + $author_name); 56 56 break; 57 - case DifferentialAction::ACTION_UPDATE: 58 - $title = pht('%s updated this revision.', 59 - $author_name); 57 + case DifferentialAction::ACTION_UPDATE: 58 + $title = pht('%s updated this revision.', 59 + $author_name); 60 60 break; 61 - case DifferentialAction::ACTION_RESIGN: 62 - $title = pht('%s resigned from this revision.', 63 - $author_name); 61 + case DifferentialAction::ACTION_RESIGN: 62 + $title = pht('%s resigned from this revision.', 63 + $author_name); 64 64 break; 65 - case DifferentialAction::ACTION_SUMMARIZE: 66 - $title = pht('%s summarized this revision.', 67 - $author_name); 65 + case DifferentialAction::ACTION_SUMMARIZE: 66 + $title = pht('%s summarized this revision.', 67 + $author_name); 68 68 break; 69 - case DifferentialAction::ACTION_TESTPLAN: 70 - $title = pht('%s explained the test plan for this revision.', 71 - $author_name); 69 + case DifferentialAction::ACTION_TESTPLAN: 70 + $title = pht('%s explained the test plan for this revision.', 71 + $author_name); 72 72 break; 73 - case DifferentialAction::ACTION_CREATE: 74 - $title = pht('%s created this revision.', 75 - $author_name); 73 + case DifferentialAction::ACTION_CREATE: 74 + $title = pht('%s created this revision.', 75 + $author_name); 76 + break; 77 + case DifferentialAction::ACTION_ADDREVIEWERS: 78 + $title = pht('%s added reviewers to this revision.', 79 + $author_name); 76 80 break; 77 - case DifferentialAction::ACTION_ADDREVIEWERS: 78 - $title = pht('%s added reviewers to this revision.', 79 - $author_name); 81 + case DifferentialAction::ACTION_ADDCCS: 82 + $title = pht('%s added CCs to this revision.', 83 + $author_name); 80 84 break; 81 - case DifferentialAction::ACTION_ADDCCS: 82 - $title = pht('%s added CCs to this revision.', 83 - $author_name); 85 + case DifferentialAction::ACTION_CLAIM: 86 + $title = pht('%s commandeered this revision.', 87 + $author_name); 84 88 break; 85 - case DifferentialAction::ACTION_CLAIM: 86 - $title = pht('%s commandeered this revision.', 87 - $author_name); 89 + case DifferentialAction::ACTION_REOPEN: 90 + $title = pht('%s reopened this revision.', 91 + $author_name); 88 92 break; 89 - case DifferentialAction::ACTION_REOPEN: 90 - $title = pht('%s reopened this revision.', 91 - $author_name); 93 + case DifferentialTransaction::TYPE_INLINE: 94 + $title = pht( 95 + '%s added an inline comment.', 96 + $author_name); 92 97 break; 93 - case DifferentialTransaction::TYPE_INLINE: 94 - $title = pht( 95 - '%s added an inline comment.', 96 - $author_name); 97 - break; 98 - default: 99 - $title = pht('Ghosts happened to this revision.'); 98 + default: 99 + $title = pht('Ghosts happened to this revision.'); 100 100 break; 101 - } 101 + } 102 102 return $title; 103 103 } 104 104
+94 -6
src/applications/differential/storage/DifferentialTransaction.php
··· 102 102 $new = $this->getNewValue(); 103 103 104 104 switch ($this->getTransactionType()) { 105 + case self::TYPE_ACTION: 106 + if ($new == DifferentialAction::ACTION_CLOSE && 107 + $this->getMetadataValue('isCommitClose')) { 108 + $phids[] = $this->getMetadataValue('commitPHID'); 109 + if ($this->getMetadataValue('committerPHID')) { 110 + $phids[] = $this->getMetadataValue('committerPHID'); 111 + } 112 + if ($this->getMetadataValue('authorPHID')) { 113 + $phids[] = $this->getMetadataValue('authorPHID'); 114 + } 115 + } 116 + break; 105 117 case self::TYPE_UPDATE: 106 118 if ($new) { 107 119 $phids[] = $new; ··· 216 228 '%s added inline comments.', 217 229 $author_handle); 218 230 case self::TYPE_UPDATE: 219 - if ($new) { 231 + if ($this->getMetadataValue('isCommitUpdate')) { 232 + return pht( 233 + 'This revision was automatically updated to reflect the '. 234 + 'committed changes.'); 235 + } else if ($new) { 220 236 // TODO: Migrate to PHIDs and use handles here? 221 237 if (phid_get_type($new) == DifferentialDiffPHIDType::TYPECONST) { 222 238 return pht( ··· 234 250 $author_handle); 235 251 } 236 252 case self::TYPE_ACTION: 237 - return DifferentialAction::getBasicStoryText($new, $author_handle); 253 + switch ($new) { 254 + case DifferentialAction::ACTION_CLOSE: 255 + if (!$this->getMetadataValue('isCommitClose')) { 256 + return DifferentialAction::getBasicStoryText( 257 + $new, 258 + $author_handle); 259 + } 260 + $commit_name = $this->renderHandleLink( 261 + $this->getMetadataValue('commitPHID')); 262 + $committer_phid = $this->getMetadataValue('committerPHID'); 263 + $author_phid = $this->getMetadataValue('authorPHID'); 264 + if ($this->getHandleIfExists($committer_phid)) { 265 + $committer_name = $this->renderHandleLink($committer_phid); 266 + } else { 267 + $committer_name = $this->getMetadataValue('committerName'); 268 + } 269 + if ($this->getHandleIfExists($author_phid)) { 270 + $author_name = $this->renderHandleLink($author_phid); 271 + } else { 272 + $author_name = $this->getMetadataValue('authorName'); 273 + } 274 + 275 + if ($committer_name && ($committer_name != $author_name)) { 276 + return pht( 277 + 'Closed by commit %s (authored by %s, committed by %s).', 278 + $commit_name, 279 + $author_name, 280 + $committer_name); 281 + } else { 282 + return pht( 283 + 'Closed by commit %s (authored by %s).', 284 + $commit_name, 285 + $author_name); 286 + } 287 + break; 288 + default: 289 + return DifferentialAction::getBasicStoryText($new, $author_handle); 290 + } 291 + break; 238 292 case self::TYPE_STATUS: 239 293 switch ($this->getNewValue()) { 240 294 case ArcanistDifferentialRevisionStatus::ACCEPTED: ··· 296 350 $author_link, 297 351 $object_link); 298 352 case DifferentialAction::ACTION_CLOSE: 299 - return pht( 300 - '%s closed %s.', 301 - $author_link, 302 - $object_link); 353 + if (!$this->getMetadataValue('isCommitClose')) { 354 + return pht( 355 + '%s closed %s.', 356 + $author_link, 357 + $object_link); 358 + } else { 359 + $commit_name = $this->renderHandleLink( 360 + $this->getMetadataValue('commitPHID')); 361 + $committer_phid = $this->getMetadataValue('committerPHID'); 362 + $author_phid = $this->getMetadataValue('authorPHID'); 363 + if ($this->getHandleIfExists($committer_phid)) { 364 + $committer_name = $this->renderHandleLink($committer_phid); 365 + } else { 366 + $committer_name = $this->getMetadataValue('committerName'); 367 + } 368 + if ($this->getHandleIfExists($author_phid)) { 369 + $author_name = $this->renderHandleLink($author_phid); 370 + } else { 371 + $author_name = $this->getMetadataValue('authorName'); 372 + } 373 + 374 + if ($committer_name && ($committer_name != $author_name)) { 375 + return pht( 376 + '%s closed %s by commit %s (authored by %s).', 377 + $author_link, 378 + $object_link, 379 + $commit_name, 380 + $author_name); 381 + } else { 382 + return pht( 383 + '%s closed %s by commit %s.', 384 + $author_link, 385 + $object_link, 386 + $commit_name); 387 + } 388 + } 389 + break; 390 + 303 391 case DifferentialAction::ACTION_REQUEST: 304 392 return pht( 305 393 '%s requested review of %s.',
+27 -49
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
··· 140 140 $should_autoclose; 141 141 142 142 if ($should_close) { 143 - $commit_name = $repository->formatCommitName( 144 - $commit->getCommitIdentifier()); 143 + $commit_close_xaction = id(new DifferentialTransaction()) 144 + ->setTransactionType(DifferentialTransaction::TYPE_ACTION) 145 + ->setNewValue(DifferentialAction::ACTION_CLOSE) 146 + ->setMetadataValue('isCommitClose', true); 145 147 146 - $committer_name = $this->loadUserName( 147 - $committer_phid, 148 - $data->getCommitDetail('committer'), 149 - $actor); 150 - 151 - $author_name = $this->loadUserName( 152 - $author_phid, 153 - $data->getAuthorName(), 154 - $actor); 155 - 156 - if ($committer_name && ($committer_name != $author_name)) { 157 - $revision_update_comment = pht( 158 - 'Closed by commit %s (authored by %s, committed by %s).', 159 - $commit_name, 160 - $author_name, 161 - $committer_name); 162 - } else { 163 - $revision_update_comment = pht( 164 - 'Closed by commit %s (authored by %s).', 165 - $commit_name, 166 - $author_name); 167 - } 148 + $commit_close_xaction->setMetadataValue( 149 + 'commitPHID', 150 + $commit->getPHID()); 151 + $commit_close_xaction->setMetadataValue( 152 + 'committerPHID', 153 + $committer_phid); 154 + $commit_close_xaction->setMetadataValue( 155 + 'committerName', 156 + $data->getCommitDetail('committer')); 157 + $commit_close_xaction->setMetadataValue( 158 + 'authorPHID', 159 + $author_phid); 160 + $commit_close_xaction->setMetadataValue( 161 + 'authorName', 162 + $data->getAuthorName()); 163 + $commit_close_xaction->setMetadataValue( 164 + 'commitHashes', 165 + $hashes); 168 166 169 167 $diff = $this->generateFinalDiff($revision, $acting_as_phid); 170 168 ··· 181 179 } 182 180 183 181 $xactions = array(); 184 - 185 - $xactions[] = id(new DifferentialTransaction()) 186 - ->setTransactionType(DifferentialTransaction::TYPE_ACTION) 187 - ->setNewValue(DifferentialAction::ACTION_CLOSE); 188 - 189 182 $xactions[] = id(new DifferentialTransaction()) 190 183 ->setTransactionType(DifferentialTransaction::TYPE_UPDATE) 191 184 ->setIgnoreOnNoEffect(true) 192 - ->setNewValue($diff->getPHID()); 193 - 194 - $xactions[] = id(new DifferentialTransaction()) 195 - ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 196 - ->setIgnoreOnNoEffect(true) 197 - ->attachComment( 198 - id(new DifferentialTransactionComment()) 199 - ->setContent($revision_update_comment)); 185 + ->setNewValue($diff->getPHID()) 186 + ->setMetadataValue('isCommitUpdate', true); 187 + $xactions[] = $commit_close_xaction; 200 188 201 189 $content_source = PhabricatorContentSource::newForSource( 202 190 PhabricatorContentSource::SOURCE_DAEMON, ··· 235 223 236 224 $commit->writeImportStatusFlag( 237 225 PhabricatorRepositoryCommit::IMPORTED_MESSAGE); 238 - } 239 - 240 - private function loadUserName($user_phid, $default, PhabricatorUser $actor) { 241 - if (!$user_phid) { 242 - return $default; 243 - } 244 - $handle = id(new PhabricatorHandleQuery()) 245 - ->setViewer($actor) 246 - ->withPHIDs(array($user_phid)) 247 - ->executeOne(); 248 - 249 - return '@'.$handle->getName(); 250 226 } 251 227 252 228 private function generateFinalDiff( ··· 521 497 ->setActingAsPHID($acting_as) 522 498 ->setContinueOnNoEffect(true) 523 499 ->setContinueOnMissingFields(true) 500 + ->setUnmentionablePHIDMap( 501 + array($commit->getPHID() => $commit->getPHID())) 524 502 ->setContentSource($content_source); 525 503 526 504 $editor->applyTransactions($task, $xactions);