Differential D12993 Diff 31330 src/applications/repository/customfield/PhabricatorCommitMergedCommitsField.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/customfield/PhabricatorCommitMergedCommitsField.php
- This file was added.
| <?php | |||||
| final class PhabricatorCommitMergedCommitsField | |||||
| extends PhabricatorCommitCustomField { | |||||
| public function getFieldKey() { | |||||
| return 'diffusion:mergedcommits'; | |||||
| } | |||||
| public function shouldDisableByDefault() { | |||||
| return true; | |||||
| } | |||||
| public function shouldAppearInTransactionMail() { | |||||
| return true; | |||||
| } | |||||
| public function updateTransactionMailBody( | |||||
| PhabricatorMetaMTAMailBody $body, | |||||
| PhabricatorApplicationTransactionEditor $editor, | |||||
| array $xactions) { | |||||
| // Get all the merged commits if this commit is a merge | |||||
| $merges_caption = ''; | |||||
| // TODO: Make this limit configurable after T6030 | |||||
| $limit = 50; | |||||
| $commit = $this->getObject(); | |||||
| try { | |||||
| $drequest = DiffusionRequest::newFromDictionary( | |||||
| array( | |||||
| 'user' => PhabricatorUser::getOmnipotentUser(), | |||||
epriestley: This should be the actual viewer -- I think `$this->getViewer()` will work. | |||||
| 'initFromConduit' => false, | |||||
epriestleyUnsubmitted Not Done Inline ActionsI think this is no longer used for anything and has no effect (we determine it automatically in all cases, now). epriestley: I think this is no longer used for anything and has no effect (we determine it automatically in… | |||||
| 'repository' => $commit->getRepository(), | |||||
| 'commit' => $commit->getCommitIdentifier(), | |||||
| )); | |||||
| $merges = DiffusionPathChange::newFromConduit( | |||||
| DiffusionQuery::callConduitWithDiffusionRequest( | |||||
epriestleyUnsubmitted Not Done Inline ActionsUsing ConduitCall directly (as in PhabricatorCommitBranchesField) might be a little simpler than building a DiffusionRequest. epriestley: Using ConduitCall directly (as in `PhabricatorCommitBranchesField`) might be a little simpler… | |||||
| PhabricatorUser::getOmnipotentUser(), | |||||
epriestleyUnsubmitted Not Done Inline ActionsUse real viewer. epriestley: Use real viewer. | |||||
| $drequest, | |||||
| 'diffusion.mergedcommitsquery', | |||||
| array( | |||||
| 'commit' => $commit->getCommitIdentifier(), | |||||
| 'limit' => $limit + 1, | |||||
| ))); | |||||
| if (count($merges) > $limit) { | |||||
| $merges = array_slice($merges, 0, $limit); | |||||
| $merges_caption = | |||||
| "This commit merges more than {$limit} changes. Only the first ". | |||||
| "{$limit} are shown.\n"; | |||||
epriestleyUnsubmitted Not Done Inline ActionsUse pht(). epriestley: Use `pht()`. | |||||
| } | |||||
| if ($merges) { | |||||
| for ($i = 0; $i < count($merges); $i++) { | |||||
| $merges[$i] = $merges[$i]->getAuthorName(). | |||||
| ': '. | |||||
| $merges[$i]->getSummary(); | |||||
| } | |||||
epriestleyUnsubmitted Not Done Inline ActionsMaybe simpler with foreach ($merges as $merge). epriestley: Maybe simpler with `foreach ($merges as $merge)`. | |||||
| $body->addTextSection( | |||||
| pht('MERGED COMMITS'), | |||||
| $merges_caption.implode("\n", $merges)); | |||||
| } | |||||
| } catch (ConduitException $ex) { | |||||
| // Log the exception and continue. | |||||
| phlog($ex); | |||||
epriestleyUnsubmitted Not Done Inline ActionsMaybe put $ex->getMessage() in the mail body? So we end up with something like:
That seems more obvious/helpful than just dumping it to the webserver error log. epriestley: Maybe put $ex->getMessage() in the mail body? So we end up with something like:
> MERGED… | |||||
| } | |||||
| } | |||||
| } | |||||
This should be the actual viewer -- I think $this->getViewer() will work.