@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 120 lines 3.2 kB view raw
1<?php 2 3final class HarbormasterURIArtifact extends HarbormasterArtifact { 4 5 const ARTIFACTCONST = 'uri'; 6 7 public function getArtifactTypeName() { 8 return pht('URI'); 9 } 10 11 public function getArtifactTypeSummary() { 12 return pht('Stores a URI.'); 13 } 14 15 public function getArtifactTypeDescription() { 16 return pht( 17 "Stores a URI.\n\n". 18 "With `ui.external`, you can use this artifact type to add links to ". 19 "build results in an external build system."); 20 } 21 22 public function getArtifactParameterSpecification() { 23 return array( 24 'uri' => 'string', 25 'name' => 'optional string', 26 'ui.external' => 'optional bool', 27 ); 28 } 29 30 public function readArtifactHTTPParameter($key, $value) { 31 // TODO: This is hacky and artifact parameters should be replaced more 32 // broadly, likely with EditFields. See T11887. 33 switch ($key) { 34 case 'ui.external': 35 return (bool)$value; 36 } 37 return $value; 38 } 39 40 public function getArtifactParameterDescriptions() { 41 return array( 42 'uri' => pht('The URI to store.'), 43 'name' => pht('Optional label for this URI.'), 44 'ui.external' => pht( 45 'If true, display this URI in the UI as an link to '. 46 'additional build details in an external build system.'), 47 ); 48 } 49 50 public function getArtifactDataExample() { 51 return array( 52 'uri' => 'https://buildserver.mycompany.com/build/123/', 53 'name' => pht('View External Build Results'), 54 'ui.external' => true, 55 ); 56 } 57 58 public function renderArtifactSummary(PhabricatorUser $viewer) { 59 return $this->renderLink(); 60 } 61 62 public function isExternalLink() { 63 $artifact = $this->getBuildArtifact(); 64 return (bool)$artifact->getProperty('ui.external', false); 65 } 66 67 public function renderLink() { 68 $artifact = $this->getBuildArtifact(); 69 $uri = $artifact->getProperty('uri'); 70 71 try { 72 $this->validateURI($uri); 73 } catch (Exception $ex) { 74 return pht('<Invalid URI>'); 75 } 76 77 $name = $artifact->getProperty('name', $uri); 78 79 return phutil_tag( 80 'a', 81 array( 82 'href' => $uri, 83 'target' => '_blank', 84 'rel' => 'noreferrer', 85 ), 86 $name); 87 } 88 89 public function willCreateArtifact(PhabricatorUser $actor) { 90 $artifact = $this->getBuildArtifact(); 91 $uri = $artifact->getProperty('uri'); 92 $this->validateURI($uri); 93 } 94 95 private function validateURI($raw_uri) { 96 $uri = new PhutilURI($raw_uri); 97 98 $protocol = $uri->getProtocol(); 99 if (!strlen($protocol)) { 100 throw new Exception( 101 pht( 102 'Unable to identify the protocol for URI "%s". URIs must be '. 103 'fully qualified and have an identifiable protocol.', 104 $raw_uri)); 105 } 106 107 $protocol_key = 'uri.allowed-protocols'; 108 $protocols = PhabricatorEnv::getEnvConfig($protocol_key); 109 if (empty($protocols[$protocol])) { 110 throw new Exception( 111 pht( 112 'URI "%s" does not have an allowable protocol. Configure '. 113 'protocols in `%s`. Allowed protocols are: %s.', 114 $raw_uri, 115 $protocol_key, 116 implode(', ', array_keys($protocols)))); 117 } 118 } 119 120}