1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-13 02:12:41 +01:00

Ask for lint and unit excuses asynchronously

Summary: This diff obsoletes D3385.

Test Plan: Made lint error, explained it, verified that unit already finished before I finished explaining (by adding `sleep(3)` to test).

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3786
This commit is contained in:
vrana 2012-10-22 14:46:31 -07:00
parent 1b51b74135
commit 0b02170723

View file

@ -31,8 +31,7 @@ final class ArcanistDiffWorkflow extends ArcanistBaseWorkflow {
private $console; private $console;
private $hasWarnedExternals = false; private $hasWarnedExternals = false;
private $unresolvedLint; private $unresolvedLint;
private $lintExcuse; private $excuses = array('lint' => null, 'unit' => null);
private $unitExcuse;
private $testResults; private $testResults;
private $diffID; private $diffID;
private $revisionID; private $revisionID;
@ -417,6 +416,7 @@ EOTEXT
if ($background) { if ($background) {
$server = new PhutilConsoleServer(); $server = new PhutilConsoleServer();
$server->addExecFutureClient($lint_unit); $server->addExecFutureClient($lint_unit);
$server->setHandler(array($this, 'handleServerMessage'));
$server->run(); $server->run();
list($err) = $lint_unit->resolve(); list($err) = $lint_unit->resolve();
@ -425,14 +425,14 @@ EOTEXT
return 1; return 1;
} }
} else { } else {
$server = $this->console->getServer();
$server->setHandler(array($this, 'handleServerMessage'));
$data = $this->runLintUnit(); $data = $this->runLintUnit();
} }
$lint_result = $data['lintResult']; $lint_result = $data['lintResult'];
$this->lintExcuse = $data['lintExcuse'];
$this->unresolvedLint = $data['unresolvedLint']; $this->unresolvedLint = $data['unresolvedLint'];
$this->postponedLinters = $data['postponedLinters']; $this->postponedLinters = $data['postponedLinters'];
$unit_result = $data['unitResult']; $unit_result = $data['unitResult'];
$this->unitExcuse = $data['unitExcuse'];
$this->testResults = $data['testResults']; $this->testResults = $data['testResults'];
$changes = $this->generateChanges(); $changes = $this->generateChanges();
@ -1203,11 +1203,9 @@ EOTEXT
$unit_result = $this->runUnit(); $unit_result = $this->runUnit();
return array( return array(
'lintResult' => $lint_result, 'lintResult' => $lint_result,
'lintExcuse' => $this->lintExcuse,
'unresolvedLint' => $this->unresolvedLint, 'unresolvedLint' => $this->unresolvedLint,
'postponedLinters' => $this->postponedLinters, 'postponedLinters' => $this->postponedLinters,
'unitResult' => $unit_result, 'unitResult' => $unit_result,
'unitExcuse' => $this->unitExcuse,
'testResults' => $this->testResults, 'testResults' => $this->testResults,
); );
} }
@ -1248,14 +1246,16 @@ EOTEXT
"<bg:green>** LINT OKAY **</bg> No lint problems.\n"); "<bg:green>** LINT OKAY **</bg> No lint problems.\n");
break; break;
case ArcanistLintWorkflow::RESULT_WARNINGS: case ArcanistLintWorkflow::RESULT_WARNINGS:
$this->lintExcuse = $this->getErrorExcuse( $this->getErrorExcuse(
'lint',
"Lint issued unresolved warnings.", "Lint issued unresolved warnings.",
'lint-excuses'); 'lint-excuses');
break; break;
case ArcanistLintWorkflow::RESULT_ERRORS: case ArcanistLintWorkflow::RESULT_ERRORS:
$this->console->writeOut( $this->console->writeOut(
"<bg:red>** LINT ERRORS **</bg> Lint raised errors!\n"); "<bg:red>** LINT ERRORS **</bg> Lint raised errors!\n");
$this->lintExcuse = $this->getErrorExcuse( $this->getErrorExcuse(
'lint',
"Lint issued unresolved errors!", "Lint issued unresolved errors!",
'lint-excuses'); 'lint-excuses');
break; break;
@ -1336,7 +1336,8 @@ EOTEXT
case ArcanistUnitWorkflow::RESULT_FAIL: case ArcanistUnitWorkflow::RESULT_FAIL:
$this->console->writeOut( $this->console->writeOut(
"<bg:red>** UNIT ERRORS **</bg> Unit testing raised errors!\n"); "<bg:red>** UNIT ERRORS **</bg> Unit testing raised errors!\n");
$this->unitExcuse = $this->getErrorExcuse( $this->getErrorExcuse(
'unit',
"Unit test results include failures!", "Unit test results include failures!",
'unit-excuses'); 'unit-excuses');
break; break;
@ -1369,24 +1370,35 @@ EOTEXT
return $this->testResults; return $this->testResults;
} }
private function getErrorExcuse($prompt, $history) { private function getErrorExcuse($type, $prompt, $history) {
if ($this->getArgument('excuse')) { if ($this->getArgument('excuse')) {
$prompt .= " Ignore them?"; $prompt .= " Ignore them?";
if (!$this->console->confirm($prompt)) { if (!$this->console->confirm($prompt)) {
throw new ArcanistUserAbortException(); throw new ArcanistUserAbortException();
} }
return $this->getArgument('excuse'); $this->excuses[$type] = $this->getArgument('excuse');
return;
} }
$history = $this->getRepositoryAPI()->getScratchFilePath($history); $history = $this->getRepositoryAPI()->getScratchFilePath($history);
$prompt .= " Provide explanation to continue or press Enter to abort."; $prompt .= " Provide explanation to continue or press Enter to abort.";
$this->console->writeOut("\n\n%s", phutil_console_wrap($prompt)); $this->console->writeOut("\n\n%s", phutil_console_wrap($prompt));
$return = $this->console->prompt("Explanation:", $history); $this->console->sendMessage(array(
if ($return == '') { 'type' => $type,
'prompt' => "Explanation:",
'history' => $history,
));
}
public function handleServerMessage(PhutilConsoleMessage $message) {
$data = $message->getData();
$response = phutil_console_prompt($data['prompt'], idx($data, 'history'));
if ($response == '') {
throw new ArcanistUserAbortException(); throw new ArcanistUserAbortException();
} }
return $return; $this->excuses[$data['type']] = $response;
return null;
} }
@ -2229,9 +2241,9 @@ EOTEXT
if ($this->unresolvedLint) { if ($this->unresolvedLint) {
$this->updateDiffProperty('arc:lint', json_encode($this->unresolvedLint)); $this->updateDiffProperty('arc:lint', json_encode($this->unresolvedLint));
if (strlen($this->lintExcuse)) { if (strlen($this->excuses['lint'])) {
$this->updateDiffProperty('arc:lint-excuse', $this->updateDiffProperty('arc:lint-excuse',
json_encode($this->lintExcuse)); json_encode($this->excuses['lint']));
} }
} }
@ -2256,9 +2268,9 @@ EOTEXT
} }
$this->updateDiffProperty('arc:unit', json_encode($this->testResults)); $this->updateDiffProperty('arc:unit', json_encode($this->testResults));
if (strlen($this->unitExcuse)) { if (strlen($this->excuses['unit'])) {
$this->updateDiffProperty('arc:unit-excuse', $this->updateDiffProperty('arc:unit-excuse',
json_encode($this->unitExcuse)); json_encode($this->excuses['unit']));
} }
} }