1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-28 04:00:17 +01:00
phorge-phorge/src/applications/repository/customfield/PhabricatorCommitBranchesField.php
epriestley bb7f2ea905 Fail gracefully on bad API call when building commit mail
Summary:
Ref T8574. This could fail because the target is disabled (as here), or doesn't have access to the API, or the API request needs to be satisfied by a different host which isn't available.

In any of these cases, just show the failure and continue generating the mail. This field isn't important enough to block the mail, and many of these errors are permanent.

(I'll follow up on T8574 with some more permanent ideas to address this class of issue.)

Test Plan: Faked API call failure, generated mail, saw clean generation of mail with a failure message.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8574

Differential Revision: https://secure.phabricator.com/D13319
2015-06-16 16:06:42 -07:00

53 lines
1.3 KiB
PHP

<?php
final class PhabricatorCommitBranchesField
extends PhabricatorCommitCustomField {
public function getFieldKey() {
return 'diffusion:branches';
}
public function getFieldName() {
return pht('Branches');
}
public function getFieldDescription() {
return pht('Shows branches a commit appears on in email.');
}
public function shouldAppearInTransactionMail() {
return true;
}
public function updateTransactionMailBody(
PhabricatorMetaMTAMailBody $body,
PhabricatorApplicationTransactionEditor $editor,
array $xactions) {
$params = array(
'contains' => $this->getObject()->getCommitIdentifier(),
'callsign' => $this->getObject()->getRepository()->getCallsign(),
);
try {
$branches_raw = id(new ConduitCall('diffusion.branchquery', $params))
->setUser($this->getViewer())
->execute();
$branches = DiffusionRepositoryRef::loadAllFromDictionaries(
$branches_raw);
if (!$branches) {
return;
}
$branch_names = mpull($branches, 'getShortName');
sort($branch_names);
$branch_text = implode(', ', $branch_names);
} catch (Exception $ex) {
$branch_text = pht('<%s: %s>', get_class($ex), $ex->getMessage());
}
$body->addTextSection(pht('BRANCHES'), $branch_text);
}
}