2013-03-15 11:28:43 +00: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 10:54:15 +10:00
|
|
|
final class ReleephRequestConduitAPIMethod extends ReleephConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'releeph.request';
|
|
|
|
}
|
2013-03-15 11:28:43 +00:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2015-05-22 17:27:56 +10:00
|
|
|
return pht('Request a commit or diff to be picked to a branch.');
|
2013-03-15 11:28:43 +00:00
|
|
|
}
|
|
|
|
|
2015-04-12 15:59:07 -07:00
|
|
|
protected function defineParamTypes() {
|
2013-03-15 11:28:43 +00:00
|
|
|
return array(
|
|
|
|
'branchPHID' => 'required string',
|
2014-04-20 11:54:58 -07:00
|
|
|
'things' => 'required list<string>',
|
2013-03-15 11:28:43 +00:00
|
|
|
'fields' => 'dict<string, string>',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-12 15:59:07 -07:00
|
|
|
protected function defineReturnType() {
|
2013-03-15 11:28:43 +00:00
|
|
|
return 'dict<string, wild>';
|
|
|
|
}
|
|
|
|
|
2015-04-12 15:59:07 -07:00
|
|
|
protected function defineErrorTypes() {
|
2013-03-15 11:28:43 +00:00
|
|
|
return array(
|
2015-05-22 17:27:56 +10:00
|
|
|
'ERR_BRANCH' => pht('Unknown Releeph branch.'),
|
|
|
|
'ERR_FIELD_PARSE' => pht('Unable to parse a Releeph field.'),
|
2013-03-15 11:28:43 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
2013-04-08 16:34:21 +01:00
|
|
|
$user = $request->getUser();
|
2014-04-20 11:54:50 -07:00
|
|
|
|
|
|
|
$viewer_handle = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($user->getPHID()))
|
|
|
|
->executeOne();
|
|
|
|
|
2013-03-15 11:28:43 +00:00
|
|
|
$branch_phid = $request->getValue('branchPHID');
|
2014-04-20 11:54:58 -07:00
|
|
|
$releeph_branch = id(new ReleephBranchQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($branch_phid))
|
|
|
|
->executeOne();
|
2013-03-15 11:28:43 +00:00
|
|
|
|
|
|
|
if (!$releeph_branch) {
|
2014-06-09 11:36:49 -07:00
|
|
|
throw id(new ConduitException('ERR_BRANCH'))->setErrorDescription(
|
2015-05-22 17:27:56 +10:00
|
|
|
pht(
|
|
|
|
'No %s found with PHID %s!',
|
|
|
|
'ReleephBranch',
|
|
|
|
$branch_phid));
|
2013-03-15 11:28:43 +00:00
|
|
|
}
|
|
|
|
|
2014-04-20 11:54:58 -07:00
|
|
|
$releeph_project = $releeph_branch->getProduct();
|
2013-03-15 11:28:43 +00:00
|
|
|
|
|
|
|
// Find the requested commit identifiers
|
|
|
|
$requested_commits = array();
|
Add "requestedObjectPHID" to ReleephRequest
Summary:
Ref T3551. Currently, ReleephRequests don't have a direct concept of the //object// being requested. You can request `D123`, but that is just a convenient way to write `rXyyyy`.
When the UI wants to display information about a revision, it deduces it by examining the commit.
This is primarily an attack on T3551, so we don't need to load <commit -> edge -> revision> (in an ad-hoc way) to get revisions. Instead, when you request a revision we keep track of it and can load it directly later.
Later, this will let us do more things: for example, if you request a branch, we can automatically update the commits (as GitHub does), etc. (Repository branches will need PHIDs first, of course.)
This adds and populates the column but doesn't use it yet. The second part of the migration could safely be run while Phabricator is up, although even for Facebook this table is probably quite small.
Test Plan:
- Ran migration.
- Verified existing requests associated sensibly.
- Created a new commit request.
- Created a new revision request.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T3551
Differential Revision: https://secure.phabricator.com/D8822
2014-04-20 11:55:18 -07:00
|
|
|
$requested_object_phids = array();
|
2013-03-15 11:28:43 +00:00
|
|
|
$things = $request->getValue('things');
|
|
|
|
$finder = id(new ReleephCommitFinder())
|
2013-05-14 15:32:19 -07:00
|
|
|
->setUser($user)
|
2013-03-15 11:28:43 +00:00
|
|
|
->setReleephProject($releeph_project);
|
|
|
|
foreach ($things as $thing) {
|
|
|
|
try {
|
|
|
|
$requested_commits[$thing] = $finder->fromPartial($thing);
|
Add "requestedObjectPHID" to ReleephRequest
Summary:
Ref T3551. Currently, ReleephRequests don't have a direct concept of the //object// being requested. You can request `D123`, but that is just a convenient way to write `rXyyyy`.
When the UI wants to display information about a revision, it deduces it by examining the commit.
This is primarily an attack on T3551, so we don't need to load <commit -> edge -> revision> (in an ad-hoc way) to get revisions. Instead, when you request a revision we keep track of it and can load it directly later.
Later, this will let us do more things: for example, if you request a branch, we can automatically update the commits (as GitHub does), etc. (Repository branches will need PHIDs first, of course.)
This adds and populates the column but doesn't use it yet. The second part of the migration could safely be run while Phabricator is up, although even for Facebook this table is probably quite small.
Test Plan:
- Ran migration.
- Verified existing requests associated sensibly.
- Created a new commit request.
- Created a new revision request.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T3551
Differential Revision: https://secure.phabricator.com/D8822
2014-04-20 11:55:18 -07:00
|
|
|
$object_phid = $finder->getRequestedObjectPHID();
|
|
|
|
if (!$object_phid) {
|
|
|
|
$object_phid = $requested_commits[$thing]->getPHID();
|
|
|
|
}
|
|
|
|
$requested_object_phids[$thing] = $object_phid;
|
2013-03-15 11:28:43 +00:00
|
|
|
} catch (ReleephCommitFinderException $ex) {
|
|
|
|
throw id(new ConduitException('ERR_NO_MATCHES'))
|
|
|
|
->setErrorDescription($ex->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2013-09-11 12:27:28 -07:00
|
|
|
$requested_commit_phids = mpull($requested_commits, 'getPHID');
|
2013-03-15 11:28:43 +00:00
|
|
|
|
|
|
|
// Find any existing requests that clash on the commit id, for this branch
|
|
|
|
$existing_releeph_requests = id(new ReleephRequest())->loadAllWhere(
|
|
|
|
'requestCommitPHID IN (%Ls) AND branchID = %d',
|
2013-09-11 12:27:28 -07:00
|
|
|
$requested_commit_phids,
|
2013-03-15 11:28:43 +00:00
|
|
|
$releeph_branch->getID());
|
|
|
|
$existing_releeph_requests = mpull(
|
|
|
|
$existing_releeph_requests,
|
|
|
|
null,
|
|
|
|
'getRequestCommitPHID');
|
|
|
|
|
|
|
|
$selector = $releeph_project->getReleephFieldSelector();
|
|
|
|
$fields = $selector->getFieldSpecifications();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$field
|
|
|
|
->setReleephProject($releeph_project)
|
|
|
|
->setReleephBranch($releeph_branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = array();
|
2013-09-11 12:27:28 -07:00
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs($requested_commit_phids)
|
|
|
|
->execute();
|
2013-03-15 11:28:43 +00:00
|
|
|
foreach ($requested_commits as $thing => $commit) {
|
|
|
|
$phid = $commit->getPHID();
|
|
|
|
$name = id($handles[$phid])->getName();
|
|
|
|
|
|
|
|
$releeph_request = null;
|
|
|
|
|
|
|
|
$existing_releeph_request = idx($existing_releeph_requests, $phid);
|
|
|
|
if ($existing_releeph_request) {
|
|
|
|
$releeph_request = $existing_releeph_request;
|
|
|
|
} else {
|
2013-04-08 16:34:21 +01:00
|
|
|
$releeph_request = id(new ReleephRequest())
|
|
|
|
->setRequestUserPHID($user->getPHID())
|
|
|
|
->setBranchID($releeph_branch->getID())
|
Add "requestedObjectPHID" to ReleephRequest
Summary:
Ref T3551. Currently, ReleephRequests don't have a direct concept of the //object// being requested. You can request `D123`, but that is just a convenient way to write `rXyyyy`.
When the UI wants to display information about a revision, it deduces it by examining the commit.
This is primarily an attack on T3551, so we don't need to load <commit -> edge -> revision> (in an ad-hoc way) to get revisions. Instead, when you request a revision we keep track of it and can load it directly later.
Later, this will let us do more things: for example, if you request a branch, we can automatically update the commits (as GitHub does), etc. (Repository branches will need PHIDs first, of course.)
This adds and populates the column but doesn't use it yet. The second part of the migration could safely be run while Phabricator is up, although even for Facebook this table is probably quite small.
Test Plan:
- Ran migration.
- Verified existing requests associated sensibly.
- Created a new commit request.
- Created a new revision request.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T3551
Differential Revision: https://secure.phabricator.com/D8822
2014-04-20 11:55:18 -07:00
|
|
|
->setInBranch(0)
|
|
|
|
->setRequestedObjectPHID($requested_object_phids[$thing]);
|
2013-04-08 16:34:21 +01:00
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xactions[] = id(new ReleephRequestTransaction())
|
|
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_REQUEST)
|
|
|
|
->setNewValue($commit->getPHID());
|
|
|
|
|
|
|
|
$xactions[] = id(new ReleephRequestTransaction())
|
|
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
|
|
|
|
->setMetadataValue('userPHID', $user->getPHID())
|
|
|
|
->setMetadataValue(
|
|
|
|
'isAuthoritative',
|
|
|
|
$releeph_project->isAuthoritative($user))
|
|
|
|
->setNewValue(ReleephRequest::INTENT_WANT);
|
|
|
|
|
2013-03-15 11:28:43 +00:00
|
|
|
foreach ($fields as $field) {
|
|
|
|
if (!$field->isEditable()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$field->setReleephRequest($releeph_request);
|
|
|
|
try {
|
|
|
|
$field->setValueFromConduitAPIRequest($request);
|
|
|
|
} catch (ReleephFieldParseException $ex) {
|
|
|
|
throw id(new ConduitException('ERR_FIELD_PARSE'))
|
|
|
|
->setErrorDescription($ex->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2013-04-08 16:34:21 +01:00
|
|
|
|
|
|
|
$editor = id(new ReleephRequestTransactionalEditor())
|
|
|
|
->setActor($user)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSource(
|
|
|
|
PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_CONDUIT,
|
|
|
|
array()));
|
|
|
|
|
|
|
|
$editor->applyTransactions($releeph_request, $xactions);
|
2013-03-15 11:28:43 +00:00
|
|
|
}
|
|
|
|
|
2014-04-20 11:54:50 -07:00
|
|
|
$url = PhabricatorEnv::getProductionURI('/Y'.$releeph_request->getID());
|
2013-03-15 11:28:43 +00:00
|
|
|
$results[$thing] = array(
|
|
|
|
'thing' => $thing,
|
|
|
|
'branch' => $releeph_branch->getDisplayNameWithDetail(),
|
|
|
|
'commitName' => $name,
|
|
|
|
'commitID' => $commit->getCommitIdentifier(),
|
|
|
|
'url' => $url,
|
|
|
|
'requestID' => $releeph_request->getID(),
|
2014-04-20 11:54:50 -07:00
|
|
|
'requestor' => $viewer_handle->getName(),
|
2013-03-15 11:28:43 +00:00
|
|
|
'requestTime' => $releeph_request->getDateCreated(),
|
|
|
|
'existing' => $existing_releeph_request !== null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|