Page MenuHomestyx hydra

No OneTemporary

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
@@ -1,59 +1,109 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ConduitAPI_differential_getcommitmessage_Method extends ConduitAPIMethod {
public function getMethodDescription() {
return "Retrieve Differential commit messages.";
}
public function defineParamTypes() {
return array(
'revision_id' => 'required revision_id',
+ 'fields' => 'optional dict<string, wild>',
+ 'edit' => 'optional bool',
);
}
public function defineReturnType() {
return 'nonempty string';
}
public function defineErrorTypes() {
return array(
'ERR_NOT_FOUND' => 'Revision was not found.',
);
}
protected function execute(ConduitAPIRequest $request) {
$id = $request->getValue('revision_id');
$revision = id(new DifferentialRevision())->load($id);
if (!$revision) {
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
@@ -1,17 +1,18 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
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');
phutil_require_source('ConduitAPI_differential_getcommitmessage_Method.php');
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
@@ -1,193 +1,193 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class DifferentialCommitMessageData {
protected $revision;
protected $dict = array();
protected $mode;
protected $comments;
const MODE_EDIT = 'edit';
const MODE_AMEND = 'amend';
public function __construct(DifferentialRevision $revision, $mode) {
$this->revision = $revision;
$this->mode = $mode;
$comments = id(new DifferentialComment())->loadAllWhere(
'revisionID = %d',
$revision->getID());
$this->comments = $comments;
}
protected function getCommenters() {
$revision = $this->revision;
$map = array();
foreach ($this->comments as $comment) {
$map[$comment->getAuthorPHID()] = true;
}
unset($map[$revision->getAuthorPHID()]);
if ($this->getReviewer()) {
unset($map[$this->getReviewer()]);
}
return array_keys($map);
}
private function getReviewer() {
$reviewer = null;
foreach ($this->comments as $comment) {
if ($comment->getAction() == DifferentialAction::ACTION_ACCEPT) {
$reviewer = $comment->getAuthorPHID();
} else if ($comment->getAction() == DifferentialAction::ACTION_REJECT) {
$reviewer = null;
}
}
return $reviewer;
}
public function prepare() {
$revision = $this->revision;
$dict = array();
if ($revision->getSummary()) {
$dict['Summary'] = $revision->getSummary();
}
$dict['Test Plan'] = $revision->getTestPlan();
- $dict['Differential Revision'] = $revision->getID();
-
$reviewer = null;
$commenters = array();
$revision->loadRelationships();
if ($this->mode == self::MODE_AMEND) {
$reviewer = $this->getReviewer();
$commenters = $this->getCommenters();
}
$reviewers = $revision->getReviewers();
$ccphids = $revision->getCCPHIDs();
$phids = array_merge($ccphids, $commenters, $reviewers);
if ($reviewer) {
$phids[] = $reviewer;
}
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
if ($this->mode == self::MODE_AMEND) {
if ($reviewer) {
$dict['Reviewed By'] = $handles[$reviewer]->getName();
}
}
if ($reviewers) {
$reviewer_names = array();
foreach ($reviewers as $uid) {
$reviewer_names[] = $handles[$uid]->getName();
}
$reviewer_names = implode(', ', $reviewer_names);
$dict['Reviewers'] = $reviewer_names;
}
$user_handles = array_select_keys($handles, $commenters);
if ($user_handles) {
$dict['Commenters'] = implode(
', ',
mpull($user_handles, 'getName'));
}
$cc_handles = array_select_keys($handles, $ccphids);
if ($cc_handles) {
$dict['CC'] = implode(
', ',
mpull($cc_handles, 'getName'));
}
if ($revision->getRevertPlan()) {
$dict['Revert Plan'] = $revision->getRevertPlan();
}
if ($revision->getBlameRevision()) {
$dict['Blame Revision'] = $revision->getBlameRevision();
}
if ($this->mode == self::MODE_EDIT) {
// In edit mode, include blank fields.
$dict += array(
'Summary' => '',
'Reviewers' => '',
'CC' => '',
'Revert Plan' => '',
'Blame Revision' => '',
);
}
$dict['Title'] = $revision->getTitle();
+ $dict['Differential Revision'] = $revision->getID();
+
$this->dict = $dict;
}
public function overwriteFieldValue($field, $value) {
$this->dict[$field] = $value;
return $this;
}
public function getCommitMessage() {
$revision = $this->revision;
$dict = $this->dict;
$message = array();
$message[] = $dict['Title']."\n";
unset($dict['Title']);
$one_line = array(
'Differential Revision' => true,
'Reviewed By' => true,
'Revert' => true,
'Blame Rev' => true,
'Commenters' => true,
'CC' => true,
'Reviewers' => true,
);
foreach ($dict as $key => $value) {
$value = trim($value);
if (isset($one_line[$key])) {
$message[] = "{$key}: {$value}";
} else {
$message[] = "{$key}:\n{$value}\n";
}
}
$message = implode("\n", $message);
$message = str_replace(
array("\r\n", "\r"),
array("\n", "\n"),
$message);
$message = $message."\n";
return $message;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Dec 3, 12:46 PM (9 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
433394
Default Alt Text
(10 KB)

Event Timeline