Page MenuHomestyx hydra

No OneTemporary

diff --git a/resources/sql/autopatches/20140420.rel.1.objectphid.sql b/resources/sql/autopatches/20140420.rel.1.objectphid.sql
new file mode 100644
index 0000000000..397b988d92
--- /dev/null
+++ b/resources/sql/autopatches/20140420.rel.1.objectphid.sql
@@ -0,0 +1,5 @@
+ALTER TABLE {$NAMESPACE}_releeph.releeph_request
+ ADD COLUMN requestedObjectPHID VARCHAR(64) COLLATE utf8_bin NOT NULL;
+
+ALTER TABLE {$NAMESPACE}_releeph.releeph_request
+ ADD KEY `key_requestedObject` (requestedObjectPHID);
diff --git a/resources/sql/autopatches/20140420.rel.2.objectmig.php b/resources/sql/autopatches/20140420.rel.2.objectmig.php
new file mode 100644
index 0000000000..04263a38ab
--- /dev/null
+++ b/resources/sql/autopatches/20140420.rel.2.objectmig.php
@@ -0,0 +1,45 @@
+<?php
+
+$pull_table = new ReleephRequest();
+$table_name = $pull_table->getTableName();
+$conn_w = $pull_table->establishConnection('w');
+
+echo "Setting object PHIDs for requests...\n";
+foreach (new LiskMigrationIterator($pull_table) as $pull) {
+ $id = $pull->getID();
+
+ echo "Migrating pull request {$id}...\n";
+ if ($pull->getRequestedObjectPHID()) {
+ // We already have a valid PHID, so skip this request.
+ continue;
+ }
+
+ $commit_phids = $pull->getCommitPHIDs();
+ if (count($commit_phids) != 1) {
+ // At the time this migration was written, all requests had exactly one
+ // commit. If a request has more than one, we don't have the information
+ // we need to process it.
+ continue;
+ }
+
+ $commit_phid = head($commit_phids);
+
+ $revision_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
+ $commit_phid,
+ PhabricatorEdgeConfig::TYPE_COMMIT_HAS_DREV);
+
+ if ($revision_phids) {
+ $object_phid = head($revision_phids);
+ } else {
+ $object_phid = $commit_phid;
+ }
+
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET requestedObjectPHID = %s WHERE id = %d',
+ $table_name,
+ $object_phid,
+ $id);
+}
+
+echo "Done.\n";
diff --git a/src/applications/releeph/commitfinder/ReleephCommitFinder.php b/src/applications/releeph/commitfinder/ReleephCommitFinder.php
index 1c7bfce23a..e1d569d92f 100644
--- a/src/applications/releeph/commitfinder/ReleephCommitFinder.php
+++ b/src/applications/releeph/commitfinder/ReleephCommitFinder.php
@@ -1,85 +1,105 @@
<?php
final class ReleephCommitFinder {
private $releephProject;
private $user;
+ private $objectPHID;
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function getUser() {
return $this->user;
}
public function setReleephProject(ReleephProject $rp) {
$this->releephProject = $rp;
return $this;
}
+ public function getRequestedObjectPHID() {
+ return $this->objectPHID;
+ }
+
public function fromPartial($partial_string) {
+ $this->objectPHID = null;
+
// Look for diffs
$matches = array();
if (preg_match('/^D([1-9]\d*)$/', $partial_string, $matches)) {
$diff_id = $matches[1];
// TOOD: (T603) This is all slated for annihilation.
$diff_rev = id(new DifferentialRevision())->load($diff_id);
if (!$diff_rev) {
throw new ReleephCommitFinderException(
"{$partial_string} does not refer to an existing diff.");
}
$commit_phids = $diff_rev->loadCommitPHIDs();
if (!$commit_phids) {
throw new ReleephCommitFinderException(
"{$partial_string} has no commits associated with it yet.");
}
+ $this->objectPHID = $diff_rev->getPHID();
+
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
'phid IN (%Ls) ORDER BY epoch ASC',
$commit_phids);
return head($commits);
}
// Look for a raw commit number, or r<callsign><commit-number>.
- $repository = $this->releephProject->loadPhabricatorRepository();
+ $repository = $this->releephProject->getRepository();
$dr_data = null;
$matches = array();
if (preg_match('/^r(?P<callsign>[A-Z]+)(?P<commit>\w+)$/',
$partial_string, $matches)) {
$callsign = $matches['callsign'];
if ($callsign != $repository->getCallsign()) {
throw new ReleephCommitFinderException(sprintf(
"%s is in a different repository to this Releeph project (%s).",
$partial_string,
$repository->getCallsign()));
} else {
$dr_data = $matches;
}
} else {
$dr_data = array(
'callsign' => $repository->getCallsign(),
'commit' => $partial_string
);
}
try {
$dr_data['user'] = $this->getUser();
$dr = DiffusionRequest::newFromDictionary($dr_data);
} catch (Exception $ex) {
$message = "No commit matches {$partial_string}: ".$ex->getMessage();
throw new ReleephCommitFinderException($message);
}
$phabricator_repository_commit = $dr->loadCommit();
if (!$phabricator_repository_commit) {
throw new ReleephCommitFinderException(
"The commit {$partial_string} doesn't exist in this repository.");
}
+ // When requesting a single commit, if it has an associated review we
+ // imply the review was requested instead. This is always correct for now
+ // and consistent with the older behavior, although it might not be the
+ // right rule in the future.
+ $phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
+ $phabricator_repository_commit->getPHID(),
+ PhabricatorEdgeConfig::TYPE_COMMIT_HAS_DREV);
+ if ($phids) {
+ $this->objectPHID = head($phids);
+ }
+
return $phabricator_repository_commit;
}
}
diff --git a/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php b/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php
index 762b4a4c9f..88ae176c79 100644
--- a/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php
+++ b/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php
@@ -1,159 +1,166 @@
<?php
final class ConduitAPI_releeph_request_Method
extends ConduitAPI_releeph_Method {
public function getMethodDescription() {
return "Request a commit or diff to be picked to a branch.";
}
public function defineParamTypes() {
return array(
'branchPHID' => 'required string',
'things' => 'required list<string>',
'fields' => 'dict<string, string>',
);
}
public function defineReturnType() {
return 'dict<string, wild>';
}
public function defineErrorTypes() {
return array(
"ERR_BRANCH" => 'Unknown Releeph branch.',
"ERR_FIELD_PARSE" => 'Unable to parse a Releeph field.',
);
}
protected function execute(ConduitAPIRequest $request) {
$user = $request->getUser();
$viewer_handle = id(new PhabricatorHandleQuery())
->setViewer($user)
->withPHIDs(array($user->getPHID()))
->executeOne();
$branch_phid = $request->getValue('branchPHID');
$releeph_branch = id(new ReleephBranchQuery())
->setViewer($user)
->withPHIDs(array($branch_phid))
->executeOne();
if (!$releeph_branch) {
throw id(new ConduitException("ERR_BRANCH"))->setErrorDescription(
"No ReleephBranch found with PHID {$branch_phid}!");
}
$releeph_project = $releeph_branch->getProduct();
// Find the requested commit identifiers
$requested_commits = array();
+ $requested_object_phids = array();
$things = $request->getValue('things');
$finder = id(new ReleephCommitFinder())
->setUser($user)
->setReleephProject($releeph_project);
foreach ($things as $thing) {
try {
$requested_commits[$thing] = $finder->fromPartial($thing);
+ $object_phid = $finder->getRequestedObjectPHID();
+ if (!$object_phid) {
+ $object_phid = $requested_commits[$thing]->getPHID();
+ }
+ $requested_object_phids[$thing] = $object_phid;
} catch (ReleephCommitFinderException $ex) {
throw id(new ConduitException('ERR_NO_MATCHES'))
->setErrorDescription($ex->getMessage());
}
}
$requested_commit_phids = mpull($requested_commits, 'getPHID');
// 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',
$requested_commit_phids,
$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();
$handles = id(new PhabricatorHandleQuery())
->setViewer($user)
->withPHIDs($requested_commit_phids)
->execute();
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 {
$releeph_request = id(new ReleephRequest())
->setRequestUserPHID($user->getPHID())
->setBranchID($releeph_branch->getID())
- ->setInBranch(0);
+ ->setInBranch(0)
+ ->setRequestedObjectPHID($requested_object_phids[$thing]);
$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);
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());
}
}
$editor = id(new ReleephRequestTransactionalEditor())
->setActor($user)
->setContinueOnNoEffect(true)
->setContentSource(
PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_CONDUIT,
array()));
$editor->applyTransactions($releeph_request, $xactions);
}
$url = PhabricatorEnv::getProductionURI('/Y'.$releeph_request->getID());
$results[$thing] = array(
'thing' => $thing,
'branch' => $releeph_branch->getDisplayNameWithDetail(),
'commitName' => $name,
'commitID' => $commit->getCommitIdentifier(),
'url' => $url,
'requestID' => $releeph_request->getID(),
'requestor' => $viewer_handle->getName(),
'requestTime' => $releeph_request->getDateCreated(),
'existing' => $existing_releeph_request !== null,
);
}
return $results;
}
}
diff --git a/src/applications/releeph/controller/request/ReleephRequestEditController.php b/src/applications/releeph/controller/request/ReleephRequestEditController.php
index 3784885a92..b87e48794f 100644
--- a/src/applications/releeph/controller/request/ReleephRequestEditController.php
+++ b/src/applications/releeph/controller/request/ReleephRequestEditController.php
@@ -1,312 +1,322 @@
<?php
final class ReleephRequestEditController extends ReleephBranchController {
private $requestID;
private $branchID;
public function willProcessRequest(array $data) {
$this->requestID = idx($data, 'requestID');
$this->branchID = idx($data, 'branchID');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
if ($this->requestID) {
$pull = id(new ReleephRequestQuery())
->setViewer($viewer)
->withIDs(array($this->requestID))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$pull) {
return new Aphront404Response();
}
$branch = $pull->getBranch();
$is_edit = true;
} else {
$branch = id(new ReleephBranchQuery())
->setViewer($viewer)
->withIDs(array($this->branchID))
->executeOne();
if (!$branch) {
return new Aphront404Response();
}
$pull = id(new ReleephRequest())
->setRequestUserPHID($viewer->getPHID())
->setBranchID($branch->getID())
- ->setInBranch(0);
+ ->setInBranch(0)
+ ->attachBranch($branch);
$is_edit = false;
}
$this->setBranch($branch);
$product = $branch->getProduct();
$request_identifier = $request->getStr('requestIdentifierRaw');
$e_request_identifier = true;
// Load all the ReleephFieldSpecifications
$selector = $branch->getProduct()->getReleephFieldSelector();
$fields = $selector->getFieldSpecifications();
foreach ($fields as $field) {
$field
->setReleephProject($product)
->setReleephBranch($branch)
->setReleephRequest($pull);
}
$field_list = PhabricatorCustomField::getObjectFields(
$pull,
PhabricatorCustomField::ROLE_EDIT);
foreach ($field_list->getFields() as $field) {
$field
->setReleephProject($product)
->setReleephBranch($branch)
->setReleephRequest($pull);
}
$field_list->readFieldsFromStorage($pull);
if ($this->branchID) {
$cancel_uri = $this->getApplicationURI('branch/'.$this->branchID.'/');
} else {
$cancel_uri = '/'.$pull->getMonogram();
}
// Make edits
$errors = array();
if ($request->isFormPost()) {
$xactions = array();
// The commit-identifier being requested...
if (!$is_edit) {
if ($request_identifier ===
ReleephRequestTypeaheadControl::PLACEHOLDER) {
$errors[] = "No commit ID was provided.";
$e_request_identifier = 'Required';
} else {
$pr_commit = null;
$finder = id(new ReleephCommitFinder())
->setUser($viewer)
->setReleephProject($product);
try {
$pr_commit = $finder->fromPartial($request_identifier);
} catch (Exception $e) {
$e_request_identifier = 'Invalid';
$errors[] =
"Request {$request_identifier} is probably not a valid commit";
$errors[] = $e->getMessage();
}
$pr_commit_data = null;
if (!$errors) {
$pr_commit_data = $pr_commit->loadCommitData();
if (!$pr_commit_data) {
$e_request_identifier = 'Not parsed yet';
$errors[] = "The requested commit hasn't been parsed yet.";
}
}
+
+ if (!$errors) {
+ $object_phid = $finder->getRequestedObjectPHID();
+ if (!$object_phid) {
+ $object_phid = $pr_commit->getPHID();
+ }
+
+ $pull->setRequestedObjectPHID($object_phid);
+ }
}
if (!$errors) {
$existing = id(new ReleephRequest())
->loadOneWhere('requestCommitPHID = %s AND branchID = %d',
$pr_commit->getPHID(), $branch->getID());
if ($existing) {
return id(new AphrontRedirectResponse())
->setURI('/releeph/request/edit/'.$existing->getID().
'?existing=1');
}
$xactions[] = id(new ReleephRequestTransaction())
->setTransactionType(ReleephRequestTransaction::TYPE_REQUEST)
->setNewValue($pr_commit->getPHID());
$xactions[] = id(new ReleephRequestTransaction())
->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
// To help hide these implicit intents...
->setMetadataValue('isRQCreate', true)
->setMetadataValue('userPHID', $viewer->getPHID())
->setMetadataValue(
'isAuthoritative',
$product->isAuthoritative($viewer))
->setNewValue(ReleephRequest::INTENT_WANT);
}
}
// TODO: This should happen implicitly while building transactions
// instead.
foreach ($field_list->getFields() as $field) {
$field->readValueFromRequest($request);
}
if (!$errors) {
foreach ($fields as $field) {
if ($field->isEditable()) {
try {
$data = $request->getRequestData();
$value = idx($data, $field->getRequiredStorageKey());
$field->validate($value);
$xactions[] = id(new ReleephRequestTransaction())
->setTransactionType(ReleephRequestTransaction::TYPE_EDIT_FIELD)
->setMetadataValue('fieldClass', get_class($field))
->setNewValue($value);
} catch (ReleephFieldParseException $ex) {
$errors[] = $ex->getMessage();
}
}
}
}
if (!$errors) {
$editor = id(new ReleephRequestTransactionalEditor())
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request);
$editor->applyTransactions($pull, $xactions);
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
}
}
$handle_phids = array(
$pull->getRequestUserPHID(),
$pull->getRequestCommitPHID(),
);
$handle_phids = array_filter($handle_phids);
if ($handle_phids) {
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($handle_phids)
->execute();
} else {
$handles = array();
}
$age_string = '';
if ($is_edit) {
$age_string = phabricator_format_relative_time(
time() - $pull->getDateCreated()) . ' ago';
}
// Warn the user if we've been redirected here because we tried to
// re-request something.
$notice_view = null;
if ($request->getInt('existing')) {
$notice_messages = array(
'You are editing an existing pick request!',
hsprintf(
"Requested %s by %s",
$age_string,
$handles[$pull->getRequestUserPHID()]->renderLink())
);
$notice_view = id(new AphrontErrorView())
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
->setErrors($notice_messages);
}
$form = id(new AphrontFormView())
->setUser($viewer);
if ($is_edit) {
$form
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Original Commit')
->setValue(
$handles[$pull->getRequestCommitPHID()]->renderLink()))
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Requestor')
->setValue(hsprintf(
'%s %s',
$handles[$pull->getRequestUserPHID()]->renderLink(),
$age_string)));
} else {
$origin = null;
$diff_rev_id = $request->getStr('D');
if ($diff_rev_id) {
$diff_rev = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withIDs(array($diff_rev_id))
->executeOne();
$origin = '/D'.$diff_rev->getID();
$title = sprintf(
'D%d: %s',
$diff_rev_id,
$diff_rev->getTitle());
$form
->addHiddenInput('requestIdentifierRaw', 'D'.$diff_rev_id)
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Diff')
->setValue($title));
} else {
$origin = $branch->getURI();
$repo = $product->getRepository();
$branch_cut_point = id(new PhabricatorRepositoryCommit())
->loadOneWhere(
'phid = %s',
$branch->getCutPointCommitPHID());
$form->appendChild(
id(new ReleephRequestTypeaheadControl())
->setName('requestIdentifierRaw')
->setLabel('Commit ID')
->setRepo($repo)
->setValue($request_identifier)
->setError($e_request_identifier)
->setStartTime($branch_cut_point->getEpoch())
->setCaption(
'Start typing to autocomplete on commit title, '.
'or give a Phabricator commit identifier like rFOO1234'));
}
}
$field_list->appendFieldsToForm($form);
$crumbs = $this->buildApplicationCrumbs();
if ($is_edit) {
$title = pht('Edit Pull Request');
$submit_name = pht('Save');
$crumbs->addTextCrumb($pull->getMonogram(), '/'.$pull->getMonogram());
$crumbs->addTextCrumb(pht('Edit'));
} else {
$title = pht('Create Pull Request');
$submit_name = pht('Create Pull Request');
$crumbs->addTextCrumb(pht('New Pull Request'));
}
$form->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri, 'Cancel')
->setValue($submit_name));
$box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->appendChild($form);
return $this->buildApplicationPage(
array(
$crumbs,
$notice_view,
$box,
),
array(
'title' => $title,
'device' => true,
));
}
}
diff --git a/src/applications/releeph/storage/ReleephRequest.php b/src/applications/releeph/storage/ReleephRequest.php
index 3c5af69850..4ff2af1ae7 100644
--- a/src/applications/releeph/storage/ReleephRequest.php
+++ b/src/applications/releeph/storage/ReleephRequest.php
@@ -1,313 +1,335 @@
<?php
final class ReleephRequest extends ReleephDAO
implements
PhabricatorPolicyInterface,
PhabricatorCustomFieldInterface {
protected $branchID;
protected $requestUserPHID;
protected $details = array();
protected $userIntents = array();
protected $inBranch;
protected $pickStatus;
protected $mailKey;
+ /**
+ * The object which is being requested. Normally this is a commit, but it
+ * might also be a revision. In the future, it could be a repository branch
+ * or an external object (like a GitHub pull request).
+ */
+ protected $requestedObjectPHID;
+
// Information about the thing being requested
protected $requestCommitPHID;
// Information about the last commit to the releeph branch
protected $commitIdentifier;
protected $commitPHID;
+
private $customFields = self::ATTACHABLE;
private $branch = self::ATTACHABLE;
/* -( Constants and helper methods )--------------------------------------- */
const INTENT_WANT = 'want';
const INTENT_PASS = 'pass';
const PICK_PENDING = 1; // old
const PICK_FAILED = 2;
const PICK_OK = 3;
const PICK_MANUAL = 4; // old
const REVERT_OK = 5;
const REVERT_FAILED = 6;
public function shouldBeInBranch() {
return
$this->getPusherIntent() == self::INTENT_WANT &&
/**
* We use "!= pass" instead of "== want" in case the requestor intent is
* not present. In other words, only revert if the requestor explicitly
* passed.
*/
$this->getRequestorIntent() != self::INTENT_PASS;
}
/**
* Will return INTENT_WANT if any pusher wants this request, and no pusher
* passes on this request.
*/
public function getPusherIntent() {
$product = $this->getBranch()->getProduct();
if (!$product->getPushers()) {
return self::INTENT_WANT;
}
$found_pusher_want = false;
foreach ($this->userIntents as $phid => $intent) {
if ($product->isAuthoritativePHID($phid)) {
if ($intent == self::INTENT_PASS) {
return self::INTENT_PASS;
}
$found_pusher_want = true;
}
}
if ($found_pusher_want) {
return self::INTENT_WANT;
} else {
return null;
}
}
public function getRequestorIntent() {
return idx($this->userIntents, $this->requestUserPHID);
}
public function getStatus() {
return $this->calculateStatus();
}
public function getMonogram() {
return 'Y'.$this->getID();
}
public function getBranch() {
return $this->assertAttached($this->branch);
}
public function attachBranch(ReleephBranch $branch) {
$this->branch = $branch;
return $this;
}
private function calculateStatus() {
if ($this->shouldBeInBranch()) {
if ($this->getInBranch()) {
return ReleephRequestStatus::STATUS_PICKED;
} else {
return ReleephRequestStatus::STATUS_NEEDS_PICK;
}
} else {
if ($this->getInBranch()) {
return ReleephRequestStatus::STATUS_NEEDS_REVERT;
} else {
$has_been_in_branch = $this->getCommitIdentifier();
// Regardless of why we reverted something, always say reverted if it
// was once in the branch.
if ($has_been_in_branch) {
return ReleephRequestStatus::STATUS_REVERTED;
} elseif ($this->getPusherIntent() === ReleephRequest::INTENT_PASS) {
// Otherwise, if it has never been in the branch, explicitly say why:
return ReleephRequestStatus::STATUS_REJECTED;
} elseif ($this->getRequestorIntent() === ReleephRequest::INTENT_WANT) {
return ReleephRequestStatus::STATUS_REQUESTED;
} else {
return ReleephRequestStatus::STATUS_ABANDONED;
}
}
}
}
/* -( Lisk mechanics )----------------------------------------------------- */
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'details' => self::SERIALIZATION_JSON,
'userIntents' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
ReleephPHIDTypeRequest::TYPECONST);
}
public function save() {
if (!$this->getMailKey()) {
$this->setMailKey(Filesystem::readRandomCharacters(20));
}
return parent::save();
}
/* -( Helpful accessors )--------------------------------------------------- */
public function getDetail($key, $default = null) {
return idx($this->getDetails(), $key, $default);
}
public function setDetail($key, $value) {
$this->details[$key] = $value;
return $this;
}
+
+ /**
+ * Get the commit PHIDs this request is requesting.
+ *
+ * NOTE: For now, this always returns one PHID.
+ *
+ * @return list<phid> Commit PHIDs requested by this request.
+ */
+ public function getCommitPHIDs() {
+ return array(
+ $this->requestCommitPHID,
+ );
+ }
+
public function getReason() {
// Backward compatibility: reason used to be called comments
$reason = $this->getDetail('reason');
if (!$reason) {
return $this->getDetail('comments');
}
return $reason;
}
/**
* Allow a null summary, and fall back to the title of the commit.
*/
public function getSummaryForDisplay() {
$summary = $this->getDetail('summary');
if (!strlen($summary)) {
$commit = $this->loadPhabricatorRepositoryCommit();
if ($commit) {
$summary = $commit->getSummary();
}
}
if (!strlen($summary)) {
$summary = pht('None');
}
return $summary;
}
public function loadRequestCommitDiffPHID() {
$phids = array();
$commit = $this->loadPhabricatorRepositoryCommit();
if ($commit) {
$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$commit->getPHID(),
PhabricatorEdgeConfig::TYPE_COMMIT_HAS_DREV);
}
return head($phids);
}
/* -( Loading external objects )------------------------------------------- */
public function loadPhabricatorRepositoryCommit() {
return $this->loadOneRelative(
new PhabricatorRepositoryCommit(),
'phid',
'getRequestCommitPHID');
}
public function loadPhabricatorRepositoryCommitData() {
$commit = $this->loadPhabricatorRepositoryCommit();
if ($commit) {
return $commit->loadOneRelative(
new PhabricatorRepositoryCommitData(),
'commitID');
}
}
// TODO: (T603) Get rid of all this one-off ad-hoc loading.
public function loadDifferentialRevision() {
$diff_phid = $this->loadRequestCommitDiffPHID();
if (!$diff_phid) {
return null;
}
return $this->loadOneRelative(
new DifferentialRevision(),
'phid',
'loadRequestCommitDiffPHID');
}
/* -( State change helpers )----------------------------------------------- */
public function setUserIntent(PhabricatorUser $user, $intent) {
$this->userIntents[$user->getPHID()] = $intent;
return $this;
}
/* -( Migrating to status-less ReleephRequests )--------------------------- */
protected function didReadData() {
if ($this->userIntents === null) {
$this->userIntents = array();
}
}
public function setStatus($value) {
throw new Exception('`status` is now deprecated!');
}
/* -( Make magic Lisk methods private )------------------------------------ */
private function setUserIntents(array $ar) {
return parent::setUserIntents($ar);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return $this->getBranch()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getBranch()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return pht(
'Pull requests have the same policies as the branches they are '.
'requested against.');
}
/* -( PhabricatorCustomFieldInterface )------------------------------------ */
public function getCustomFieldSpecificationForRole($role) {
return PhabricatorEnv::getEnvConfig('releeph.fields');
}
public function getCustomFieldBaseClass() {
return 'ReleephFieldSpecification';
}
public function getCustomFields() {
return $this->assertAttached($this->customFields);
}
public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) {
$this->customFields = $fields;
return $this;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jul 29, 8:06 AM (3 w, 20 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
188326
Default Alt Text
(31 KB)

Event Timeline