Make minor correctness and display improvements to pull logs
Summary: Depends on D18915. Ref T13046. - Distinguish between HTTP and HTTPS. - Use more constants and fewer magical strings. - For HTTP responses, give them better type information and more helpful UI behaviors. Test Plan: Pulled over SSH and HTTP. Reviewed resulting logs from the web UI. Hit errors like missing/invalid credentials. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13046 Differential Revision: https://secure.phabricator.com/D18917
This commit is contained in:
@@ -104,15 +104,29 @@ final class DiffusionServeController extends DiffusionController {
|
|||||||
try {
|
try {
|
||||||
$remote_addr = $request->getRemoteAddress();
|
$remote_addr = $request->getRemoteAddress();
|
||||||
|
|
||||||
|
if ($request->isHTTPS()) {
|
||||||
|
$remote_protocol = PhabricatorRepositoryPullEvent::PROTOCOL_HTTPS;
|
||||||
|
} else {
|
||||||
|
$remote_protocol = PhabricatorRepositoryPullEvent::PROTOCOL_HTTP;
|
||||||
|
}
|
||||||
|
|
||||||
$pull_event = id(new PhabricatorRepositoryPullEvent())
|
$pull_event = id(new PhabricatorRepositoryPullEvent())
|
||||||
->setEpoch(PhabricatorTime::getNow())
|
->setEpoch(PhabricatorTime::getNow())
|
||||||
->setRemoteAddress($remote_addr)
|
->setRemoteAddress($remote_addr)
|
||||||
->setRemoteProtocol('http');
|
->setRemoteProtocol($remote_protocol);
|
||||||
|
|
||||||
if ($response) {
|
if ($response) {
|
||||||
$pull_event
|
$response_code = $response->getHTTPResponseCode();
|
||||||
->setResultType('wild')
|
|
||||||
->setResultCode($response->getHTTPResponseCode());
|
if ($response_code == 200) {
|
||||||
|
$pull_event
|
||||||
|
->setResultType(PhabricatorRepositoryPullEvent::RESULT_PULL)
|
||||||
|
->setResultCode($response_code);
|
||||||
|
} else {
|
||||||
|
$pull_event
|
||||||
|
->setResultType(PhabricatorRepositoryPullEvent::RESULT_ERROR)
|
||||||
|
->setResultCode($response_code);
|
||||||
|
}
|
||||||
|
|
||||||
if ($response instanceof PhabricatorVCSResponse) {
|
if ($response instanceof PhabricatorVCSResponse) {
|
||||||
$pull_event->setProperties(
|
$pull_event->setProperties(
|
||||||
@@ -122,7 +136,7 @@ final class DiffusionServeController extends DiffusionController {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$pull_event
|
$pull_event
|
||||||
->setResultType('exception')
|
->setResultType(PhabricatorRepositoryPullEvent::RESULT_EXCEPTION)
|
||||||
->setResultCode(500)
|
->setResultCode(500)
|
||||||
->setProperties(
|
->setProperties(
|
||||||
array(
|
array(
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ final class DiffusionGitUploadPackSSHWorkflow extends DiffusionGitSSHWorkflow {
|
|||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
$pull_event
|
$pull_event
|
||||||
->setResultType('error')
|
->setResultType(PhabricatorRepositoryPullEvent::RESULT_ERROR)
|
||||||
->setResultCode($err);
|
->setResultCode($err);
|
||||||
} else {
|
} else {
|
||||||
$pull_event
|
$pull_event
|
||||||
->setResultType('pull')
|
->setResultType(PhabricatorRepositoryPullEvent::RESULT_PULL)
|
||||||
->setResultCode(0);
|
->setResultCode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ abstract class DiffusionSSHWorkflow extends PhabricatorSSHWorkflow {
|
|||||||
return id(new PhabricatorRepositoryPullEvent())
|
return id(new PhabricatorRepositoryPullEvent())
|
||||||
->setEpoch(PhabricatorTime::getNow())
|
->setEpoch(PhabricatorTime::getNow())
|
||||||
->setRemoteAddress($remote_address)
|
->setRemoteAddress($remote_address)
|
||||||
->setRemoteProtocol('ssh')
|
->setRemoteProtocol(PhabricatorRepositoryPullEvent::PROTOCOL_SSH)
|
||||||
->setPullerPHID($viewer->getPHID())
|
->setPullerPHID($viewer->getPHID())
|
||||||
->setRepositoryPHID($repository->getPHID());
|
->setRepositoryPHID($repository->getPHID());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ final class DiffusionPullLogListView extends AphrontView {
|
|||||||
pht('From'),
|
pht('From'),
|
||||||
pht('Via'),
|
pht('Via'),
|
||||||
null,
|
null,
|
||||||
pht('Error'),
|
pht('Code'),
|
||||||
pht('Date'),
|
pht('Date'),
|
||||||
))
|
))
|
||||||
->setColumnClasses(
|
->setColumnClasses(
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ final class PhabricatorRepositoryPullEvent
|
|||||||
|
|
||||||
private $repository = self::ATTACHABLE;
|
private $repository = self::ATTACHABLE;
|
||||||
|
|
||||||
|
const RESULT_PULL = 'pull';
|
||||||
|
const RESULT_ERROR = 'error';
|
||||||
|
const RESULT_EXCEPTION = 'exception';
|
||||||
|
|
||||||
|
const PROTOCOL_HTTP = 'http';
|
||||||
|
const PROTOCOL_HTTPS = 'https';
|
||||||
|
const PROTOCOL_SSH = 'ssh';
|
||||||
|
|
||||||
public static function initializeNewEvent(PhabricatorUser $viewer) {
|
public static function initializeNewEvent(PhabricatorUser $viewer) {
|
||||||
return id(new PhabricatorRepositoryPushEvent())
|
return id(new PhabricatorRepositoryPushEvent())
|
||||||
->setPusherPHID($viewer->getPHID());
|
->setPusherPHID($viewer->getPHID());
|
||||||
@@ -62,8 +70,9 @@ final class PhabricatorRepositoryPullEvent
|
|||||||
|
|
||||||
public function getRemoteProtocolDisplayName() {
|
public function getRemoteProtocolDisplayName() {
|
||||||
$map = array(
|
$map = array(
|
||||||
'ssh' => pht('SSH'),
|
self::PROTOCOL_SSH => pht('SSH'),
|
||||||
'http' => pht('HTTP'),
|
self::PROTOCOL_HTTP => pht('HTTP'),
|
||||||
|
self::PROTOCOL_HTTPS => pht('HTTPS'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$protocol = $this->getRemoteProtocol();
|
$protocol = $this->getRemoteProtocol();
|
||||||
@@ -74,25 +83,53 @@ final class PhabricatorRepositoryPullEvent
|
|||||||
public function newResultIcon() {
|
public function newResultIcon() {
|
||||||
$icon = new PHUIIconView();
|
$icon = new PHUIIconView();
|
||||||
$type = $this->getResultType();
|
$type = $this->getResultType();
|
||||||
|
$code = $this->getResultCode();
|
||||||
|
|
||||||
|
$protocol = $this->getRemoteProtocol();
|
||||||
|
|
||||||
|
$is_any_http =
|
||||||
|
($protocol === self::PROTOCOL_HTTP) ||
|
||||||
|
($protocol === self::PROTOCOL_HTTPS);
|
||||||
|
|
||||||
|
// If this was an HTTP request and we responded with a 401, that means
|
||||||
|
// the user didn't provide credentials. This is technically an error, but
|
||||||
|
// it's routine and just causes the client to prompt them. Show a more
|
||||||
|
// comforting icon and description in the UI.
|
||||||
|
if ($is_any_http) {
|
||||||
|
if ($code == 401) {
|
||||||
|
return $icon
|
||||||
|
->setIcon('fa-key blue')
|
||||||
|
->setTooltip(pht('Authentication Required'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'wild':
|
case self::RESULT_ERROR:
|
||||||
$icon
|
$icon
|
||||||
->setIcon('fa-question indigo')
|
->setIcon('fa-times red')
|
||||||
->setTooltip(pht('Unknown ("%s")', $type));
|
->setTooltip(pht('Error'));
|
||||||
break;
|
break;
|
||||||
case 'pull':
|
case self::RESULT_EXCEPTION:
|
||||||
|
$icon
|
||||||
|
->setIcon('fa-exclamation-triangle red')
|
||||||
|
->setTooltip(pht('Exception'));
|
||||||
|
break;
|
||||||
|
case self::RESULT_PULL:
|
||||||
$icon
|
$icon
|
||||||
->setIcon('fa-download green')
|
->setIcon('fa-download green')
|
||||||
->setTooltip(pht('Pull'));
|
->setTooltip(pht('Pull'));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
$icon
|
||||||
|
->setIcon('fa-question indigo')
|
||||||
|
->setTooltip(pht('Unknown ("%s")', $type));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $icon;
|
return $icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user