1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 03:50:54 +01:00

add a getrevision conduit method

Summary:
Add a method to get the information about a revision, including its full
list of diffs.

We could add an option to just return the diff IDs if we wanted.  For my
use case, I need the full set of information for each diff, so fewer
round trips is better.  This is also how the old json.php page used to
work.

Test Plan:
Tuomas tested it in his sandbox.

Reviewed By: tuomaspelkonen
Reviewers: jungejason, tuomaspelkonen, epriestley
CC: tuomaspelkonen
Differential Revision: 156
This commit is contained in:
Adam Simpkins 2011-04-20 16:38:16 -07:00
parent dbb01cfe63
commit d4576262db
4 changed files with 107 additions and 0 deletions

View file

@ -82,6 +82,7 @@ phutil_register_library_map(array(
'ConduitAPI_differential_getcommitmessage_Method' => 'applications/conduit/method/differential/getcommitmessage',
'ConduitAPI_differential_getcommitpaths_Method' => 'applications/conduit/method/differential/getcommitpaths',
'ConduitAPI_differential_getdiff_Method' => 'applications/conduit/method/differential/getdiff',
'ConduitAPI_differential_getrevision_Method' => 'applications/conduit/method/differential/getrevision',
'ConduitAPI_differential_getrevisionfeedback_Method' => 'applications/conduit/method/differential/getrevisionfeedback',
'ConduitAPI_differential_markcommitted_Method' => 'applications/conduit/method/differential/markcommitted',
'ConduitAPI_differential_parsecommitmessage_Method' => 'applications/conduit/method/differential/parsecommitmessage',
@ -531,6 +532,7 @@ phutil_register_library_map(array(
'ConduitAPI_differential_getcommitmessage_Method' => 'ConduitAPIMethod',
'ConduitAPI_differential_getcommitpaths_Method' => 'ConduitAPIMethod',
'ConduitAPI_differential_getdiff_Method' => 'ConduitAPIMethod',
'ConduitAPI_differential_getrevision_Method' => 'ConduitAPIMethod',
'ConduitAPI_differential_getrevisionfeedback_Method' => 'ConduitAPIMethod',
'ConduitAPI_differential_markcommitted_Method' => 'ConduitAPIMethod',
'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod',

View file

@ -69,6 +69,10 @@ class ConduitAPI_differential_getdiff_Method extends ConduitAPIMethod {
$changeset->attachHunks($changeset->loadHunks());
}
return $this->createDiffDict($diff);
}
public static function createDiffDict(DifferentialDiff $diff) {
$dict = array(
'id' => $diff->getID(),
'parent' => $diff->getParentRevisionID(),

View file

@ -0,0 +1,83 @@
<?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_getrevision_Method extends ConduitAPIMethod {
public function getMethodDescription() {
return "Load the content of a revision from Differential.";
}
public function defineParamTypes() {
return array(
'revision_id' => 'required id',
);
}
public function defineReturnType() {
return 'nonempty dict';
}
public function defineErrorTypes() {
return array(
'ERR_BAD_REVISION' => 'No such revision exists.',
);
}
protected function execute(ConduitAPIRequest $request) {
$diff = null;
$revision_id = $request->getValue('revision_id');
$revision = id(new DifferentialRevision())->load($revision_id);
if (!$revision) {
throw new ConduitException('ERR_BAD_REVISION');
}
$diffs = $revision->loadDiffs();
$diff_dicts = array();
foreach ($diffs as $diff) {
$diff->attachChangesets($diff->loadChangesets());
// TODO: We could batch this to improve performance.
foreach ($diff->getChangesets() as $changeset) {
$changeset->attachHunks($changeset->loadHunks());
}
$diff_dicts[] =
ConduitAPI_differential_getdiff_Method::createDiffDict($diff);
}
$dict = array(
'id' => $revision->getID(),
'phid' => $revision->getPHID(),
'authorPHID' => $revision->getAuthorPHID(),
'title' => $revision->getTitle(),
'status' => $revision->getStatus(),
'statusName' => DifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()),
'summary' => $revision->getSummary(),
'testPlan' => $revision->getTestPlan(),
'revertPlan' => $revision->getRevertPlan(),
'blameRevision' => $revision->getBlameRevision(),
'dateCommitted' => $revision->getDateCommitted(),
'lineCount' => $revision->getLineCount(),
'diffs' => $diff_dicts,
);
return $dict;
}
}

View file

@ -0,0 +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/method/differential/getdiff');
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phutil', 'utils');
phutil_require_source('ConduitAPI_differential_getrevision_Method.php');