@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 159 lines 4.5 kB view raw
1<?php 2 3final class HarbormasterBuildLintMessage 4 extends HarbormasterDAO { 5 6 protected $buildTargetPHID; 7 protected $path; 8 protected $line; 9 protected $characterOffset; 10 protected $code; 11 protected $severity; 12 protected $name; 13 protected $properties = array(); 14 15 private $buildTarget = self::ATTACHABLE; 16 17 public static function initializeNewLintMessage( 18 HarbormasterBuildTarget $build_target) { 19 return id(new HarbormasterBuildLintMessage()) 20 ->setBuildTargetPHID($build_target->getPHID()); 21 } 22 23 public static function getParameterSpec() { 24 return array( 25 'name' => array( 26 'type' => 'string', 27 'description' => pht( 28 'Short message name, like "Syntax Error".'), 29 ), 30 'code' => array( 31 'type' => 'string', 32 'description' => pht( 33 'Lint message code identifying the type of message, like "ERR123".'), 34 ), 35 'severity' => array( 36 'type' => 'string', 37 'description' => pht( 38 'Severity of the message.'), 39 ), 40 'path' => array( 41 'type' => 'string', 42 'description' => pht( 43 'Path to the file containing the lint message, from the project '. 44 'root.'), 45 ), 46 'line' => array( 47 'type' => 'optional int', 48 'description' => pht( 49 'Line number in the file where the text which triggered the '. 50 'message first appears. The first line of the file is line 1, '. 51 'not line 0.'), 52 ), 53 'char' => array( 54 'type' => 'optional int', 55 'description' => pht( 56 'Byte position on the line where the text which triggered the '. 57 'message starts. The first byte on the line is byte 1, not byte '. 58 '0. This position is byte-based (not character-based) because '. 59 'not all lintable files have a valid character encoding.'), 60 ), 61 'description' => array( 62 'type' => 'optional string', 63 'description' => pht( 64 'Long explanation of the lint message.'), 65 ), 66 ); 67 } 68 69 public static function newFromDictionary( 70 HarbormasterBuildTarget $build_target, 71 array $dict) { 72 73 $obj = self::initializeNewLintMessage($build_target); 74 75 $spec = self::getParameterSpec(); 76 $spec = ipull($spec, 'type'); 77 78 // We're just going to ignore extra keys for now, to make it easier to 79 // add stuff here later on. 80 $dict = array_select_keys($dict, array_keys($spec)); 81 PhutilTypeSpec::checkMap($dict, $spec); 82 83 $obj->setPath($dict['path']); 84 $obj->setLine(idx($dict, 'line')); 85 $obj->setCharacterOffset(idx($dict, 'char')); 86 $obj->setCode($dict['code']); 87 $obj->setSeverity($dict['severity']); 88 $obj->setName($dict['name']); 89 90 $description = idx($dict, 'description'); 91 if (strlen($description)) { 92 $obj->setProperty('description', $description); 93 } 94 95 return $obj; 96 } 97 98 protected function getConfiguration() { 99 return array( 100 self::CONFIG_SERIALIZATION => array( 101 'properties' => self::SERIALIZATION_JSON, 102 ), 103 self::CONFIG_COLUMN_SCHEMA => array( 104 'path' => 'text', 105 'line' => 'uint32?', 106 'characterOffset' => 'uint32?', 107 'code' => 'text128', 108 'severity' => 'text32', 109 'name' => 'text255', 110 ), 111 self::CONFIG_KEY_SCHEMA => array( 112 'key_target' => array( 113 'columns' => array('buildTargetPHID'), 114 ), 115 ), 116 ) + parent::getConfiguration(); 117 } 118 119 public function attachBuildTarget(HarbormasterBuildTarget $build_target) { 120 $this->buildTarget = $build_target; 121 return $this; 122 } 123 124 public function getBuildTarget() { 125 return $this->assertAttached($this->buildTarget); 126 } 127 128 public function getProperty($key, $default = null) { 129 return idx($this->properties, $key, $default); 130 } 131 132 public function setProperty($key, $value) { 133 $this->properties[$key] = $value; 134 return $this; 135 } 136 137 public function getSortKey() { 138 // TODO: Maybe use more numeric values after T6861. 139 $map = array( 140 ArcanistLintSeverity::SEVERITY_ERROR => 'A', 141 ArcanistLintSeverity::SEVERITY_WARNING => 'B', 142 ArcanistLintSeverity::SEVERITY_AUTOFIX => 'C', 143 ArcanistLintSeverity::SEVERITY_ADVICE => 'Y', 144 ArcanistLintSeverity::SEVERITY_DISABLED => 'Z', 145 ); 146 147 $severity = idx($map, $this->getSeverity(), 'N'); 148 149 $parts = array( 150 $severity, 151 $this->getPath(), 152 sprintf('%08d', $this->getLine()), 153 $this->getCode(), 154 ); 155 156 return implode("\0", $parts); 157 } 158 159}