1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-04-09 02:48:41 +02:00

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
This commit is contained in:
epriestley 2018-08-01 12:39:56 -07:00
parent d8834377be
commit 06380e8079
3 changed files with 64 additions and 11 deletions

View file

@ -12,6 +12,7 @@ final class PhabricatorRepositoryPushLogQuery
private $pushEventPHIDs; private $pushEventPHIDs;
private $epochMin; private $epochMin;
private $epochMax; private $epochMax;
private $blockingHeraldRulePHIDs;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -54,6 +55,11 @@ final class PhabricatorRepositoryPushLogQuery
return $this; return $this;
} }
public function withBlockingHeraldRulePHIDs(array $phids) {
$this->blockingHeraldRulePHIDs = $phids;
return $this;
}
public function newResultObject() { public function newResultObject() {
return new PhabricatorRepositoryPushLog(); return new PhabricatorRepositoryPushLog();
} }
@ -89,71 +95,105 @@ final class PhabricatorRepositoryPushLogQuery
if ($this->ids !== null) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'id IN (%Ld)', 'log.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids !== null) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'phid IN (%Ls)', 'log.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->repositoryPHIDs !== null) { if ($this->repositoryPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'repositoryPHID IN (%Ls)', 'log.repositoryPHID IN (%Ls)',
$this->repositoryPHIDs); $this->repositoryPHIDs);
} }
if ($this->pusherPHIDs !== null) { if ($this->pusherPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'pusherPHID in (%Ls)', 'log.pusherPHID in (%Ls)',
$this->pusherPHIDs); $this->pusherPHIDs);
} }
if ($this->pushEventPHIDs !== null) { if ($this->pushEventPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'pushEventPHID in (%Ls)', 'log.pushEventPHID in (%Ls)',
$this->pushEventPHIDs); $this->pushEventPHIDs);
} }
if ($this->refTypes !== null) { if ($this->refTypes !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'refType IN (%Ls)', 'log.refType IN (%Ls)',
$this->refTypes); $this->refTypes);
} }
if ($this->newRefs !== null) { if ($this->newRefs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'refNew IN (%Ls)', 'log.refNew IN (%Ls)',
$this->newRefs); $this->newRefs);
} }
if ($this->epochMin !== null) { if ($this->epochMin !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'epoch >= %d', 'log.epoch >= %d',
$this->epochMin); $this->epochMin);
} }
if ($this->epochMax !== null) { if ($this->epochMax !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'epoch <= %d', 'log.epoch <= %d',
$this->epochMax); $this->epochMax);
} }
if ($this->blockingHeraldRulePHIDs !== null) {
$where[] = qsprintf(
$conn,
'(event.rejectCode = %d AND event.rejectDetails IN (%Ls))',
PhabricatorRepositoryPushLog::REJECT_HERALD,
$this->blockingHeraldRulePHIDs);
}
return $where; 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() { public function getQueryApplicationClass() {
return 'PhabricatorDiffusionApplication'; return 'PhabricatorDiffusionApplication';
} }
protected function getPrimaryTableAlias() {
return 'log';
}
} }

View file

@ -32,6 +32,10 @@ final class PhabricatorRepositoryPushLogSearchEngine
$map['createdEnd']); $map['createdEnd']);
} }
if ($map['blockingHeraldRulePHIDs']) {
$query->withBlockingHeraldRulePHIDs($map['blockingHeraldRulePHIDs']);
}
return $query; return $query;
} }
@ -43,13 +47,19 @@ final class PhabricatorRepositoryPushLogSearchEngine
->setAliases(array('repository', 'repositories', 'repositoryPHID')) ->setAliases(array('repository', 'repositories', 'repositoryPHID'))
->setLabel(pht('Repositories')) ->setLabel(pht('Repositories'))
->setDescription( ->setDescription(
pht('Search for pull logs for specific repositories.')), pht('Search for push logs for specific repositories.')),
id(new PhabricatorUsersSearchField()) id(new PhabricatorUsersSearchField())
->setKey('pusherPHIDs') ->setKey('pusherPHIDs')
->setAliases(array('pusher', 'pushers', 'pusherPHID')) ->setAliases(array('pusher', 'pushers', 'pusherPHID'))
->setLabel(pht('Pushers')) ->setLabel(pht('Pushers'))
->setDescription( ->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()) id(new PhabricatorSearchDateField())
->setLabel(pht('Created After')) ->setLabel(pht('Created After'))
->setKey('createdStart'), ->setKey('createdStart'),

View file

@ -49,6 +49,9 @@ final class PhabricatorRepositoryPushEvent
'key_identifier' => array( 'key_identifier' => array(
'columns' => array('requestIdentifier'), 'columns' => array('requestIdentifier'),
), ),
'key_reject' => array(
'columns' => array('rejectCode', 'rejectDetails'),
),
), ),
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }