mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Use DifferentialCommitMessageParser and Modular Transactions to implement "Auditors: ..."
Summary: Ref T10978. Updates how we implement "Auditors: ..." in commit messages: - Use the same parsing code as everything else. - (Also: parse package names.) - Use the new transaction code. Also, fix some UI strings. Test Plan: Used `bin/repository reparse --herald <commit>` to re-run this code on commits with various messages (valid Auditors, invalid Auditors, no Auditors). Saw appropriate auditors added in the UI. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10978 Differential Revision: https://secure.phabricator.com/D17262
This commit is contained in:
parent
e16080ce7e
commit
bc41c3f5a5
3 changed files with 32 additions and 20 deletions
|
@ -375,35 +375,26 @@ final class PhabricatorAuditEditor
|
|||
private function createAuditRequestTransactionFromCommitMessage(
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
|
||||
$actor = $this->getActor();
|
||||
$data = $commit->getCommitData();
|
||||
$message = $data->getCommitMessage();
|
||||
|
||||
$matches = null;
|
||||
if (!preg_match('/^Auditors?:\s*(.*)$/im', $message, $matches)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$phids = id(new PhabricatorObjectListQuery())
|
||||
->setViewer($this->getActor())
|
||||
->setAllowPartialResults(true)
|
||||
->setAllowedTypes(
|
||||
array(
|
||||
PhabricatorPeopleUserPHIDType::TYPECONST,
|
||||
PhabricatorProjectProjectPHIDType::TYPECONST,
|
||||
))
|
||||
->setObjectList($matches[1])
|
||||
->execute();
|
||||
$result = DifferentialCommitMessageParser::newStandardParser($actor)
|
||||
->setRaiseMissingFieldErrors(false)
|
||||
->parseFields($message);
|
||||
|
||||
$field_key = DifferentialAuditorsCommitMessageField::FIELDKEY;
|
||||
$phids = idx($result, $field_key, null);
|
||||
if (!$phids) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($phids as $phid) {
|
||||
$this->addAuditReason($phid, pht('Requested by Author'));
|
||||
}
|
||||
return id(new PhabricatorAuditTransaction())
|
||||
->setTransactionType(PhabricatorAuditActionConstants::ADD_AUDITORS)
|
||||
->setNewValue(array_fuse($phids));
|
||||
->setTransactionType(DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue(
|
||||
array(
|
||||
'+' => array_fuse($phids),
|
||||
));
|
||||
}
|
||||
|
||||
protected function sortTransactions(array $xactions) {
|
||||
|
|
|
@ -15,6 +15,7 @@ final class DifferentialAuditorsCommitMessageField
|
|||
array(
|
||||
PhabricatorPeopleUserPHIDType::TYPECONST,
|
||||
PhabricatorProjectProjectPHIDType::TYPECONST,
|
||||
PhabricatorOwnersPackagePHIDType::TYPECONST,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -1588,6 +1588,26 @@ final class PhabricatorUSEnglishTranslation
|
|||
),
|
||||
),
|
||||
|
||||
'%s added %s auditor(s): %s.' => array(
|
||||
array(
|
||||
'%s added an auditor: %3$s.',
|
||||
'%s added auditors: %3$s.',
|
||||
),
|
||||
),
|
||||
|
||||
'%s removed %s auditor(s): %s.' => array(
|
||||
array(
|
||||
'%s removed an auditor: %3$s.',
|
||||
'%s removed auditors: %3$s.',
|
||||
),
|
||||
),
|
||||
|
||||
'%s edited %s auditor(s), removed %s: %s; added %s: %s.' => array(
|
||||
array(
|
||||
'%s edited auditors, removed: %4$s; added: %6$s.',
|
||||
),
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue