diff --git a/src/applications/conduit/method/differential/getcommitmessage/ConduitAPI_differential_getcommitmessage_Method.php b/src/applications/conduit/method/differential/getcommitmessage/ConduitAPI_differential_getcommitmessage_Method.php index 2e6e045c1b..597ca7366c 100644 --- a/src/applications/conduit/method/differential/getcommitmessage/ConduitAPI_differential_getcommitmessage_Method.php +++ b/src/applications/conduit/method/differential/getcommitmessage/ConduitAPI_differential_getcommitmessage_Method.php @@ -25,6 +25,8 @@ class ConduitAPI_differential_getcommitmessage_Method extends ConduitAPIMethod { public function defineParamTypes() { return array( 'revision_id' => 'required revision_id', + 'fields' => 'optional dict', + 'edit' => 'optional bool', ); } @@ -46,11 +48,59 @@ class ConduitAPI_differential_getcommitmessage_Method extends ConduitAPIMethod { throw new ConduitException('ERR_NOT_FOUND'); } - $message_data = new DifferentialCommitMessageData( - $revision, - DifferentialCommitMessageData::MODE_AMEND); + $edit = $request->getValue('edit'); + $mode = $edit + ? DifferentialCommitMessageData::MODE_EDIT + : DifferentialCommitMessageData::MODE_AMEND; + + $message_data = new DifferentialCommitMessageData($revision, $mode); $message_data->prepare(); + if ($mode == DifferentialCommitMessageData::MODE_EDIT) { + $fields = $request->getValue('fields'); + if ($fields) { + + static $simple_fields = array( + 'title' => 'Title', + 'summary' => 'Summary', + 'testPlan' => 'Test Plan', + 'blameRevision' => 'Blame Revision', + 'revertPlan' => 'Revert Plan', + ); + + foreach ($fields as $field => $value) { + if (isset($simple_fields[$field])) { + $message_data->overwriteFieldValue( + $simple_fields[$field], + $value); + } else { + $overwrite = true; + static $overwrite_map = array( + 'reviewerPHIDs' => 'Reviewers', + 'ccPHIDs' => 'CC', + 'taskPHIDs' => 'Tasks', + ); + switch ($field) { + case 'reviewerPHIDs': + case 'ccPHIDs': + $handles = id(new PhabricatorObjectHandleData($value)) + ->loadHandles($handles); + $value = implode(', ', mpull($handles, 'getName')); + break; + default: + $overwrite = false; + break; + } + if ($overwrite) { + $message_data->overwriteFieldValue( + $overwrite_map[$field], + $value); + } + } + } + } + } + $commit_message = $message_data->getCommitMessage(); return wordwrap($commit_message, 80); diff --git a/src/applications/conduit/method/differential/getcommitmessage/__init__.php b/src/applications/conduit/method/differential/getcommitmessage/__init__.php index d1e80a8a82..2de8f9d9d0 100644 --- a/src/applications/conduit/method/differential/getcommitmessage/__init__.php +++ b/src/applications/conduit/method/differential/getcommitmessage/__init__.php @@ -10,6 +10,7 @@ phutil_require_module('phabricator', 'applications/conduit/method/base'); phutil_require_module('phabricator', 'applications/conduit/protocol/exception'); phutil_require_module('phabricator', 'applications/differential/data/commitmessage'); phutil_require_module('phabricator', 'applications/differential/storage/revision'); +phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/differential/data/commitmessage/DifferentialCommitMessageData.php b/src/applications/differential/data/commitmessage/DifferentialCommitMessageData.php index 7e31f7e24b..9e1084ebc2 100644 --- a/src/applications/differential/data/commitmessage/DifferentialCommitMessageData.php +++ b/src/applications/differential/data/commitmessage/DifferentialCommitMessageData.php @@ -73,8 +73,6 @@ class DifferentialCommitMessageData { $dict['Test Plan'] = $revision->getTestPlan(); - $dict['Differential Revision'] = $revision->getID(); - $reviewer = null; $commenters = array(); $revision->loadRelationships(); @@ -145,6 +143,8 @@ class DifferentialCommitMessageData { $dict['Title'] = $revision->getTitle(); + $dict['Differential Revision'] = $revision->getID(); + $this->dict = $dict; }