mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add a "tags" field to Diffusion commit
Summary: - Fixes T4588. - See D8501. - Adds a "Tags" field for Herald commit emails. - Fixes a bug in `tagsquery` when filtering by commit name. - Make `tagsquery` just return nothing instead of fataling against Mercurial/Subversion. Test Plan: Used `bin/repository/reparse.php --herald` to exercise this code. Reviewers: btrahan Reviewed By: btrahan Subscribers: aran, epriestley Maniphest Tasks: T4588 Differential Revision: https://secure.phabricator.com/D8502
This commit is contained in:
parent
611f670720
commit
a4a4322d7a
4 changed files with 60 additions and 7 deletions
|
@ -1283,6 +1283,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorChatLogQuery' => 'applications/chatlog/PhabricatorChatLogQuery.php',
|
||||
'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php',
|
||||
'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php',
|
||||
'PhabricatorCommitTagsField' => 'applications/repository/customfield/PhabricatorCommitTagsField.php',
|
||||
'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php',
|
||||
'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php',
|
||||
'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php',
|
||||
|
@ -3962,6 +3963,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField',
|
||||
'PhabricatorCommitCustomField' => 'PhabricatorCustomField',
|
||||
'PhabricatorCommitTagsField' => 'PhabricatorCommitCustomField',
|
||||
'PhabricatorCommonPasswords' => 'Phobject',
|
||||
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',
|
||||
'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO',
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_diffusion_tagsquery_Method
|
||||
extends ConduitAPI_diffusion_abstractquery_Method {
|
||||
|
||||
|
@ -38,12 +35,14 @@ final class ConduitAPI_diffusion_tagsquery_Method
|
|||
|
||||
$all_tags = $this->loadGitTagList();
|
||||
$all_tags = mpull($all_tags, null, 'getName');
|
||||
|
||||
if ($name_filter !== null) {
|
||||
$all_tags = array_intersect_key($all_tags, array_fuse($name_filter));
|
||||
}
|
||||
if ($commit_filter !== null) {
|
||||
$all_tags = array_intersect_key($all_tags, array_fuse($commit_filter));
|
||||
$all_tags = array_intersect_key($all_tags, $commit_filter);
|
||||
}
|
||||
|
||||
$tags = array_values($all_tags);
|
||||
|
||||
$offset = $request->getValue('offset');
|
||||
|
@ -151,4 +150,14 @@ final class ConduitAPI_diffusion_tagsquery_Method
|
|||
return $tags;
|
||||
}
|
||||
|
||||
protected function getMercurialResult(ConduitAPIRequest $request) {
|
||||
// For now, we don't support Mercurial tags via API.
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function getSVNResult(ConduitAPIRequest $request) {
|
||||
// Subversion has no meaningful concept of tags.
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCommitTagsField
|
||||
extends PhabricatorCommitCustomField {
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'diffusion:tags';
|
||||
}
|
||||
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function buildApplicationTransactionMailBody(
|
||||
PhabricatorApplicationTransaction $xaction,
|
||||
PhabricatorMetaMTAMailBody $body) {
|
||||
|
||||
$params = array(
|
||||
'commit' => $this->getObject()->getCommitIdentifier(),
|
||||
'callsign' => $this->getObject()->getRepository()->getCallsign(),
|
||||
);
|
||||
|
||||
$tags_raw = id(new ConduitCall('diffusion.tagsquery', $params))
|
||||
->setUser($this->getViewer())
|
||||
->execute();
|
||||
|
||||
$tags = DiffusionRepositoryTag::newFromConduit($tags_raw);
|
||||
if (!$tags) {
|
||||
return;
|
||||
}
|
||||
$tag_names = mpull($tags, 'getName');
|
||||
sort($tag_names);
|
||||
|
||||
$body->addTextSection(pht('TAGS'), implode(', ', $tag_names));
|
||||
}
|
||||
|
||||
}
|
|
@ -167,9 +167,14 @@ final class PhabricatorRepositoryCommitHeraldWorker
|
|||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->readFieldsFromStorage($commit);
|
||||
foreach ($field_list->getFields() as $field) {
|
||||
$field->buildApplicationTransactionMailBody(
|
||||
new DifferentialTransaction(), // Bogus object to satisfy typehint.
|
||||
$body);
|
||||
try {
|
||||
$field->buildApplicationTransactionMailBody(
|
||||
new DifferentialTransaction(), // Bogus object to satisfy typehint.
|
||||
$body);
|
||||
} catch (Exception $ex) {
|
||||
// Log the exception and continue.
|
||||
phlog($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$body->addTextSection(pht('DIFFERENTIAL REVISION'), $differential);
|
||||
|
|
Loading…
Reference in a new issue