From 5d6dddc5eb610c89064c7a8160952c74a737832e Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 16 Feb 2021 11:59:18 -0800 Subject: [PATCH] Add more constraints to "harbormaster.target.search" Summary: Ref T13607. Add some time-oriented constraints to this API method to support compiling build statistics. Test Plan: - Called "harbormaster.target.search" with all new constraints. - Viewed documentation in API console. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13607 Differential Revision: https://secure.phabricator.com/D21559 --- .../query/HarbormasterBuildTargetQuery.php | 80 +++++++++++++++++++ .../HarbormasterBuildTargetSearchEngine.php | 58 ++++++++++++++ .../storage/build/HarbormasterBuildTarget.php | 9 +++ 3 files changed, 147 insertions(+) diff --git a/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php b/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php index 6872be835b..54b9c4ee16 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php @@ -7,6 +7,14 @@ final class HarbormasterBuildTargetQuery private $phids; private $buildPHIDs; private $buildGenerations; + private $dateCreatedMin; + private $dateCreatedMax; + private $dateStartedMin; + private $dateStartedMax; + private $dateCompletedMin; + private $dateCompletedMax; + private $statuses; + private $needBuildSteps; public function withIDs(array $ids) { @@ -29,6 +37,29 @@ final class HarbormasterBuildTargetQuery return $this; } + public function withDateCreatedBetween($min, $max) { + $this->dateCreatedMin = $min; + $this->dateCreatedMax = $max; + return $this; + } + + public function withDateStartedBetween($min, $max) { + $this->dateStartedMin = $min; + $this->dateStartedMax = $max; + return $this; + } + + public function withDateCompletedBetween($min, $max) { + $this->dateCompletedMin = $min; + $this->dateCompletedMax = $max; + return $this; + } + + public function withTargetStatuses(array $statuses) { + $this->statuses = $statuses; + return $this; + } + public function needBuildSteps($need_build_steps) { $this->needBuildSteps = $need_build_steps; return $this; @@ -73,6 +104,55 @@ final class HarbormasterBuildTargetQuery $this->buildGenerations); } + if ($this->dateCreatedMin !== null) { + $where[] = qsprintf( + $conn, + 'dateCreated >= %d', + $this->dateCreatedMin); + } + + if ($this->dateCreatedMax !== null) { + $where[] = qsprintf( + $conn, + 'dateCreated <= %d', + $this->dateCreatedMax); + } + + if ($this->dateStartedMin !== null) { + $where[] = qsprintf( + $conn, + 'dateStarted >= %d', + $this->dateStartedMin); + } + + if ($this->dateStartedMax !== null) { + $where[] = qsprintf( + $conn, + 'dateStarted <= %d', + $this->dateStartedMax); + } + + if ($this->dateCompletedMin !== null) { + $where[] = qsprintf( + $conn, + 'dateCompleted >= %d', + $this->dateCompletedMin); + } + + if ($this->dateCompletedMax !== null) { + $where[] = qsprintf( + $conn, + 'dateCompleted <= %d', + $this->dateCompletedMax); + } + + if ($this->statuses !== null) { + $where[] = qsprintf( + $conn, + 'targetStatus IN (%Ls)', + $this->statuses); + } + return $where; } diff --git a/src/applications/harbormaster/query/HarbormasterBuildTargetSearchEngine.php b/src/applications/harbormaster/query/HarbormasterBuildTargetSearchEngine.php index b224808322..db7d6f7c87 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildTargetSearchEngine.php +++ b/src/applications/harbormaster/query/HarbormasterBuildTargetSearchEngine.php @@ -24,6 +24,42 @@ final class HarbormasterBuildTargetSearchEngine ->setDescription( pht('Search for targets of a given build.')) ->setDatasource(new HarbormasterBuildPlanDatasource()), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created After')) + ->setKey('createdStart') + ->setDescription( + pht('Search for targets created on or after a particular date.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created Before')) + ->setKey('createdEnd') + ->setDescription( + pht('Search for targets created on or before a particular date.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Started After')) + ->setKey('startedStart') + ->setDescription( + pht('Search for targets started on or after a particular date.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Started Before')) + ->setKey('startedEnd') + ->setDescription( + pht('Search for targets started on or before a particular date.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Completed After')) + ->setKey('completedStart') + ->setDescription( + pht('Search for targets completed on or after a particular date.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Completed Before')) + ->setKey('completedEnd') + ->setDescription( + pht('Search for targets completed on or before a particular date.')), + id(new PhabricatorSearchStringListField()) + ->setLabel(pht('Statuses')) + ->setKey('statuses') + ->setAliases(array('status')) + ->setDescription( + pht('Search for targets with given statuses.')), ); } @@ -34,6 +70,28 @@ final class HarbormasterBuildTargetSearchEngine $query->withBuildPHIDs($map['buildPHIDs']); } + if ($map['createdStart'] !== null || $map['createdEnd'] !== null) { + $query->withDateCreatedBetween( + $map['createdStart'], + $map['createdEnd']); + } + + if ($map['startedStart'] !== null || $map['startedEnd'] !== null) { + $query->withDateStartedBetween( + $map['startedStart'], + $map['startedEnd']); + } + + if ($map['completedStart'] !== null || $map['completedEnd'] !== null) { + $query->withDateCompletedBetween( + $map['completedStart'], + $map['completedEnd']); + } + + if ($map['statuses']) { + $query->withTargetStatuses($map['statuses']); + } + return $query; } diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php index 30b1bd79e4..fa838288c1 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php @@ -119,6 +119,15 @@ final class HarbormasterBuildTarget 'key_build' => array( 'columns' => array('buildPHID', 'buildStepPHID'), ), + 'key_started' => array( + 'columns' => array('dateStarted'), + ), + 'key_completed' => array( + 'columns' => array('dateCompleted'), + ), + 'key_created' => array( + 'columns' => array('dateCreated'), + ), ), ) + parent::getConfiguration(); }