1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Improve differential.createinline

Summary:
  - Share code between `createinline` and `getcomments`
  - Make them both extend the base class.
  - Sync up the parameters (this is more or less nonbreaking since the call is ~6 hours old).

Test Plan: Created and fetched inlines via the API.

Reviewers: alanh, vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1500

Differential Revision: https://secure.phabricator.com/D2988
This commit is contained in:
epriestley 2012-07-17 12:06:18 -07:00
parent 02f40fd7ef
commit 9d26ef4248
3 changed files with 39 additions and 34 deletions

View file

@ -32,4 +32,31 @@ abstract class ConduitAPI_differential_Method extends ConduitAPIMethod {
} }
protected function buildInlineInfoDictionary(
DifferentialInlineComment $inline,
DifferentialChangeset $changeset = null) {
$file_path = null;
$diff_id = null;
if ($changeset) {
$file_path = $inline->getIsNewFile()
? $changeset->getFilename()
: $changeset->getOldFile();
$diff_id = $changeset->getDiffID();
}
return array(
'id' => $inline->getID(),
'authorPHID' => $inline->getAuthorPHID(),
'filePath' => $file_path,
'isNewFile' => $inline->getIsNewFile(),
'lineNumber' => $inline->getLineNumber(),
'lineLength' => $inline->getLineLength(),
'diffID' => $diff_id,
'content' => $inline->getContent(),
);
}
} }

View file

@ -20,7 +20,7 @@
* @group conduit * @group conduit
*/ */
final class ConduitAPI_differential_createinline_Method final class ConduitAPI_differential_createinline_Method
extends ConduitAPIMethod { extends ConduitAPI_differential_Method {
public function getMethodDescription() { public function getMethodDescription() {
return "Add an inline comment to a Differential revision."; return "Add an inline comment to a Differential revision.";
@ -32,9 +32,9 @@ final class ConduitAPI_differential_createinline_Method
'diffID' => 'optional diffid', 'diffID' => 'optional diffid',
'filePath' => 'required string', 'filePath' => 'required string',
'isNewFile' => 'required bool', 'isNewFile' => 'required bool',
'lineStart' => 'required int', 'lineNumber' => 'required int',
'lineCount' => 'optional int', 'lineLength' => 'optional int',
'message' => 'required string', 'content' => 'required string',
); );
} }
@ -106,25 +106,16 @@ final class ConduitAPI_differential_createinline_Method
->setRevisionID($rid) ->setRevisionID($rid)
->setChangesetID($cid) ->setChangesetID($cid)
->setAuthorPHID($request->getUser()->getPHID()) ->setAuthorPHID($request->getUser()->getPHID())
->setContent($request->getValue('message')) ->setContent($request->getValue('content'))
->setIsNewFile($request->getValue('isNewFile')) ->setIsNewFile($request->getValue('isNewFile'))
->setLineNumber($request->getValue('lineStart')) ->setLineNumber($request->getValue('lineNumber'))
->setLineLength($request->getValue('lineCount', 0)) ->setLineLength($request->getValue('lineLength', 0))
->save(); ->save();
// Load everything again, just to be safe. // Load everything again, just to be safe.
$changeset = id(new DifferentialChangeset()) $changeset = id(new DifferentialChangeset())
->load($inline->getChangesetID()); ->load($inline->getChangesetID());
return array( return $this->buildInlineInfoDictionary($inline, $changeset);
'filePath' => ($inline->getIsNewFile() ?
$changeset->getFilename() :
$changeset->getOldFile()),
'isNewFile' => $inline->getIsNewFile(),
'lineNumber' => $inline->getLineNumber(),
'lineLength' => $inline->getLineLength(),
'diffID' => $changeset->getDiffID(),
'content' => $inline->getContent(),
);
} }
} }

View file

@ -20,7 +20,7 @@
* @group conduit * @group conduit
*/ */
final class ConduitAPI_differential_getrevisioncomments_Method final class ConduitAPI_differential_getrevisioncomments_Method
extends ConduitAPIMethod { extends ConduitAPI_differential_Method {
public function getMethodDescription() { public function getMethodDescription() {
return "Retrieve Differential Revision Comments."; return "Retrieve Differential Revision Comments.";
@ -81,23 +81,10 @@ final class ConduitAPI_differential_getrevisioncomments_Method
if ($with_inlines) { if ($with_inlines) {
$result['inlines'] = array(); $result['inlines'] = array();
foreach (idx($inlines, $comment->getID(), array()) as $inline) { foreach (idx($inlines, $comment->getID(), array()) as $inline) {
$file_path = null;
$diff_id = null;
$changeset = idx($changesets, $inline->getChangesetID()); $changeset = idx($changesets, $inline->getChangesetID());
if ($changeset) { $result['inlines'][] = $this->buildInlineInfoDictionary(
$file_path = ($inline->getIsNewFile() ? $inline,
$changeset->getFilename() : $changeset);
$changeset->getOldFile());
$diff_id = $changeset->getDiffID();
}
$result['inlines'][] = array(
'filePath' => $file_path,
'isNewFile' => $inline->getIsNewFile(),
'lineNumber' => $inline->getLineNumber(),
'lineLength' => $inline->getLineLength(),
'diffID' => $diff_id,
'content' => $inline->getContent(),
);
} }
// TODO: Put synthetic inlines without an attached comment somewhere. // TODO: Put synthetic inlines without an attached comment somewhere.
} }