2012-06-15 02:09:24 +02:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class DifferentialFinishPostponedLintersConduitAPIMethod
|
|
|
|
extends DifferentialConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'differential.finishpostponedlinters';
|
|
|
|
}
|
2012-06-15 02:09:24 +02:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Update diff with new lint messages and mark postponed '.
|
|
|
|
'linters as finished.';
|
2012-06-15 02:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function defineParamTypes() {
|
|
|
|
return array(
|
|
|
|
'diffID' => 'required diffID',
|
|
|
|
'linters' => 'required dict',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'void';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array(
|
|
|
|
'ERR-BAD-DIFF' => 'Bad diff ID.',
|
|
|
|
'ERR-BAD-LINTER' => 'No postponed linter by the given name',
|
|
|
|
'ERR-NO-LINT' => 'No postponed lint field available in diff',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
|
|
|
|
$diff_id = $request->getValue('diffID');
|
|
|
|
$linter_map = $request->getValue('linters');
|
|
|
|
|
2013-07-01 21:38:42 +02:00
|
|
|
$diff = id(new DifferentialDiffQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withIDs(array($diff_id))
|
|
|
|
->executeOne();
|
2012-06-15 02:09:24 +02:00
|
|
|
if (!$diff) {
|
|
|
|
throw new ConduitException('ERR-BAD-DIFF');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the finished linters and messages from the linter map.
|
|
|
|
$finished_linters = array_keys($linter_map);
|
|
|
|
$new_messages = array();
|
|
|
|
foreach ($linter_map as $linter => $messages) {
|
|
|
|
$new_messages = array_merge($new_messages, $messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the postponed linters attached to this diff.
|
|
|
|
$postponed_linters_property = id(
|
|
|
|
new DifferentialDiffProperty())->loadOneWhere(
|
|
|
|
'diffID = %d AND name = %s',
|
|
|
|
$diff_id,
|
|
|
|
'arc:lint-postponed');
|
|
|
|
if ($postponed_linters_property) {
|
|
|
|
$postponed_linters = $postponed_linters_property->getData();
|
|
|
|
} else {
|
|
|
|
$postponed_linters = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($finished_linters as $linter) {
|
|
|
|
if (!in_array($linter, $postponed_linters)) {
|
|
|
|
throw new ConduitException('ERR-BAD-LINTER');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($postponed_linters as $idx => $linter) {
|
|
|
|
if (in_array($linter, $finished_linters)) {
|
|
|
|
unset($postponed_linters[$idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:12:48 +02:00
|
|
|
// Load the lint messages currenty attached to the diff. If this
|
2012-06-15 02:09:24 +02:00
|
|
|
// diff property doesn't exist, create it.
|
|
|
|
$messages_property = id(new DifferentialDiffProperty())->loadOneWhere(
|
|
|
|
'diffID = %d AND name = %s',
|
|
|
|
$diff_id,
|
2013-02-19 22:33:10 +01:00
|
|
|
'arc:lint');
|
2012-06-15 02:09:24 +02:00
|
|
|
if ($messages_property) {
|
|
|
|
$messages = $messages_property->getData();
|
|
|
|
} else {
|
|
|
|
$messages = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add new lint messages, removing duplicates.
|
|
|
|
foreach ($new_messages as $new_message) {
|
|
|
|
if (!in_array($new_message, $messages)) {
|
|
|
|
$messages[] = $new_message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use setdiffproperty to update the postponed linters and messages,
|
|
|
|
// as these will also update the lint status correctly.
|
|
|
|
$call = new ConduitCall(
|
|
|
|
'differential.setdiffproperty',
|
|
|
|
array(
|
|
|
|
'diff_id' => $diff_id,
|
|
|
|
'name' => 'arc:lint',
|
2014-10-07 15:01:04 +02:00
|
|
|
'data' => json_encode($messages),
|
|
|
|
));
|
2012-06-15 02:09:24 +02:00
|
|
|
$call->setUser($request->getUser());
|
|
|
|
$call->execute();
|
|
|
|
$call = new ConduitCall(
|
|
|
|
'differential.setdiffproperty',
|
|
|
|
array(
|
|
|
|
'diff_id' => $diff_id,
|
|
|
|
'name' => 'arc:lint-postponed',
|
2014-10-07 15:01:04 +02:00
|
|
|
'data' => json_encode($postponed_linters),
|
|
|
|
));
|
2012-06-15 02:09:24 +02:00
|
|
|
$call->setUser($request->getUser());
|
|
|
|
$call->execute();
|
|
|
|
}
|
|
|
|
}
|