3 final class PhabricatorRepositoryPullEvent
4 extends PhabricatorRepositoryDAO
5 implements PhabricatorPolicyInterface
{
7 protected $repositoryPHID;
10 protected $remoteAddress;
11 protected $remoteProtocol;
12 protected $resultType;
13 protected $resultCode;
14 protected $properties;
16 private $repository = self
::ATTACHABLE
;
18 const RESULT_PULL
= 'pull';
19 const RESULT_ERROR
= 'error';
20 const RESULT_EXCEPTION
= 'exception';
22 const PROTOCOL_HTTP
= 'http';
23 const PROTOCOL_HTTPS
= 'https';
24 const PROTOCOL_SSH
= 'ssh';
26 public static function initializeNewEvent(PhabricatorUser
$viewer) {
27 return id(new PhabricatorRepositoryPushEvent())
28 ->setPusherPHID($viewer->getPHID());
31 protected function getConfiguration() {
33 self
::CONFIG_AUX_PHID
=> true,
34 self
::CONFIG_TIMESTAMPS
=> false,
35 self
::CONFIG_SERIALIZATION
=> array(
36 'properties' => self
::SERIALIZATION_JSON
,
38 self
::CONFIG_COLUMN_SCHEMA
=> array(
39 'repositoryPHID' => 'phid?',
40 'pullerPHID' => 'phid?',
41 'remoteAddress' => 'ipaddress?',
42 'remoteProtocol' => 'text32?',
43 'resultType' => 'text32',
44 'resultCode' => 'uint32',
46 self
::CONFIG_KEY_SCHEMA
=> array(
47 'key_repository' => array(
48 'columns' => array('repositoryPHID'),
51 'columns' => array('epoch'),
54 ) + parent
::getConfiguration();
57 public function generatePHID() {
58 return PhabricatorPHID
::generateNewPHID(
59 PhabricatorRepositoryPullEventPHIDType
::TYPECONST
);
62 public function attachRepository(PhabricatorRepository
$repository = null) {
63 $this->repository
= $repository;
67 public function getRepository() {
68 return $this->assertAttached($this->repository
);
71 public function getRemoteProtocolDisplayName() {
73 self
::PROTOCOL_SSH
=> pht('SSH'),
74 self
::PROTOCOL_HTTP
=> pht('HTTP'),
75 self
::PROTOCOL_HTTPS
=> pht('HTTPS'),
78 $protocol = $this->getRemoteProtocol();
80 return idx($map, $protocol, $protocol);
83 public function newResultIcon() {
84 $icon = new PHUIIconView();
85 $type = $this->getResultType();
86 $code = $this->getResultCode();
88 $protocol = $this->getRemoteProtocol();
91 ($protocol === self
::PROTOCOL_HTTP
) ||
92 ($protocol === self
::PROTOCOL_HTTPS
);
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.
101 ->setIcon('fa-key blue')
102 ->setTooltip(pht('Authentication Required'));
107 case self
::RESULT_ERROR
:
109 ->setIcon('fa-times red')
110 ->setTooltip(pht('Error'));
112 case self
::RESULT_EXCEPTION
:
114 ->setIcon('fa-exclamation-triangle red')
115 ->setTooltip(pht('Exception'));
117 case self
::RESULT_PULL
:
119 ->setIcon('fa-download green')
120 ->setTooltip(pht('Pull'));
124 ->setIcon('fa-question indigo')
125 ->setTooltip(pht('Unknown ("%s")', $type));
133 /* -( PhabricatorPolicyInterface )----------------------------------------- */
136 public function getCapabilities() {
138 PhabricatorPolicyCapability
::CAN_VIEW
,
142 public function getPolicy($capability) {
143 if ($this->getRepository()) {
144 return $this->getRepository()->getPolicy($capability);
147 return PhabricatorPolicies
::POLICY_ADMIN
;
150 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
151 if (!$this->getRepository()) {
155 return $this->getRepository()->hasAutomaticCapability($capability, $viewer);
158 public function describeAutomaticCapability($capability) {
160 "A repository's pull events are visible to users who can see the ".