mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-02 02:40:58 +01:00
Enhance Phabricator capabilities for differential.getcommitmessage (2)
Summary: Enables --edit workflow to behave properly [edit] Test Plan: meta [what] Reviewers: CC: epriestley Differential Revision: 26
This commit is contained in:
parent
deac6e85cc
commit
e98d1ae9be
3 changed files with 56 additions and 5 deletions
|
@ -25,6 +25,8 @@ class ConduitAPI_differential_getcommitmessage_Method extends ConduitAPIMethod {
|
|||
public function defineParamTypes() {
|
||||
return array(
|
||||
'revision_id' => 'required revision_id',
|
||||
'fields' => 'optional dict<string, wild>',
|
||||
'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);
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue