1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Diffusion + Herald - warn users if importing repository

Summary: 'cuz things fail a bunch until importing is done. Fixes T4094.

Test Plan: set isImporting to return true. Browsed Diffusion and saw helpful warnings everywhere. Browse Herald transcript and saw a helpful warning

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T4094

Differential Revision: https://secure.phabricator.com/D8903
This commit is contained in:
Bob Trahan 2014-04-29 15:07:00 -07:00
parent 8fe27800fc
commit 7ed28dacb5
2 changed files with 92 additions and 13 deletions

View file

@ -4,6 +4,18 @@ abstract class DiffusionController extends PhabricatorController {
protected $diffusionRequest; protected $diffusionRequest;
public function setDiffusionRequest(DiffusionRequest $request) {
$this->diffusionRequest = $request;
return $this;
}
protected function getDiffusionRequest() {
if (!$this->diffusionRequest) {
throw new Exception("No Diffusion request object!");
}
return $this->diffusionRequest;
}
public function willBeginExecution() { public function willBeginExecution() {
$request = $this->getRequest(); $request = $this->getRequest();
@ -24,20 +36,26 @@ abstract class DiffusionController extends PhabricatorController {
$drequest = DiffusionRequest::newFromAphrontRequestDictionary( $drequest = DiffusionRequest::newFromAphrontRequestDictionary(
$data, $data,
$this->getRequest()); $this->getRequest());
$this->diffusionRequest = $drequest; $this->setDiffusionRequest($drequest);
} }
} }
public function setDiffusionRequest(DiffusionRequest $request) { public function buildApplicationPage($view, array $options) {
$this->diffusionRequest = $request; $drequest = $this->getDiffusionRequest();
return $this; $repository = $drequest->getRepository();
} $error_view = $this->buildRepositoryWarning($repository);
protected function getDiffusionRequest() { $views = array();
if (!$this->diffusionRequest) { $not_inserted = true;
throw new Exception("No Diffusion request object!"); foreach ($view as $view_object_or_array) {
$views[] = $view_object_or_array;
if ($not_inserted &&
$view_object_or_array instanceof PhabricatorCrumbsView) {
$views[] = $error_view;
$not_inserted = false;
}
} }
return $this->diffusionRequest; return parent::buildApplicationPage($views, $options);
} }
public function buildCrumbs(array $spec = array()) { public function buildCrumbs(array $spec = array()) {
@ -235,4 +253,22 @@ abstract class DiffusionController extends PhabricatorController {
->appendChild($body); ->appendChild($body);
} }
private function buildRepositoryWarning(PhabricatorRepository $repository) {
$error_view = null;
if ($repository->isImporting()) {
$title = pht('This repository is still importing.');
$body = pht('Things may not work properly until the import finishes.');
} else if (!$repository->isTracked()) {
$title = pht('This repository is not tracked.');
$body = pht(
'Things may not work properly until tracking is enabled and '.
'importing finishes.');
}
if ($title) {
$error_view = $this->renderStatusMessage($title, $body);
}
return $error_view;
}
} }

View file

@ -83,6 +83,9 @@ final class HeraldTranscriptController extends HeraldController {
$nav->appendChild($notice); $nav->appendChild($notice);
} }
$warning_panel = $this->buildWarningPanel($xscript);
$nav->appendChild($warning_panel);
$apply_xscript_panel = $this->buildApplyTranscriptPanel( $apply_xscript_panel = $this->buildApplyTranscriptPanel(
$xscript); $xscript);
$nav->appendChild($apply_xscript_panel); $nav->appendChild($apply_xscript_panel);
@ -287,7 +290,47 @@ final class HeraldTranscriptController extends HeraldController {
$keep_rule_xscripts)); $keep_rule_xscripts));
} }
private function buildApplyTranscriptPanel($xscript) { private function buildWarningPanel(HeraldTranscript $xscript) {
$request = $this->getRequest();
$panel = null;
if ($xscript->getObjectTranscript()) {
$handles = $this->handles;
$object_xscript = $xscript->getObjectTranscript();
$handle = $handles[$object_xscript->getPHID()];
if ($handle->getType() ==
PhabricatorRepositoryPHIDTypeCommit::TYPECONST) {
$commit = id(new DiffusionCommitQuery())
->setViewer($request->getUser())
->withPHIDs(array($handle->getPHID()))
->executeOne();
if ($commit) {
$repository = $commit->getRepository();
if ($repository->isImporting()) {
$title = pht(
'The %s repository is still importing.',
$repository->getMonogram());
$body = pht(
'Herald rules will not trigger until import completes.');
} else if (!$repository->isTracked()) {
$title = pht(
'The %s repository is not tracked.',
$repository->getMonogram());
$body = pht(
'Herald rules will not trigger until tracking is enabled.');
} else {
return $panel;
}
$panel = id(new AphrontErrorView())
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
->setTitle($title)
->appendChild($body);
}
}
}
return $panel;
}
private function buildApplyTranscriptPanel(HeraldTranscript $xscript) {
$handles = $this->handles; $handles = $this->handles;
$adapter = $this->getAdapter(); $adapter = $this->getAdapter();
@ -350,7 +393,7 @@ final class HeraldTranscriptController extends HeraldController {
return $box; return $box;
} }
private function buildActionTranscriptPanel($xscript) { private function buildActionTranscriptPanel(HeraldTranscript $xscript) {
$action_xscript = mgroup($xscript->getApplyTranscripts(), 'getRuleID'); $action_xscript = mgroup($xscript->getApplyTranscripts(), 'getRuleID');
$adapter = $this->getAdapter(); $adapter = $this->getAdapter();
@ -442,7 +485,7 @@ final class HeraldTranscriptController extends HeraldController {
return $box; return $box;
} }
private function buildObjectTranscriptPanel($xscript) { private function buildObjectTranscriptPanel(HeraldTranscript $xscript) {
$adapter = $this->getAdapter(); $adapter = $this->getAdapter();
$field_names = $adapter->getFieldNameMap(); $field_names = $adapter->getFieldNameMap();
@ -452,7 +495,7 @@ final class HeraldTranscriptController extends HeraldController {
$data = array(); $data = array();
if ($object_xscript) { if ($object_xscript) {
$phid = $object_xscript->getPHID(); $phid = $object_xscript->getPHID();
$handles = $this->loadViewerHandles(array($phid)); $handles = $this->handles;
$data += array( $data += array(
pht('Object Name') => $object_xscript->getName(), pht('Object Name') => $object_xscript->getName(),