1
0
Fork 0
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:
epriestley 2011-03-04 17:03:59 -08:00
parent deac6e85cc
commit e98d1ae9be
3 changed files with 56 additions and 5 deletions

View file

@ -25,6 +25,8 @@ class ConduitAPI_differential_getcommitmessage_Method extends ConduitAPIMethod {
public function defineParamTypes() { public function defineParamTypes() {
return array( return array(
'revision_id' => 'required revision_id', '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'); throw new ConduitException('ERR_NOT_FOUND');
} }
$message_data = new DifferentialCommitMessageData( $edit = $request->getValue('edit');
$revision, $mode = $edit
DifferentialCommitMessageData::MODE_AMEND); ? DifferentialCommitMessageData::MODE_EDIT
: DifferentialCommitMessageData::MODE_AMEND;
$message_data = new DifferentialCommitMessageData($revision, $mode);
$message_data->prepare(); $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(); $commit_message = $message_data->getCommitMessage();
return wordwrap($commit_message, 80); return wordwrap($commit_message, 80);

View file

@ -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/conduit/protocol/exception');
phutil_require_module('phabricator', 'applications/differential/data/commitmessage'); phutil_require_module('phabricator', 'applications/differential/data/commitmessage');
phutil_require_module('phabricator', 'applications/differential/storage/revision'); phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -73,8 +73,6 @@ class DifferentialCommitMessageData {
$dict['Test Plan'] = $revision->getTestPlan(); $dict['Test Plan'] = $revision->getTestPlan();
$dict['Differential Revision'] = $revision->getID();
$reviewer = null; $reviewer = null;
$commenters = array(); $commenters = array();
$revision->loadRelationships(); $revision->loadRelationships();
@ -145,6 +143,8 @@ class DifferentialCommitMessageData {
$dict['Title'] = $revision->getTitle(); $dict['Title'] = $revision->getTitle();
$dict['Differential Revision'] = $revision->getID();
$this->dict = $dict; $this->dict = $dict;
} }