3 final class HeraldDifferentialRevisionAdapter
4 extends HeraldDifferentialAdapter
5 implements HarbormasterBuildableAdapterInterface
{
9 protected $affectedPackages;
10 protected $changesets;
13 private $buildRequests = array();
15 public function getAdapterApplicationClass() {
16 return 'PhabricatorDifferentialApplication';
19 protected function newObject() {
20 return new DifferentialRevision();
23 public function isTestAdapterForObject($object) {
24 return ($object instanceof DifferentialRevision
);
27 public function getAdapterTestDescription() {
29 'Test rules which run when a revision is created or updated.');
32 public function newTestAdapter(PhabricatorUser
$viewer, $object) {
33 return self
::newLegacyAdapter(
35 $object->loadActiveDiff());
38 protected function initializeNewAdapter() {
39 $this->revision
= $this->newObject();
42 public function getObject() {
43 return $this->revision
;
46 public function getAdapterContentType() {
47 return 'differential';
50 public function getAdapterContentName() {
51 return pht('Differential Revisions');
54 public function getAdapterContentDescription() {
56 "React to revisions being created or updated.\n".
57 "Revision rules can send email, flag revisions, add reviewers, ".
58 "and run build plans.");
61 public function supportsRuleType($rule_type) {
63 case HeraldRuleTypeConfig
::RULE_TYPE_GLOBAL
:
64 case HeraldRuleTypeConfig
::RULE_TYPE_PERSONAL
:
66 case HeraldRuleTypeConfig
::RULE_TYPE_OBJECT
:
72 public static function newLegacyAdapter(
73 DifferentialRevision
$revision,
74 DifferentialDiff
$diff) {
75 $object = new HeraldDifferentialRevisionAdapter();
77 // Reload the revision to pick up relationship information.
78 $revision = id(new DifferentialRevisionQuery())
79 ->withIDs(array($revision->getID()))
80 ->setViewer(PhabricatorUser
::getOmnipotentUser())
84 $object->revision
= $revision;
85 $object->setDiff($diff);
90 public function getHeraldName() {
91 return $this->revision
->getTitle();
94 protected function loadChangesets() {
95 if ($this->changesets
=== null) {
96 $this->changesets
= $this->getDiff()->loadChangesets();
98 return $this->changesets
;
101 protected function loadChangesetsWithHunks() {
102 $changesets = $this->loadChangesets();
104 if ($changesets && !$this->haveHunks
) {
105 $this->haveHunks
= true;
107 id(new DifferentialHunkQuery())
108 ->setViewer(PhabricatorUser
::getOmnipotentUser())
109 ->withChangesets($changesets)
110 ->needAttachToChangesets(true)
117 public function loadAffectedPackages() {
118 if ($this->affectedPackages
=== null) {
119 $this->affectedPackages
= array();
121 $repository = $this->loadRepository();
123 $packages = PhabricatorOwnersPackage
::loadAffectedPackagesForChangesets(
126 $this->loadChangesets());
127 $this->affectedPackages
= $packages;
130 return $this->affectedPackages
;
133 public function loadReviewers() {
134 return $this->getObject()->getReviewerPHIDs();
138 /* -( HarbormasterBuildableAdapterInterface )------------------------------ */
141 public function getHarbormasterBuildablePHID() {
142 return $this->getDiff()->getPHID();
145 public function getHarbormasterContainerPHID() {
146 return $this->getObject()->getPHID();
149 public function getQueuedHarbormasterBuildRequests() {
150 return $this->buildRequests
;
153 public function queueHarbormasterBuildRequest(
154 HarbormasterBuildRequest
$request) {
155 $this->buildRequests
[] = $request;