Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php
12256 views
1
<?php
2
3
final class DifferentialQueryConduitAPIMethod
4
extends DifferentialConduitAPIMethod {
5
6
public function getAPIMethodName() {
7
return 'differential.query';
8
}
9
10
public function getMethodDescription() {
11
return pht('Query Differential revisions which match certain criteria.');
12
}
13
14
public function getMethodStatus() {
15
return self::METHOD_STATUS_FROZEN;
16
}
17
18
public function getMethodStatusDescription() {
19
return pht(
20
'This method is frozen and will eventually be deprecated. New code '.
21
'should use "differential.revision.search" instead.');
22
}
23
24
protected function defineParamTypes() {
25
$hash_types = ArcanistDifferentialRevisionHash::getTypes();
26
$hash_const = $this->formatStringConstants($hash_types);
27
28
$status_types = DifferentialLegacyQuery::getAllConstants();
29
$status_const = $this->formatStringConstants($status_types);
30
31
$order_types = array(
32
DifferentialRevisionQuery::ORDER_MODIFIED,
33
DifferentialRevisionQuery::ORDER_CREATED,
34
);
35
$order_const = $this->formatStringConstants($order_types);
36
37
return array(
38
'authors' => 'optional list<phid>',
39
'ccs' => 'optional list<phid>',
40
'reviewers' => 'optional list<phid>',
41
'paths' => 'unsupported',
42
'commitHashes' => 'optional list<pair<'.$hash_const.', string>>',
43
'status' => 'optional '.$status_const,
44
'order' => 'optional '.$order_const,
45
'limit' => 'optional uint',
46
'offset' => 'optional uint',
47
'ids' => 'optional list<uint>',
48
'phids' => 'optional list<phid>',
49
'subscribers' => 'optional list<phid>',
50
'responsibleUsers' => 'optional list<phid>',
51
'branches' => 'optional list<string>',
52
);
53
}
54
55
protected function defineReturnType() {
56
return 'list<dict>';
57
}
58
59
protected function defineErrorTypes() {
60
return array(
61
'ERR-INVALID-PARAMETER' => pht('Missing or malformed parameter.'),
62
);
63
}
64
65
protected function execute(ConduitAPIRequest $request) {
66
$authors = $request->getValue('authors');
67
$ccs = $request->getValue('ccs');
68
$reviewers = $request->getValue('reviewers');
69
$status = $request->getValue('status');
70
$order = $request->getValue('order');
71
$path_pairs = $request->getValue('paths');
72
$commit_hashes = $request->getValue('commitHashes');
73
$limit = $request->getValue('limit');
74
$offset = $request->getValue('offset');
75
$ids = $request->getValue('ids');
76
$phids = $request->getValue('phids');
77
$subscribers = $request->getValue('subscribers');
78
$responsible_users = $request->getValue('responsibleUsers');
79
$branches = $request->getValue('branches');
80
81
$query = id(new DifferentialRevisionQuery())
82
->setViewer($request->getUser());
83
84
if ($authors) {
85
$query->withAuthors($authors);
86
}
87
if ($ccs) {
88
$query->withCCs($ccs);
89
}
90
if ($reviewers) {
91
$query->withReviewers($reviewers);
92
}
93
94
if ($path_pairs) {
95
throw new Exception(
96
pht(
97
'Parameter "paths" to Conduit API method "differential.query" is '.
98
'no longer supported. Use the "paths" constraint to '.
99
'"differential.revision.search" instead. See T13639.'));
100
}
101
102
if ($commit_hashes) {
103
$hash_types = ArcanistDifferentialRevisionHash::getTypes();
104
foreach ($commit_hashes as $info) {
105
list($type, $hash) = $info;
106
if (empty($type) ||
107
!in_array($type, $hash_types) ||
108
empty($hash)) {
109
throw new ConduitException('ERR-INVALID-PARAMETER');
110
}
111
}
112
$query->withCommitHashes($commit_hashes);
113
}
114
115
if ($status) {
116
$statuses = DifferentialLegacyQuery::getModernValues($status);
117
if ($statuses) {
118
$query->withStatuses($statuses);
119
}
120
}
121
if ($order) {
122
$query->setOrder($order);
123
}
124
if ($limit) {
125
$query->setLimit($limit);
126
}
127
if ($offset) {
128
$query->setOffset($offset);
129
}
130
if ($ids) {
131
$query->withIDs($ids);
132
}
133
if ($phids) {
134
$query->withPHIDs($phids);
135
}
136
if ($responsible_users) {
137
$query->withResponsibleUsers($responsible_users);
138
}
139
if ($subscribers) {
140
$query->withCCs($subscribers);
141
}
142
if ($branches) {
143
$query->withBranches($branches);
144
}
145
146
$query->needReviewers(true);
147
$query->needCommitPHIDs(true);
148
$query->needDiffIDs(true);
149
$query->needActiveDiffs(true);
150
$query->needHashes(true);
151
152
$revisions = $query->execute();
153
154
$field_data = $this->loadCustomFieldsForRevisions(
155
$request->getUser(),
156
$revisions);
157
158
if ($revisions) {
159
$ccs = id(new PhabricatorSubscribersQuery())
160
->withObjectPHIDs(mpull($revisions, 'getPHID'))
161
->execute();
162
} else {
163
$ccs = array();
164
}
165
166
$results = array();
167
foreach ($revisions as $revision) {
168
$diff = $revision->getActiveDiff();
169
if (!$diff) {
170
continue;
171
}
172
173
$id = $revision->getID();
174
$phid = $revision->getPHID();
175
176
$result = array(
177
'id' => $id,
178
'phid' => $phid,
179
'title' => $revision->getTitle(),
180
'uri' => PhabricatorEnv::getProductionURI('/D'.$id),
181
'dateCreated' => $revision->getDateCreated(),
182
'dateModified' => $revision->getDateModified(),
183
'authorPHID' => $revision->getAuthorPHID(),
184
185
// NOTE: For backward compatibility this is explicitly a string, like
186
// "2", even though the value of the string is an integer. See PHI14.
187
'status' => (string)$revision->getLegacyRevisionStatus(),
188
189
'statusName' => $revision->getStatusDisplayName(),
190
'properties' => $revision->getProperties(),
191
'branch' => $diff->getBranch(),
192
'summary' => $revision->getSummary(),
193
'testPlan' => $revision->getTestPlan(),
194
'lineCount' => $revision->getLineCount(),
195
'activeDiffPHID' => $diff->getPHID(),
196
'diffs' => $revision->getDiffIDs(),
197
'commits' => $revision->getCommitPHIDs(),
198
'reviewers' => $revision->getReviewerPHIDs(),
199
'ccs' => idx($ccs, $phid, array()),
200
'hashes' => $revision->getHashes(),
201
'auxiliary' => idx($field_data, $phid, array()),
202
'repositoryPHID' => $diff->getRepositoryPHID(),
203
);
204
205
// TODO: This is a hacky way to put permissions on this field until we
206
// have first-class support, see T838.
207
if ($revision->getAuthorPHID() == $request->getUser()->getPHID()) {
208
$result['sourcePath'] = $diff->getSourcePath();
209
}
210
211
$results[] = $result;
212
}
213
214
return $results;
215
}
216
217
}
218
219