1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

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
This commit is contained in:
epriestley 2021-02-16 11:59:18 -08:00
parent 9feb7343e6
commit 5d6dddc5eb
3 changed files with 147 additions and 0 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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();
}