Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php
12256 views
1
<?php
2
3
final class HeraldDifferentialRevisionAdapter
4
extends HeraldDifferentialAdapter
5
implements HarbormasterBuildableAdapterInterface {
6
7
protected $revision;
8
9
protected $affectedPackages;
10
protected $changesets;
11
private $haveHunks;
12
13
private $buildRequests = array();
14
15
public function getAdapterApplicationClass() {
16
return 'PhabricatorDifferentialApplication';
17
}
18
19
protected function newObject() {
20
return new DifferentialRevision();
21
}
22
23
public function isTestAdapterForObject($object) {
24
return ($object instanceof DifferentialRevision);
25
}
26
27
public function getAdapterTestDescription() {
28
return pht(
29
'Test rules which run when a revision is created or updated.');
30
}
31
32
public function newTestAdapter(PhabricatorUser $viewer, $object) {
33
return self::newLegacyAdapter(
34
$object,
35
$object->loadActiveDiff());
36
}
37
38
protected function initializeNewAdapter() {
39
$this->revision = $this->newObject();
40
}
41
42
public function getObject() {
43
return $this->revision;
44
}
45
46
public function getAdapterContentType() {
47
return 'differential';
48
}
49
50
public function getAdapterContentName() {
51
return pht('Differential Revisions');
52
}
53
54
public function getAdapterContentDescription() {
55
return pht(
56
"React to revisions being created or updated.\n".
57
"Revision rules can send email, flag revisions, add reviewers, ".
58
"and run build plans.");
59
}
60
61
public function supportsRuleType($rule_type) {
62
switch ($rule_type) {
63
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
64
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
65
return true;
66
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
67
default:
68
return false;
69
}
70
}
71
72
public static function newLegacyAdapter(
73
DifferentialRevision $revision,
74
DifferentialDiff $diff) {
75
$object = new HeraldDifferentialRevisionAdapter();
76
77
// Reload the revision to pick up relationship information.
78
$revision = id(new DifferentialRevisionQuery())
79
->withIDs(array($revision->getID()))
80
->setViewer(PhabricatorUser::getOmnipotentUser())
81
->needReviewers(true)
82
->executeOne();
83
84
$object->revision = $revision;
85
$object->setDiff($diff);
86
87
return $object;
88
}
89
90
public function getHeraldName() {
91
return $this->revision->getTitle();
92
}
93
94
protected function loadChangesets() {
95
if ($this->changesets === null) {
96
$this->changesets = $this->getDiff()->loadChangesets();
97
}
98
return $this->changesets;
99
}
100
101
protected function loadChangesetsWithHunks() {
102
$changesets = $this->loadChangesets();
103
104
if ($changesets && !$this->haveHunks) {
105
$this->haveHunks = true;
106
107
id(new DifferentialHunkQuery())
108
->setViewer(PhabricatorUser::getOmnipotentUser())
109
->withChangesets($changesets)
110
->needAttachToChangesets(true)
111
->execute();
112
}
113
114
return $changesets;
115
}
116
117
public function loadAffectedPackages() {
118
if ($this->affectedPackages === null) {
119
$this->affectedPackages = array();
120
121
$repository = $this->loadRepository();
122
if ($repository) {
123
$packages = PhabricatorOwnersPackage::loadAffectedPackagesForChangesets(
124
$repository,
125
$this->getDiff(),
126
$this->loadChangesets());
127
$this->affectedPackages = $packages;
128
}
129
}
130
return $this->affectedPackages;
131
}
132
133
public function loadReviewers() {
134
return $this->getObject()->getReviewerPHIDs();
135
}
136
137
138
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
139
140
141
public function getHarbormasterBuildablePHID() {
142
return $this->getDiff()->getPHID();
143
}
144
145
public function getHarbormasterContainerPHID() {
146
return $this->getObject()->getPHID();
147
}
148
149
public function getQueuedHarbormasterBuildRequests() {
150
return $this->buildRequests;
151
}
152
153
public function queueHarbormasterBuildRequest(
154
HarbormasterBuildRequest $request) {
155
$this->buildRequests[] = $request;
156
}
157
158
}
159
160