1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-22 11:39:03 +01:00

Support export of revisions to Excel/CSV/JSON/etc

Summary: Ref T13210. See PHI806. This enables basic export of revisions into flat data formats. This isn't too fancy, but just covers the basics since the driving use case isn't especially concerned about getting all the fields and details.

Test Plan: Exported some revisions into JSON, got sensible output.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13210

Differential Revision: https://secure.phabricator.com/D19743
This commit is contained in:
epriestley 2018-10-11 08:20:13 -07:00
parent 4f557ff075
commit 4f54d483d5
2 changed files with 76 additions and 3 deletions

View file

@ -1,6 +1,7 @@
<?php
final class PhabricatorDifferentialApplication extends PhabricatorApplication {
final class PhabricatorDifferentialApplication
extends PhabricatorApplication {
public function getBaseURI() {
return '/differential/';
@ -48,8 +49,7 @@ final class PhabricatorDifferentialApplication extends PhabricatorApplication {
'/(?P<filter>new)/' => 'DifferentialRevisionViewController',
),
'/differential/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'DifferentialRevisionListController',
$this->getQueryRoutePattern() => 'DifferentialRevisionListController',
'diff/' => array(
'(?P<id>[1-9]\d*)/' => array(
'' => 'DifferentialDiffViewController',

View file

@ -289,4 +289,77 @@ final class DifferentialRevisionSearchEngine
return $result;
}
protected function newExportFields() {
$fields = array(
id(new PhabricatorStringExportField())
->setKey('monogram')
->setLabel(pht('Monogram')),
id(new PhabricatorPHIDExportField())
->setKey('authorPHID')
->setLabel(pht('Author PHID')),
id(new PhabricatorStringExportField())
->setKey('author')
->setLabel(pht('Author')),
id(new PhabricatorStringExportField())
->setKey('status')
->setLabel(pht('Status')),
id(new PhabricatorStringExportField())
->setKey('statusName')
->setLabel(pht('Status Name')),
id(new PhabricatorURIExportField())
->setKey('uri')
->setLabel(pht('URI')),
id(new PhabricatorStringExportField())
->setKey('title')
->setLabel(pht('Title')),
id(new PhabricatorStringExportField())
->setKey('summary')
->setLabel(pht('Summary')),
id(new PhabricatorStringExportField())
->setKey('testPlan')
->setLabel(pht('Test Plan')),
);
return $fields;
}
protected function newExportData(array $revisions) {
$viewer = $this->requireViewer();
$phids = array();
foreach ($revisions as $revision) {
$phids[] = $revision->getAuthorPHID();
}
$handles = $viewer->loadHandles($phids);
$export = array();
foreach ($revisions as $revision) {
$author_phid = $revision->getAuthorPHID();
if ($author_phid) {
$author_name = $handles[$author_phid]->getName();
} else {
$author_name = null;
}
$status = $revision->getStatusObject();
$status_name = $status->getDisplayName();
$status_value = $status->getKey();
$export[] = array(
'monogram' => $revision->getMonogram(),
'authorPHID' => $author_phid,
'author' => $author_name,
'status' => $status_value,
'statusName' => $status_name,
'uri' => PhabricatorEnv::getProductionURI($revision->getURI()),
'title' => (string)$revision->getTitle(),
'summary' => (string)$revision->getSummary(),
'testPlan' => (string)$revision->getTestPlan(),
);
}
return $export;
}
}