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:
parent
02f40fd7ef
commit
9d26ef4248
3 changed files with 39 additions and 34 deletions
|
@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_differential_createinline_Method
|
||||
extends ConduitAPIMethod {
|
||||
extends ConduitAPI_differential_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Add an inline comment to a Differential revision.";
|
||||
|
@ -32,9 +32,9 @@ final class ConduitAPI_differential_createinline_Method
|
|||
'diffID' => 'optional diffid',
|
||||
'filePath' => 'required string',
|
||||
'isNewFile' => 'required bool',
|
||||
'lineStart' => 'required int',
|
||||
'lineCount' => 'optional int',
|
||||
'message' => 'required string',
|
||||
'lineNumber' => 'required int',
|
||||
'lineLength' => 'optional int',
|
||||
'content' => 'required string',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -106,25 +106,16 @@ final class ConduitAPI_differential_createinline_Method
|
|||
->setRevisionID($rid)
|
||||
->setChangesetID($cid)
|
||||
->setAuthorPHID($request->getUser()->getPHID())
|
||||
->setContent($request->getValue('message'))
|
||||
->setContent($request->getValue('content'))
|
||||
->setIsNewFile($request->getValue('isNewFile'))
|
||||
->setLineNumber($request->getValue('lineStart'))
|
||||
->setLineLength($request->getValue('lineCount', 0))
|
||||
->setLineNumber($request->getValue('lineNumber'))
|
||||
->setLineLength($request->getValue('lineLength', 0))
|
||||
->save();
|
||||
|
||||
// Load everything again, just to be safe.
|
||||
$changeset = id(new DifferentialChangeset())
|
||||
->load($inline->getChangesetID());
|
||||
return array(
|
||||
'filePath' => ($inline->getIsNewFile() ?
|
||||
$changeset->getFilename() :
|
||||
$changeset->getOldFile()),
|
||||
'isNewFile' => $inline->getIsNewFile(),
|
||||
'lineNumber' => $inline->getLineNumber(),
|
||||
'lineLength' => $inline->getLineLength(),
|
||||
'diffID' => $changeset->getDiffID(),
|
||||
'content' => $inline->getContent(),
|
||||
);
|
||||
return $this->buildInlineInfoDictionary($inline, $changeset);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_differential_getrevisioncomments_Method
|
||||
extends ConduitAPIMethod {
|
||||
extends ConduitAPI_differential_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Retrieve Differential Revision Comments.";
|
||||
|
@ -81,23 +81,10 @@ final class ConduitAPI_differential_getrevisioncomments_Method
|
|||
if ($with_inlines) {
|
||||
$result['inlines'] = array();
|
||||
foreach (idx($inlines, $comment->getID(), array()) as $inline) {
|
||||
$file_path = null;
|
||||
$diff_id = null;
|
||||
$changeset = idx($changesets, $inline->getChangesetID());
|
||||
if ($changeset) {
|
||||
$file_path = ($inline->getIsNewFile() ?
|
||||
$changeset->getFilename() :
|
||||
$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(),
|
||||
);
|
||||
$result['inlines'][] = $this->buildInlineInfoDictionary(
|
||||
$inline,
|
||||
$changeset);
|
||||
}
|
||||
// TODO: Put synthetic inlines without an attached comment somewhere.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue