@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.

at recaptime-dev/main 164 lines 4.4 kB view raw
1<?php 2 3final class PhabricatorRepositoryPullEvent 4 extends PhabricatorRepositoryDAO 5 implements PhabricatorPolicyInterface { 6 7 protected $repositoryPHID; 8 protected $epoch; 9 protected $pullerPHID; 10 protected $remoteAddress; 11 protected $remoteProtocol; 12 protected $resultType; 13 protected $resultCode; 14 protected $properties; 15 16 private $repository = self::ATTACHABLE; 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 26 public static function initializeNewEvent(PhabricatorUser $viewer) { 27 return id(new PhabricatorRepositoryPushEvent()) 28 ->setPusherPHID($viewer->getPHID()); 29 } 30 31 protected function getConfiguration() { 32 return array( 33 self::CONFIG_AUX_PHID => true, 34 self::CONFIG_TIMESTAMPS => false, 35 self::CONFIG_SERIALIZATION => array( 36 'properties' => self::SERIALIZATION_JSON, 37 ), 38 self::CONFIG_COLUMN_SCHEMA => array( 39 'repositoryPHID' => 'phid?', 40 'pullerPHID' => 'phid?', 41 'remoteAddress' => 'ipaddress?', 42 'remoteProtocol' => 'text32?', 43 'resultType' => 'text32', 44 'resultCode' => 'uint32', 45 ), 46 self::CONFIG_KEY_SCHEMA => array( 47 'key_repository' => array( 48 'columns' => array('repositoryPHID'), 49 ), 50 'key_epoch' => array( 51 'columns' => array('epoch'), 52 ), 53 ), 54 ) + parent::getConfiguration(); 55 } 56 57 public function generatePHID() { 58 return PhabricatorPHID::generateNewPHID( 59 PhabricatorRepositoryPullEventPHIDType::TYPECONST); 60 } 61 62 public function attachRepository(?PhabricatorRepository $repository = null) { 63 $this->repository = $repository; 64 return $this; 65 } 66 67 public function getRepository() { 68 return $this->assertAttached($this->repository); 69 } 70 71 public function getRemoteProtocolDisplayName() { 72 $map = array( 73 self::PROTOCOL_SSH => pht('SSH'), 74 self::PROTOCOL_HTTP => pht('HTTP'), 75 self::PROTOCOL_HTTPS => pht('HTTPS'), 76 ); 77 78 $protocol = $this->getRemoteProtocol(); 79 80 return idx($map, $protocol, $protocol); 81 } 82 83 public function newResultIcon() { 84 $icon = new PHUIIconView(); 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 } 105 106 switch ($type) { 107 case self::RESULT_ERROR: 108 $icon 109 ->setIcon('fa-times red') 110 ->setTooltip(pht('Error')); 111 break; 112 case self::RESULT_EXCEPTION: 113 $icon 114 ->setIcon('fa-exclamation-triangle red') 115 ->setTooltip(pht('Exception')); 116 break; 117 case self::RESULT_PULL: 118 $icon 119 ->setIcon('fa-download green') 120 ->setTooltip(pht('Pull')); 121 break; 122 default: 123 $icon 124 ->setIcon('fa-question indigo') 125 ->setTooltip(pht('Unknown ("%s")', $type)); 126 break; 127 } 128 129 return $icon; 130 } 131 132 133/* -( PhabricatorPolicyInterface )----------------------------------------- */ 134 135 136 public function getCapabilities() { 137 return array( 138 PhabricatorPolicyCapability::CAN_VIEW, 139 ); 140 } 141 142 public function getPolicy($capability) { 143 if ($this->getRepository()) { 144 return $this->getRepository()->getPolicy($capability); 145 } 146 147 return PhabricatorPolicies::POLICY_ADMIN; 148 } 149 150 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 151 if (!$this->getRepository()) { 152 return false; 153 } 154 155 return $this->getRepository()->hasAutomaticCapability($capability, $viewer); 156 } 157 158 public function describeAutomaticCapability($capability) { 159 return pht( 160 "A repository's pull events are visible to users who can see the ". 161 "repository."); 162 } 163 164}