@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+67 -16
+19 -5
src/applications/diffusion/controller/DiffusionServeController.php
··· 104 104 try { 105 105 $remote_addr = $request->getRemoteAddress(); 106 106 107 + if ($request->isHTTPS()) { 108 + $remote_protocol = PhabricatorRepositoryPullEvent::PROTOCOL_HTTPS; 109 + } else { 110 + $remote_protocol = PhabricatorRepositoryPullEvent::PROTOCOL_HTTP; 111 + } 112 + 107 113 $pull_event = id(new PhabricatorRepositoryPullEvent()) 108 114 ->setEpoch(PhabricatorTime::getNow()) 109 115 ->setRemoteAddress($remote_addr) 110 - ->setRemoteProtocol('http'); 116 + ->setRemoteProtocol($remote_protocol); 111 117 112 118 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 + } 116 130 117 131 if ($response instanceof PhabricatorVCSResponse) { 118 132 $pull_event->setProperties( ··· 122 136 } 123 137 } else { 124 138 $pull_event 125 - ->setResultType('exception') 139 + ->setResultType(PhabricatorRepositoryPullEvent::RESULT_EXCEPTION) 126 140 ->setResultCode(500) 127 141 ->setProperties( 128 142 array(
+2 -2
src/applications/diffusion/ssh/DiffusionGitUploadPackSSHWorkflow.php
··· 61 61 62 62 if ($err) { 63 63 $pull_event 64 - ->setResultType('error') 64 + ->setResultType(PhabricatorRepositoryPullEvent::RESULT_ERROR) 65 65 ->setResultCode($err); 66 66 } else { 67 67 $pull_event 68 - ->setResultType('pull') 68 + ->setResultType(PhabricatorRepositoryPullEvent::RESULT_PULL) 69 69 ->setResultCode(0); 70 70 } 71 71
+1 -1
src/applications/diffusion/ssh/DiffusionSSHWorkflow.php
··· 272 272 return id(new PhabricatorRepositoryPullEvent()) 273 273 ->setEpoch(PhabricatorTime::getNow()) 274 274 ->setRemoteAddress($remote_address) 275 - ->setRemoteProtocol('ssh') 275 + ->setRemoteProtocol(PhabricatorRepositoryPullEvent::PROTOCOL_SSH) 276 276 ->setPullerPHID($viewer->getPHID()) 277 277 ->setRepositoryPHID($repository->getPHID()); 278 278 }
+1 -1
src/applications/diffusion/view/DiffusionPullLogListView.php
··· 94 94 pht('From'), 95 95 pht('Via'), 96 96 null, 97 - pht('Error'), 97 + pht('Code'), 98 98 pht('Date'), 99 99 )) 100 100 ->setColumnClasses(
+44 -7
src/applications/repository/storage/PhabricatorRepositoryPullEvent.php
··· 15 15 16 16 private $repository = self::ATTACHABLE; 17 17 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 + 18 26 public static function initializeNewEvent(PhabricatorUser $viewer) { 19 27 return id(new PhabricatorRepositoryPushEvent()) 20 28 ->setPusherPHID($viewer->getPHID()); ··· 62 70 63 71 public function getRemoteProtocolDisplayName() { 64 72 $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'), 67 76 ); 68 77 69 78 $protocol = $this->getRemoteProtocol(); ··· 74 83 public function newResultIcon() { 75 84 $icon = new PHUIIconView(); 76 85 $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 + } 77 105 78 106 switch ($type) { 79 - case 'wild': 107 + case self::RESULT_ERROR: 108 + $icon 109 + ->setIcon('fa-times red') 110 + ->setTooltip(pht('Error')); 111 + break; 112 + case self::RESULT_EXCEPTION: 80 113 $icon 81 - ->setIcon('fa-question indigo') 82 - ->setTooltip(pht('Unknown ("%s")', $type)); 114 + ->setIcon('fa-exclamation-triangle red') 115 + ->setTooltip(pht('Exception')); 83 116 break; 84 - case 'pull': 117 + case self::RESULT_PULL: 85 118 $icon 86 119 ->setIcon('fa-download green') 87 120 ->setTooltip(pht('Pull')); 88 121 break; 122 + default: 123 + $icon 124 + ->setIcon('fa-question indigo') 125 + ->setTooltip(pht('Unknown ("%s")', $type)); 126 + break; 89 127 } 90 128 91 129 return $icon; 92 130 } 93 - 94 131 95 132 96 133 /* -( PhabricatorPolicyInterface )----------------------------------------- */