3 final class HarbormasterURIArtifact
extends HarbormasterArtifact
{
5 const ARTIFACTCONST
= 'uri';
7 public function getArtifactTypeName() {
11 public function getArtifactTypeSummary() {
12 return pht('Stores a URI.');
15 public function getArtifactTypeDescription() {
18 "With `ui.external`, you can use this artifact type to add links to ".
19 "build results in an external build system.");
22 public function getArtifactParameterSpecification() {
25 'name' => 'optional string',
26 'ui.external' => 'optional bool',
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.
40 public function getArtifactParameterDescriptions() {
42 'uri' => pht('The URI to store.'),
43 'name' => pht('Optional label for this URI.'),
45 'If true, display this URI in the UI as an link to '.
46 'additional build details in an external build system.'),
50 public function getArtifactDataExample() {
52 'uri' => 'https://buildserver.mycompany.com/build/123/',
53 'name' => pht('View External Build Results'),
54 'ui.external' => true,
58 public function renderArtifactSummary(PhabricatorUser
$viewer) {
59 return $this->renderLink();
62 public function isExternalLink() {
63 $artifact = $this->getBuildArtifact();
64 return (bool)$artifact->getProperty('ui.external', false);
67 public function renderLink() {
68 $artifact = $this->getBuildArtifact();
69 $uri = $artifact->getProperty('uri');
72 $this->validateURI($uri);
73 } catch (Exception
$ex) {
74 return pht('<Invalid URI>');
77 $name = $artifact->getProperty('name', $uri);
84 'rel' => 'noreferrer',
89 public function willCreateArtifact(PhabricatorUser
$actor) {
90 $artifact = $this->getBuildArtifact();
91 $uri = $artifact->getProperty('uri');
92 $this->validateURI($uri);
95 private function validateURI($raw_uri) {
96 $uri = new PhutilURI($raw_uri);
98 $protocol = $uri->getProtocol();
99 if (!strlen($protocol)) {
102 'Unable to identify the protocol for URI "%s". URIs must be '.
103 'fully qualified and have an identifiable protocol.',
107 $protocol_key = 'uri.allowed-protocols';
108 $protocols = PhabricatorEnv
::getEnvConfig($protocol_key);
109 if (empty($protocols[$protocol])) {
112 'URI "%s" does not have an allowable protocol. Configure '.
113 'protocols in `%s`. Allowed protocols are: %s.',
116 implode(', ', array_keys($protocols))));