@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 191 lines 4.8 kB view raw
1<?php 2 3final class PhabricatorRepositoryCommitData extends PhabricatorRepositoryDAO { 4 5 protected $commitID; 6 protected $authorName = ''; 7 protected $commitMessage = ''; 8 protected $commitDetails = array(); 9 private $commitRef; 10 11 protected function getConfiguration() { 12 return array( 13 self::CONFIG_TIMESTAMPS => false, 14 self::CONFIG_SERIALIZATION => array( 15 'commitDetails' => self::SERIALIZATION_JSON, 16 ), 17 self::CONFIG_COLUMN_SCHEMA => array( 18 'authorName' => 'text', 19 'commitMessage' => 'text', 20 ), 21 self::CONFIG_KEY_SCHEMA => array( 22 'commitID' => array( 23 'columns' => array('commitID'), 24 'unique' => true, 25 ), 26 ), 27 ) + parent::getConfiguration(); 28 } 29 30 public function getSummary() { 31 $message = $this->getCommitMessage(); 32 return self::summarizeCommitMessage($message); 33 } 34 35 public static function summarizeCommitMessage($message) { 36 $max_bytes = id(new PhabricatorRepositoryCommit()) 37 ->getColumnMaximumByteLength('summary'); 38 39 $summary = phutil_split_lines($message, $retain_endings = false); 40 $summary = head($summary); 41 $summary = id(new PhutilUTF8StringTruncator()) 42 ->setMaximumBytes($max_bytes) 43 ->setMaximumGlyphs(80) 44 ->truncateString($summary); 45 46 return $summary; 47 } 48 49 public function getCommitDetail($key, $default = null) { 50 return idx($this->commitDetails, $key, $default); 51 } 52 53 public function setCommitDetail($key, $value) { 54 $this->commitDetails[$key] = $value; 55 return $this; 56 } 57 58 public function toDictionary() { 59 return array( 60 'commitID' => $this->commitID, 61 'authorName' => $this->authorName, 62 'commitMessage' => $this->commitMessage, 63 'commitDetails' => json_encode($this->commitDetails), 64 ); 65 } 66 67 public static function newFromDictionary(array $dict) { 68 return id(new PhabricatorRepositoryCommitData()) 69 ->loadFromArray($dict); 70 } 71 72 public function newPublisherHoldReasons() { 73 $holds = $this->getCommitDetail('holdReasons'); 74 75 // Look for the legacy "autocloseReason" if we don't have a modern list 76 // of hold reasons. 77 if (!$holds) { 78 $old_hold = $this->getCommitDetail('autocloseReason'); 79 if ($old_hold) { 80 $holds = array($old_hold); 81 } 82 } 83 84 if (!$holds) { 85 $holds = array(); 86 } 87 88 foreach ($holds as $key => $reason) { 89 $holds[$key] = PhabricatorRepositoryPublisherHoldReason::newForHoldKey( 90 $reason); 91 } 92 93 return array_values($holds); 94 } 95 96 public function getAuthorString() { 97 $ref = $this->getCommitRef(); 98 99 $author = $ref->getAuthor(); 100 if (phutil_nonempty_string($author)) { 101 return $author; 102 } 103 104 $author = phutil_string_cast($this->authorName); 105 if (strlen($author)) { 106 return $author; 107 } 108 109 return null; 110 } 111 112 public function getAuthorDisplayName() { 113 return $this->getCommitRef()->getAuthorName(); 114 } 115 116 public function getAuthorEmail() { 117 return $this->getCommitRef()->getAuthorEmail(); 118 } 119 120 public function getAuthorEpoch() { 121 $epoch = $this->getCommitRef()->getAuthorEpoch(); 122 123 if ($epoch) { 124 return (int)$epoch; 125 } 126 127 return null; 128 } 129 130 public function getCommitterString() { 131 $ref = $this->getCommitRef(); 132 133 $committer = $ref->getCommitter(); 134 if (phutil_nonempty_string($committer)) { 135 return $committer; 136 } 137 138 return $this->getCommitDetailString('committer'); 139 } 140 141 public function getCommitterDisplayName() { 142 return $this->getCommitRef()->getCommitterName(); 143 } 144 145 public function getCommitterEmail() { 146 return $this->getCommitRef()->getCommitterEmail(); 147 } 148 149 private function getCommitDetailString($key) { 150 $string = $this->getCommitDetail($key); 151 $string = phutil_string_cast($string); 152 153 if (strlen($string)) { 154 return $string; 155 } 156 157 return null; 158 } 159 160 public function setCommitRef(DiffusionCommitRef $ref) { 161 $this->setCommitDetail('ref', $ref->newDictionary()); 162 $this->commitRef = null; 163 164 return $this; 165 } 166 167 public function getCommitRef() { 168 if ($this->commitRef === null) { 169 $map = $this->getCommitDetail('ref', array()); 170 171 if (!is_array($map)) { 172 $map = array(); 173 } 174 175 $map = $map + array( 176 'authorName' => $this->getCommitDetailString('authorName'), 177 'authorEmail' => $this->getCommitDetailString('authorEmail'), 178 'authorEpoch' => $this->getCommitDetailString('authorEpoch'), 179 'committerName' => $this->getCommitDetailString('committerName'), 180 'committerEmail' => $this->getCommitDetailString('committerEmail'), 181 'message' => $this->getCommitMessage(), 182 ); 183 184 $ref = DiffusionCommitRef::newFromDictionary($map); 185 $this->commitRef = $ref; 186 } 187 188 return $this->commitRef; 189 } 190 191}