From 06380e8079dec5170bcd3ec47e8e6825dad22d72 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 1 Aug 2018 12:39:56 -0700 Subject: [PATCH] Allow push events to be filtered by which Herald rule blocked the push Summary: Depends on D19555. Ref T13164. See PHI765. An install is interested in getting a sense of the impact of a particular blocking rule, which seems reasonable. Support filtering for pushes blocked by a particular rule or set of rules. Test Plan: {F5776385} Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13164 Differential Revision: https://secure.phabricator.com/D19556 --- .../PhabricatorRepositoryPushLogQuery.php | 58 ++++++++++++++++--- ...abricatorRepositoryPushLogSearchEngine.php | 14 ++++- .../PhabricatorRepositoryPushEvent.php | 3 + 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php b/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php index cb097fae2f..d4734f61e6 100644 --- a/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php @@ -12,6 +12,7 @@ final class PhabricatorRepositoryPushLogQuery private $pushEventPHIDs; private $epochMin; private $epochMax; + private $blockingHeraldRulePHIDs; public function withIDs(array $ids) { $this->ids = $ids; @@ -54,6 +55,11 @@ final class PhabricatorRepositoryPushLogQuery return $this; } + public function withBlockingHeraldRulePHIDs(array $phids) { + $this->blockingHeraldRulePHIDs = $phids; + return $this; + } + public function newResultObject() { return new PhabricatorRepositoryPushLog(); } @@ -89,71 +95,105 @@ final class PhabricatorRepositoryPushLogQuery if ($this->ids !== null) { $where[] = qsprintf( $conn, - 'id IN (%Ld)', + 'log.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, - 'phid IN (%Ls)', + 'log.phid IN (%Ls)', $this->phids); } if ($this->repositoryPHIDs !== null) { $where[] = qsprintf( $conn, - 'repositoryPHID IN (%Ls)', + 'log.repositoryPHID IN (%Ls)', $this->repositoryPHIDs); } if ($this->pusherPHIDs !== null) { $where[] = qsprintf( $conn, - 'pusherPHID in (%Ls)', + 'log.pusherPHID in (%Ls)', $this->pusherPHIDs); } if ($this->pushEventPHIDs !== null) { $where[] = qsprintf( $conn, - 'pushEventPHID in (%Ls)', + 'log.pushEventPHID in (%Ls)', $this->pushEventPHIDs); } if ($this->refTypes !== null) { $where[] = qsprintf( $conn, - 'refType IN (%Ls)', + 'log.refType IN (%Ls)', $this->refTypes); } if ($this->newRefs !== null) { $where[] = qsprintf( $conn, - 'refNew IN (%Ls)', + 'log.refNew IN (%Ls)', $this->newRefs); } if ($this->epochMin !== null) { $where[] = qsprintf( $conn, - 'epoch >= %d', + 'log.epoch >= %d', $this->epochMin); } if ($this->epochMax !== null) { $where[] = qsprintf( $conn, - 'epoch <= %d', + 'log.epoch <= %d', $this->epochMax); } + if ($this->blockingHeraldRulePHIDs !== null) { + $where[] = qsprintf( + $conn, + '(event.rejectCode = %d AND event.rejectDetails IN (%Ls))', + PhabricatorRepositoryPushLog::REJECT_HERALD, + $this->blockingHeraldRulePHIDs); + } + return $where; } + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { + $joins = parent::buildJoinClauseParts($conn); + + if ($this->shouldJoinPushEventTable()) { + $joins[] = qsprintf( + $conn, + 'JOIN %T event ON event.phid = log.pushEventPHID', + id(new PhabricatorRepositoryPushEvent())->getTableName()); + } + + return $joins; + } + + private function shouldJoinPushEventTable() { + if ($this->blockingHeraldRulePHIDs !== null) { + return true; + } + + return false; + } + public function getQueryApplicationClass() { return 'PhabricatorDiffusionApplication'; } + protected function getPrimaryTableAlias() { + return 'log'; + } + + } diff --git a/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php b/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php index eb2bc6b45b..87b2e44740 100644 --- a/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php +++ b/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php @@ -32,6 +32,10 @@ final class PhabricatorRepositoryPushLogSearchEngine $map['createdEnd']); } + if ($map['blockingHeraldRulePHIDs']) { + $query->withBlockingHeraldRulePHIDs($map['blockingHeraldRulePHIDs']); + } + return $query; } @@ -43,13 +47,19 @@ final class PhabricatorRepositoryPushLogSearchEngine ->setAliases(array('repository', 'repositories', 'repositoryPHID')) ->setLabel(pht('Repositories')) ->setDescription( - pht('Search for pull logs for specific repositories.')), + pht('Search for push logs for specific repositories.')), id(new PhabricatorUsersSearchField()) ->setKey('pusherPHIDs') ->setAliases(array('pusher', 'pushers', 'pusherPHID')) ->setLabel(pht('Pushers')) ->setDescription( - pht('Search for pull logs by specific users.')), + pht('Search for push logs by specific users.')), + id(new PhabricatorSearchDatasourceField()) + ->setDatasource(new HeraldRuleDatasource()) + ->setKey('blockingHeraldRulePHIDs') + ->setLabel(pht('Blocked By')) + ->setDescription( + pht('Search for pushes blocked by particular Herald rules.')), id(new PhabricatorSearchDateField()) ->setLabel(pht('Created After')) ->setKey('createdStart'), diff --git a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php index e44f99df4d..682b367926 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php +++ b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php @@ -49,6 +49,9 @@ final class PhabricatorRepositoryPushEvent 'key_identifier' => array( 'columns' => array('requestIdentifier'), ), + 'key_reject' => array( + 'columns' => array('rejectCode', 'rejectDetails'), + ), ), ) + parent::getConfiguration(); }