Implement maniphest baking
This commit is contained in:
@@ -46,14 +46,23 @@ $viewer = PhabricatorUser::getOmnipotentUser();
|
||||
|
||||
$application_configuration = CreateApplicationConfiguration();
|
||||
|
||||
$application = id(new PhabricatorDifferentialApplication());
|
||||
$differential_application = id(new PhabricatorDifferentialApplication());
|
||||
$revision_controller = id(new DifferentialRevisionViewController())
|
||||
->setCurrentApplication($application);
|
||||
->setCurrentApplication($differential_application);
|
||||
|
||||
$routing_map = id(new AphrontRoutingMap())
|
||||
$maniphest_application = id(new PhabricatorManiphestApplication());
|
||||
$maniphest_controller = id(new ManiphestTaskDetailController())
|
||||
->setCurrentApplication($maniphest_application);
|
||||
|
||||
$differential_routing_map = id(new AphrontRoutingMap())
|
||||
->setSite($site)
|
||||
->setApplication($application)
|
||||
->setRoutes($application->getRoutes());
|
||||
->setApplication($differential_application)
|
||||
->setRoutes($differential_application->getRoutes());
|
||||
|
||||
$maniphest_routing_map = id(new AphrontRoutingMap())
|
||||
->setSite($site)
|
||||
->setApplication($maniphest_application)
|
||||
->setRoutes($maniphest_application->getRoutes());
|
||||
|
||||
$conduit = id(new ConduitClient('https://developer.blender.org/api/'))
|
||||
->setConduitToken(trim(file_get_contents($CONDUIT_TOKEN_FILE)));
|
||||
@@ -70,6 +79,15 @@ function EnsureDirectoryOrDie($dir) {
|
||||
}
|
||||
}
|
||||
|
||||
function RenderResponseToHTML($response) {
|
||||
$html = '';
|
||||
foreach ($response->renderChildren() as $child) {
|
||||
$html .= $child->render();
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Revision baking.
|
||||
|
||||
@@ -142,61 +160,25 @@ function GetRevisionRawDiffFilename($revision, $diff_id) {
|
||||
return PathJoin(array($revision_dir, 'raw_diff', $file_name));
|
||||
}
|
||||
|
||||
/*
|
||||
function MakeGenericOutputDirectory($subject) {
|
||||
global $OUTPUT_DIR;
|
||||
|
||||
$dir = $OUTPUT_DIR . DIRECTORY_SEPARATOR . $subject;
|
||||
EnsureDirectoryOrDie($dir);
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
function MakeRevisionBaseOutputFileName($revision, $diff_id, $subject) {
|
||||
$dir = MakeGenericOutputDirectory($subject);
|
||||
|
||||
$file_name = $dir . DIRECTORY_SEPARATOR . 'D' . $revision->getID();
|
||||
|
||||
if (!is_null($diff_id)) {
|
||||
$file_name .= '.' . $diff_id;
|
||||
}
|
||||
|
||||
return $file_name;
|
||||
}
|
||||
|
||||
function MakeRevisionHTMLOutputFileName($revision, $diff_id) {
|
||||
return MakeRevisionBaseOutputFileName(
|
||||
$revision, $diff_id, 'revision') . '.html';
|
||||
}
|
||||
|
||||
function MakeRawDiffOutputFileName($revision, $diff_id) {
|
||||
return MakeRevisionBaseOutputFileName(
|
||||
$revision, $diff_id, 'raw_diff') . '.diff';
|
||||
}
|
||||
*/
|
||||
|
||||
function RenderDifferentialToResponse($revision, $diff_id) {
|
||||
global $application_configuration;
|
||||
global $revision_controller;
|
||||
global $routing_map;
|
||||
global $differential_routing_map;
|
||||
global $viewer;
|
||||
|
||||
$revision_id = $revision->getID();
|
||||
|
||||
$path = '/D' . $revision_id;
|
||||
|
||||
$route_result = $routing_map->routePath($path);
|
||||
$route_result = $differential_routing_map->routePath($path);
|
||||
$uri_data = $route_result->getURIData();
|
||||
|
||||
$application_configuration->setPath($path);
|
||||
|
||||
$request_data = array(
|
||||
'id' => $diff_id,
|
||||
);
|
||||
|
||||
if (!is_null($diff_id)) {
|
||||
$request_data['id'] = $diff_id;
|
||||
}
|
||||
|
||||
$request = $application_configuration->buildRequest()
|
||||
->setUser($viewer)
|
||||
->setRequestData($request_data)
|
||||
@@ -209,20 +191,7 @@ function RenderDifferentialToResponse($revision, $diff_id) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
function RenderResponseToHTML($response) {
|
||||
$html = '';
|
||||
foreach ($response->renderChildren() as $child) {
|
||||
$html .= $child->render();
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function StoreRawDiff($revision, $diff_id) {
|
||||
if (is_null($diff_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $viewer;
|
||||
global $conduit;
|
||||
|
||||
@@ -260,8 +229,11 @@ function GetRevisionHash($revision) {
|
||||
$digest = '';
|
||||
|
||||
$digest .= $revision->getDateModified();
|
||||
$digest .= '_' . $xaction->getPHID();
|
||||
$digest .= '_' . $xaction->getDateModified();
|
||||
|
||||
if ($xaction) {
|
||||
$digest .= '_' . $xaction->getPHID();
|
||||
$digest .= '_' . $xaction->getDateModified();
|
||||
}
|
||||
|
||||
return $digest;
|
||||
}
|
||||
@@ -319,6 +291,162 @@ function BakeRevision($revision, $diff_id) {
|
||||
$info->SaveToFile($info_file_name);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Task baking.
|
||||
|
||||
class TaskInfo {
|
||||
public $title = '';
|
||||
public $page_title = '';
|
||||
|
||||
public $hash = '';
|
||||
|
||||
public static function ReadFromFile($file_name) {
|
||||
$info = new TaskInfo();
|
||||
|
||||
if (!file_exists($file_name)) {
|
||||
return $info;
|
||||
}
|
||||
|
||||
$json = json_decode(file_get_contents($file_name));
|
||||
foreach ($json as $key => $value) {
|
||||
$info->{$key} = $value;
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function SaveToFile($file_name) {
|
||||
$json_str = json_encode(get_object_vars($this));
|
||||
file_put_contents($file_name, $json_str);
|
||||
}
|
||||
};
|
||||
|
||||
function GetTaskOutputDirectory($task) {
|
||||
global $OUTPUT_DIR;
|
||||
|
||||
$id = $task->getID();
|
||||
|
||||
return PathJoin(array($OUTPUT_DIR, 'maniphest', SubpathFromId($id)));
|
||||
}
|
||||
|
||||
function EnsureTaskOutputDirectory($task) {
|
||||
$dir = GetTaskOutputDirectory($task);
|
||||
|
||||
EnsureDirectoryOrDie($dir);
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
function GetTaskInfoFilename($task) {
|
||||
$task_dir = GetTaskOutputDirectory($task);
|
||||
return PathJoin(array($task_dir, 'info.json'));
|
||||
}
|
||||
|
||||
function GetTaskHTMLFilename($task) {
|
||||
$task_id = $task->getID();
|
||||
$task_dir = GetTaskOutputDirectory($task);
|
||||
|
||||
$file_name = "index.html";
|
||||
|
||||
return PathJoin(array($task_dir, $file_name));
|
||||
}
|
||||
|
||||
function RenderTaskToResponse($task) {
|
||||
global $application_configuration;
|
||||
global $maniphest_routing_map;
|
||||
global $viewer;
|
||||
global $maniphest_controller;
|
||||
|
||||
$task_id = $task->getID();
|
||||
|
||||
$path = '/T' . $task_id;
|
||||
|
||||
$route_result = $maniphest_routing_map->routePath($path);
|
||||
$uri_data = $route_result->getURIData();
|
||||
|
||||
$application_configuration->setPath($path);
|
||||
|
||||
$request_data = array(
|
||||
);
|
||||
|
||||
$request = $application_configuration->buildRequest()
|
||||
->setUser($viewer)
|
||||
->setRequestData($request_data)
|
||||
->setURIMap($uri_data);
|
||||
|
||||
$response = id($maniphest_controller)
|
||||
->setRequest($request)
|
||||
->handleRequest($request);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function GetTaskHash($task) {
|
||||
global $viewer;
|
||||
|
||||
$xaction = id(new DifferentialTransactionQuery())
|
||||
->setViewer($viewer)
|
||||
->withObjectPHIDs(array($task->getPHID()))
|
||||
->setOrder('newest')
|
||||
->setLimit(1)
|
||||
->executeOne();
|
||||
|
||||
$digest = '';
|
||||
|
||||
$digest .= $task->getDateModified();
|
||||
|
||||
if ($xaction) {
|
||||
$digest .= '_' . $xaction->getPHID();
|
||||
$digest .= '_' . $xaction->getDateModified();
|
||||
}
|
||||
|
||||
return $digest;
|
||||
}
|
||||
|
||||
function NeedBakeTask($info, $task) {
|
||||
if (!file_exists(GetTaskHTMLFilename($task))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($task->getTitle() != $info->title) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GetTaskHash($task) != $info->hash) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function BakeTask($task) {
|
||||
$task_id = $task->getID();
|
||||
|
||||
printf('Baking T' . $task_id . ' ...' . "\n");
|
||||
|
||||
$info_file_name = GetTaskInfoFilename($task);
|
||||
|
||||
$info = TaskInfo::ReadFromFile($info_file_name);
|
||||
|
||||
if (!NeedBakeTask($info, $task)) {
|
||||
print(' ... ignoring: up to date' . "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
$response = RenderTaskToResponse($task);
|
||||
|
||||
$html = RenderResponseToHTML($response);
|
||||
|
||||
$html_file_name = GetTaskHTMLFIlename($task);
|
||||
file_put_contents($html_file_name, $html);
|
||||
|
||||
$info->title = $task->getTitle();
|
||||
$info->page_title = $response->getTitle();
|
||||
$info->hash = GetTaskHash($task);
|
||||
|
||||
$info->SaveToFile($info_file_name);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Baking main loop.
|
||||
|
||||
@@ -337,4 +465,16 @@ foreach ($revisions as $revision_id => $revision) {
|
||||
}
|
||||
}
|
||||
|
||||
print("\n");
|
||||
print('Querying maniphest tasks from the database ... ' . "\n");
|
||||
$tasks = id(new ManiphestTaskQuery())
|
||||
->setViewer($viewer)
|
||||
->setOrder('oldest')
|
||||
->execute();
|
||||
|
||||
foreach ($tasks as $task_id => $task) {
|
||||
EnsureTaskOutputDirectory($task);
|
||||
BakeTask($task);
|
||||
}
|
||||
|
||||
?>
|
@@ -210,7 +210,8 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||
$view = id(new PHUIHeaderView())
|
||||
->setHeader($task->getTitle())
|
||||
->setUser($this->getRequest()->getUser())
|
||||
->setPolicyObject($task);
|
||||
// ->setPolicyObject($task)
|
||||
;
|
||||
|
||||
$priority_name = ManiphestTaskPriority::getTaskPriorityName(
|
||||
$task->getPriority());
|
||||
@@ -271,6 +272,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||
|
||||
$curtain = $this->newCurtainView($task);
|
||||
|
||||
/*
|
||||
$curtain->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Edit Task'))
|
||||
@@ -278,6 +280,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||
->setHref($this->getApplicationURI("/task/edit/{$id}/"))
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow($workflow_edit));
|
||||
*/
|
||||
|
||||
$subtype_map = $task->newEditEngineSubtypeMap();
|
||||
$subtask_options = $subtype_map->getCreateFormsForSubtype(
|
||||
@@ -325,16 +328,20 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||
ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY,
|
||||
);
|
||||
|
||||
/*
|
||||
$task_submenu = $relationship_list->newActionSubmenu($submenu_actions)
|
||||
->setName(pht('Edit Related Tasks...'))
|
||||
->setIcon('fa-anchor');
|
||||
|
||||
$curtain->addAction($task_submenu);
|
||||
*/
|
||||
|
||||
/*
|
||||
$relationship_submenu = $relationship_list->newActionMenu();
|
||||
if ($relationship_submenu) {
|
||||
$curtain->addAction($relationship_submenu);
|
||||
}
|
||||
*/
|
||||
|
||||
$viewer_phid = $viewer->getPHID();
|
||||
$owner_phid = $task->getOwnerPHID();
|
||||
|
@@ -36,7 +36,7 @@ final class ManiphestTaskPHIDType extends PhabricatorPHIDType {
|
||||
|
||||
$handle->setName("T{$id}");
|
||||
$handle->setFullName("T{$id}: {$title}");
|
||||
$handle->setURI("/T{$id}");
|
||||
$handle->setURI($task->getURI());
|
||||
|
||||
if ($task->isClosed()) {
|
||||
$handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED);
|
||||
|
@@ -193,7 +193,8 @@ final class ManiphestTask extends ManiphestDAO
|
||||
}
|
||||
|
||||
public function getURI() {
|
||||
return '/'.$this->getMonogram();
|
||||
$subpath = SubpathFromId($this->getID());
|
||||
return '../../../maniphest/' . $subpath . '/T' . $this->getID();
|
||||
}
|
||||
|
||||
public function attachGroupByProjectPHID($phid) {
|
||||
|
@@ -150,7 +150,8 @@ final class PhabricatorObjectHandle
|
||||
if ($type == 'TASK') {
|
||||
// XXX: Use real link to gitea task
|
||||
// At least for now rely on the existence of the manip[hest task redirector.
|
||||
return 'https://developer.blender.org' . $this->uri;
|
||||
// return 'https://developer.blender.org' . $this->uri;
|
||||
return $this->uri;
|
||||
} else if ($type == 'DREV' || $type == 'DIFF' || $type == 'PSTE' || $type == 'FILE') {
|
||||
return $this->uri;
|
||||
}
|
||||
|
Reference in New Issue
Block a user