mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-10 23:01:04 +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',
|
'PhabricatorChatLogQuery' => 'applications/chatlog/PhabricatorChatLogQuery.php',
|
||||||
'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php',
|
'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php',
|
||||||
'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php',
|
'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php',
|
||||||
|
'PhabricatorCommitTagsField' => 'applications/repository/customfield/PhabricatorCommitTagsField.php',
|
||||||
'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php',
|
'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php',
|
||||||
'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php',
|
'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php',
|
||||||
'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php',
|
'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php',
|
||||||
|
@ -3962,6 +3963,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField',
|
'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField',
|
||||||
'PhabricatorCommitCustomField' => 'PhabricatorCustomField',
|
'PhabricatorCommitCustomField' => 'PhabricatorCustomField',
|
||||||
|
'PhabricatorCommitTagsField' => 'PhabricatorCommitCustomField',
|
||||||
'PhabricatorCommonPasswords' => 'Phobject',
|
'PhabricatorCommonPasswords' => 'Phobject',
|
||||||
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',
|
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',
|
||||||
'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO',
|
'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO',
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group conduit
|
|
||||||
*/
|
|
||||||
final class ConduitAPI_diffusion_tagsquery_Method
|
final class ConduitAPI_diffusion_tagsquery_Method
|
||||||
extends ConduitAPI_diffusion_abstractquery_Method {
|
extends ConduitAPI_diffusion_abstractquery_Method {
|
||||||
|
|
||||||
|
@ -38,12 +35,14 @@ final class ConduitAPI_diffusion_tagsquery_Method
|
||||||
|
|
||||||
$all_tags = $this->loadGitTagList();
|
$all_tags = $this->loadGitTagList();
|
||||||
$all_tags = mpull($all_tags, null, 'getName');
|
$all_tags = mpull($all_tags, null, 'getName');
|
||||||
|
|
||||||
if ($name_filter !== null) {
|
if ($name_filter !== null) {
|
||||||
$all_tags = array_intersect_key($all_tags, array_fuse($name_filter));
|
$all_tags = array_intersect_key($all_tags, array_fuse($name_filter));
|
||||||
}
|
}
|
||||||
if ($commit_filter !== null) {
|
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);
|
$tags = array_values($all_tags);
|
||||||
|
|
||||||
$offset = $request->getValue('offset');
|
$offset = $request->getValue('offset');
|
||||||
|
@ -151,4 +150,14 @@ final class ConduitAPI_diffusion_tagsquery_Method
|
||||||
return $tags;
|
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())
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
->readFieldsFromStorage($commit);
|
->readFieldsFromStorage($commit);
|
||||||
foreach ($field_list->getFields() as $field) {
|
foreach ($field_list->getFields() as $field) {
|
||||||
|
try {
|
||||||
$field->buildApplicationTransactionMailBody(
|
$field->buildApplicationTransactionMailBody(
|
||||||
new DifferentialTransaction(), // Bogus object to satisfy typehint.
|
new DifferentialTransaction(), // Bogus object to satisfy typehint.
|
||||||
$body);
|
$body);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
// Log the exception and continue.
|
||||||
|
phlog($ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$body->addTextSection(pht('DIFFERENTIAL REVISION'), $differential);
|
$body->addTextSection(pht('DIFFERENTIAL REVISION'), $differential);
|
||||||
|
|
Loading…
Reference in a new issue