Skip to content

Commit 778dfff

Browse files
author
epriestley
committed
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
1 parent a6fbde7 commit 778dfff

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

src/applications/diffusion/controller/DiffusionServeController.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,29 @@ public function handleRequest(AphrontRequest $request) {
104104
try {
105105
$remote_addr = $request->getRemoteAddress();
106106

107+
if ($request->isHTTPS()) {
108+
$remote_protocol = PhabricatorRepositoryPullEvent::PROTOCOL_HTTPS;
109+
} else {
110+
$remote_protocol = PhabricatorRepositoryPullEvent::PROTOCOL_HTTP;
111+
}
112+
107113
$pull_event = id(new PhabricatorRepositoryPullEvent())
108114
->setEpoch(PhabricatorTime::getNow())
109115
->setRemoteAddress($remote_addr)
110-
->setRemoteProtocol('http');
116+
->setRemoteProtocol($remote_protocol);
111117

112118
if ($response) {
113-
$pull_event
114-
->setResultType('wild')
115-
->setResultCode($response->getHTTPResponseCode());
119+
$response_code = $response->getHTTPResponseCode();
120+
121+
if ($response_code == 200) {
122+
$pull_event
123+
->setResultType(PhabricatorRepositoryPullEvent::RESULT_PULL)
124+
->setResultCode($response_code);
125+
} else {
126+
$pull_event
127+
->setResultType(PhabricatorRepositoryPullEvent::RESULT_ERROR)
128+
->setResultCode($response_code);
129+
}
116130

117131
if ($response instanceof PhabricatorVCSResponse) {
118132
$pull_event->setProperties(
@@ -122,7 +136,7 @@ public function handleRequest(AphrontRequest $request) {
122136
}
123137
} else {
124138
$pull_event
125-
->setResultType('exception')
139+
->setResultType(PhabricatorRepositoryPullEvent::RESULT_EXCEPTION)
126140
->setResultCode(500)
127141
->setProperties(
128142
array(

src/applications/diffusion/ssh/DiffusionGitUploadPackSSHWorkflow.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ protected function executeRepositoryOperations() {
6161

6262
if ($err) {
6363
$pull_event
64-
->setResultType('error')
64+
->setResultType(PhabricatorRepositoryPullEvent::RESULT_ERROR)
6565
->setResultCode($err);
6666
} else {
6767
$pull_event
68-
->setResultType('pull')
68+
->setResultType(PhabricatorRepositoryPullEvent::RESULT_PULL)
6969
->setResultCode(0);
7070
}
7171

src/applications/diffusion/ssh/DiffusionSSHWorkflow.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ protected function newPullEvent() {
272272
return id(new PhabricatorRepositoryPullEvent())
273273
->setEpoch(PhabricatorTime::getNow())
274274
->setRemoteAddress($remote_address)
275-
->setRemoteProtocol('ssh')
275+
->setRemoteProtocol(PhabricatorRepositoryPullEvent::PROTOCOL_SSH)
276276
->setPullerPHID($viewer->getPHID())
277277
->setRepositoryPHID($repository->getPHID());
278278
}

src/applications/diffusion/view/DiffusionPullLogListView.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function render() {
9494
pht('From'),
9595
pht('Via'),
9696
null,
97-
pht('Error'),
97+
pht('Code'),
9898
pht('Date'),
9999
))
100100
->setColumnClasses(

src/applications/repository/storage/PhabricatorRepositoryPullEvent.php

+44-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ final class PhabricatorRepositoryPullEvent
1515

1616
private $repository = self::ATTACHABLE;
1717

18+
const RESULT_PULL = 'pull';
19+
const RESULT_ERROR = 'error';
20+
const RESULT_EXCEPTION = 'exception';
21+
22+
const PROTOCOL_HTTP = 'http';
23+
const PROTOCOL_HTTPS = 'https';
24+
const PROTOCOL_SSH = 'ssh';
25+
1826
public static function initializeNewEvent(PhabricatorUser $viewer) {
1927
return id(new PhabricatorRepositoryPushEvent())
2028
->setPusherPHID($viewer->getPHID());
@@ -62,8 +70,9 @@ public function getRepository() {
6270

6371
public function getRemoteProtocolDisplayName() {
6472
$map = array(
65-
'ssh' => pht('SSH'),
66-
'http' => pht('HTTP'),
73+
self::PROTOCOL_SSH => pht('SSH'),
74+
self::PROTOCOL_HTTP => pht('HTTP'),
75+
self::PROTOCOL_HTTPS => pht('HTTPS'),
6776
);
6877

6978
$protocol = $this->getRemoteProtocol();
@@ -74,25 +83,53 @@ public function getRemoteProtocolDisplayName() {
7483
public function newResultIcon() {
7584
$icon = new PHUIIconView();
7685
$type = $this->getResultType();
86+
$code = $this->getResultCode();
87+
88+
$protocol = $this->getRemoteProtocol();
89+
90+
$is_any_http =
91+
($protocol === self::PROTOCOL_HTTP) ||
92+
($protocol === self::PROTOCOL_HTTPS);
93+
94+
// If this was an HTTP request and we responded with a 401, that means
95+
// the user didn't provide credentials. This is technically an error, but
96+
// it's routine and just causes the client to prompt them. Show a more
97+
// comforting icon and description in the UI.
98+
if ($is_any_http) {
99+
if ($code == 401) {
100+
return $icon
101+
->setIcon('fa-key blue')
102+
->setTooltip(pht('Authentication Required'));
103+
}
104+
}
77105

78106
switch ($type) {
79-
case 'wild':
107+
case self::RESULT_ERROR:
80108
$icon
81-
->setIcon('fa-question indigo')
82-
->setTooltip(pht('Unknown ("%s")', $type));
109+
->setIcon('fa-times red')
110+
->setTooltip(pht('Error'));
83111
break;
84-
case 'pull':
112+
case self::RESULT_EXCEPTION:
113+
$icon
114+
->setIcon('fa-exclamation-triangle red')
115+
->setTooltip(pht('Exception'));
116+
break;
117+
case self::RESULT_PULL:
85118
$icon
86119
->setIcon('fa-download green')
87120
->setTooltip(pht('Pull'));
88121
break;
122+
default:
123+
$icon
124+
->setIcon('fa-question indigo')
125+
->setTooltip(pht('Unknown ("%s")', $type));
126+
break;
89127
}
90128

91129
return $icon;
92130
}
93131

94132

95-
96133
/* -( PhabricatorPolicyInterface )----------------------------------------- */
97134

98135

0 commit comments

Comments
 (0)