使用Phabricator的开发人员,肯定会使用到Audit功能。
Phabricator + Git
在Audit的官方文档中提到:
If you put Auditors: username1, username2 in your commit message, it will trigger an audit request to those users when you push it to a tracked branch.
然而在实现的使用过程中发现只有提交描述必须以Auditors:….开头的提交相关人员才能收到审核请求,这样写的结果是在查看git log时首先看到的Auditors:flybeta,…..很长的一串,很时不爽。 如下:
git commit -m “Auditors: flybeta, 张三, 李四…. 修改添加逻辑”
经查看Phabricator源代码发现(430行):
phabricator/src/applications/audit/editor/PhabricatorAuditEditor.php
private function createAuditRequestTransactionFromCommitMessage(
PhabricatorRepositoryCommit $commit) {
$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();
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));
}
此处正则匹配时就是以Auditors:….开始截取的,所以只需要修改此处就可以了。