2011-03-25 05:32:26 +01:00
|
|
|
<?php
|
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
final class HeraldDifferentialRevisionAdapter
|
2015-07-30 21:22:35 +02:00
|
|
|
extends HeraldDifferentialAdapter
|
|
|
|
implements HarbormasterBuildableAdapterInterface {
|
2011-03-25 05:32:26 +01:00
|
|
|
|
|
|
|
protected $revision;
|
|
|
|
|
2011-04-06 05:49:31 +02:00
|
|
|
protected $affectedPackages;
|
|
|
|
protected $changesets;
|
2014-04-14 21:06:26 +02:00
|
|
|
private $haveHunks;
|
2011-04-06 05:49:31 +02:00
|
|
|
|
2015-10-02 15:32:08 +02:00
|
|
|
private $buildRequests = array();
|
2015-07-30 21:22:35 +02:00
|
|
|
|
2013-10-05 00:15:48 +02:00
|
|
|
public function getAdapterApplicationClass() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorDifferentialApplication';
|
2013-08-02 17:55:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-23 00:25:34 +02:00
|
|
|
protected function newObject() {
|
2015-04-22 23:01:32 +02:00
|
|
|
return new DifferentialRevision();
|
|
|
|
}
|
|
|
|
|
2015-07-06 22:15:47 +02:00
|
|
|
protected function initializeNewAdapter() {
|
|
|
|
$this->revision = $this->newObject();
|
|
|
|
}
|
|
|
|
|
2013-10-05 21:55:34 +02:00
|
|
|
public function getObject() {
|
|
|
|
return $this->revision;
|
|
|
|
}
|
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
public function getAdapterContentType() {
|
|
|
|
return 'differential';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAdapterContentName() {
|
|
|
|
return pht('Differential Revisions');
|
|
|
|
}
|
|
|
|
|
2013-12-27 22:16:33 +01:00
|
|
|
public function getAdapterContentDescription() {
|
|
|
|
return pht(
|
|
|
|
"React to revisions being created or updated.\n".
|
|
|
|
"Revision rules can send email, flag revisions, add reviewers, ".
|
|
|
|
"and run build plans.");
|
|
|
|
}
|
|
|
|
|
2013-12-31 01:48:07 +01:00
|
|
|
public function supportsRuleType($rule_type) {
|
|
|
|
switch ($rule_type) {
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
|
|
return true;
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 21:35:33 +02:00
|
|
|
public function getRepetitionOptions() {
|
|
|
|
return array(
|
|
|
|
HeraldRepetitionPolicyConfig::EVERY,
|
|
|
|
HeraldRepetitionPolicyConfig::FIRST,
|
|
|
|
);
|
|
|
|
}
|
2013-08-02 19:25:45 +02:00
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
public static function newLegacyAdapter(
|
2011-04-06 05:49:31 +02:00
|
|
|
DifferentialRevision $revision,
|
|
|
|
DifferentialDiff $diff) {
|
2013-08-02 17:55:13 +02:00
|
|
|
$object = new HeraldDifferentialRevisionAdapter();
|
|
|
|
|
2013-10-05 01:30:43 +02:00
|
|
|
// Reload the revision to pick up relationship information.
|
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->withIDs(array($revision->getID()))
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->needRelationships(true)
|
|
|
|
->needReviewerStatus(true)
|
|
|
|
->executeOne();
|
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
$object->revision = $revision;
|
2015-07-08 21:25:48 +02:00
|
|
|
$object->setDiff($diff);
|
2013-08-02 17:55:13 +02:00
|
|
|
|
|
|
|
return $object;
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeraldName() {
|
|
|
|
return $this->revision->getTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadChangesets() {
|
2011-04-06 05:49:31 +02:00
|
|
|
if ($this->changesets === null) {
|
2015-07-08 21:25:48 +02:00
|
|
|
$this->changesets = $this->getDiff()->loadChangesets();
|
2011-04-06 05:49:31 +02:00
|
|
|
}
|
|
|
|
return $this->changesets;
|
|
|
|
}
|
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
protected function loadChangesetsWithHunks() {
|
2014-04-14 21:06:26 +02:00
|
|
|
$changesets = $this->loadChangesets();
|
|
|
|
|
|
|
|
if ($changesets && !$this->haveHunks) {
|
|
|
|
$this->haveHunks = true;
|
|
|
|
|
|
|
|
id(new DifferentialHunkQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withChangesets($changesets)
|
|
|
|
->needAttachToChangesets(true)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $changesets;
|
|
|
|
}
|
|
|
|
|
2011-04-06 05:49:31 +02:00
|
|
|
public function loadAffectedPackages() {
|
|
|
|
if ($this->affectedPackages === null) {
|
|
|
|
$this->affectedPackages = array();
|
|
|
|
|
|
|
|
$repository = $this->loadRepository();
|
|
|
|
if ($repository) {
|
|
|
|
$packages = PhabricatorOwnersPackage::loadAffectedPackages(
|
|
|
|
$repository,
|
|
|
|
$this->loadAffectedPaths());
|
|
|
|
$this->affectedPackages = $packages;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->affectedPackages;
|
|
|
|
}
|
|
|
|
|
2015-07-08 21:25:48 +02:00
|
|
|
public function loadReviewers() {
|
2015-07-30 20:39:35 +02:00
|
|
|
$reviewers = $this->getObject()->getReviewerStatus();
|
|
|
|
return mpull($reviewers, 'getReviewerPHID');
|
2013-08-02 20:32:50 +02:00
|
|
|
}
|
|
|
|
|
2015-07-30 21:22:35 +02:00
|
|
|
|
|
|
|
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
public function getHarbormasterBuildablePHID() {
|
|
|
|
return $this->getDiff()->getPHID();
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 21:22:35 +02:00
|
|
|
public function getHarbormasterContainerPHID() {
|
|
|
|
return $this->getObject()->getPHID();
|
|
|
|
}
|
|
|
|
|
2015-10-02 15:32:08 +02:00
|
|
|
public function getQueuedHarbormasterBuildRequests() {
|
|
|
|
return $this->buildRequests;
|
2015-07-30 21:22:35 +02:00
|
|
|
}
|
|
|
|
|
2015-10-02 15:32:08 +02:00
|
|
|
public function queueHarbormasterBuildRequest(
|
|
|
|
HarbormasterBuildRequest $request) {
|
|
|
|
$this->buildRequests[] = $request;
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
2014-07-23 02:03:09 +02:00
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|