mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +01:00
Conduit: differential.getcommitmessage
Summary: Test Plan: Reviewers: CC:
This commit is contained in:
parent
bb8bc4ff54
commit
1369bd3dd4
5 changed files with 288 additions and 0 deletions
|
@ -67,6 +67,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_differential_creatediff_Method' => 'applications/conduit/method/differential/creatediff',
|
||||
'ConduitAPI_differential_createrevision_Method' => 'applications/conduit/method/differential/createrevision',
|
||||
'ConduitAPI_differential_find_Method' => 'applications/conduit/method/differential/find',
|
||||
'ConduitAPI_differential_getcommitmessage_Method' => 'applications/conduit/method/differential/getcommitmessage',
|
||||
'ConduitAPI_differential_parsecommitmessage_Method' => 'applications/conduit/method/differential/parsecommitmessage',
|
||||
'ConduitAPI_differential_setdiffproperty_Method' => 'applications/conduit/method/differential/setdiffproperty',
|
||||
'ConduitAPI_differential_updaterevision_Method' => 'applications/conduit/method/differential/updaterevision',
|
||||
|
@ -99,6 +100,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialCommentPreviewController' => 'applications/differential/controller/commentpreview',
|
||||
'DifferentialCommentSaveController' => 'applications/differential/controller/commentsave',
|
||||
'DifferentialCommitMessage' => 'applications/differential/parser/commitmessage',
|
||||
'DifferentialCommitMessageData' => 'applications/differential/data/commitmessage',
|
||||
'DifferentialCommitMessageParserException' => 'applications/differential/parser/commitmessage/exception',
|
||||
'DifferentialController' => 'applications/differential/controller/base',
|
||||
'DifferentialDAO' => 'applications/differential/storage/base',
|
||||
|
@ -293,6 +295,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_createrevision_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_find_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_getcommitmessage_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_updaterevision_Method' => 'ConduitAPIMethod',
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?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',
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
$message_data->prepare();
|
||||
|
||||
$commit_message = $message_data->getCommitMessage();
|
||||
|
||||
return wordwrap($commit_message, 80);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?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('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('ConduitAPI_differential_getcommitmessage_Method.php');
|
|
@ -0,0 +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($handles);
|
||||
|
||||
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();
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/action');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/comment');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DifferentialCommitMessageData.php');
|
Loading…
Reference in a new issue