@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
at upstream/main 150 lines 3.6 kB view raw
1<?php 2 3final class DiffusionCommitRef extends Phobject { 4 5 private $message; 6 private $authorEpoch; 7 private $authorName; 8 private $authorEmail; 9 private $committerName; 10 private $committerEmail; 11 private $hashes = array(); 12 13 public function newDictionary() { 14 $hashes = $this->getHashes(); 15 $hashes = mpull($hashes, 'newDictionary'); 16 $hashes = array_values($hashes); 17 18 return array( 19 'authorEpoch' => $this->authorEpoch, 20 'authorName' => $this->authorName, 21 'authorEmail' => $this->authorEmail, 22 'committerName' => $this->committerName, 23 'committerEmail' => $this->committerEmail, 24 'message' => $this->message, 25 'hashes' => $hashes, 26 ); 27 } 28 29 public static function newFromDictionary(array $map) { 30 $hashes = idx($map, 'hashes', array()); 31 foreach ($hashes as $key => $hash_map) { 32 $hashes[$key] = DiffusionCommitHash::newFromDictionary($hash_map); 33 } 34 $hashes = array_values($hashes); 35 36 $author_epoch = idx($map, 'authorEpoch'); 37 $author_name = idx($map, 'authorName'); 38 $author_email = idx($map, 'authorEmail'); 39 $committer_name = idx($map, 'committerName'); 40 $committer_email = idx($map, 'committerEmail'); 41 $message = idx($map, 'message'); 42 43 return id(new self()) 44 ->setAuthorEpoch($author_epoch) 45 ->setAuthorName($author_name) 46 ->setAuthorEmail($author_email) 47 ->setCommitterName($committer_name) 48 ->setCommitterEmail($committer_email) 49 ->setMessage($message) 50 ->setHashes($hashes); 51 } 52 53 /** 54 * @param array<DiffusionCommitHash> $hashes 55 */ 56 public function setHashes(array $hashes) { 57 assert_instances_of($hashes, DiffusionCommitHash::class); 58 $this->hashes = $hashes; 59 return $this; 60 } 61 62 public function getHashes() { 63 return $this->hashes; 64 } 65 66 public function setAuthorEpoch($author_epoch) { 67 $this->authorEpoch = $author_epoch; 68 return $this; 69 } 70 71 public function getAuthorEpoch() { 72 return $this->authorEpoch; 73 } 74 75 public function setCommitterEmail($committer_email) { 76 $this->committerEmail = $committer_email; 77 return $this; 78 } 79 80 public function getCommitterEmail() { 81 return $this->committerEmail; 82 } 83 84 85 public function setCommitterName($committer_name) { 86 $this->committerName = $committer_name; 87 return $this; 88 } 89 90 public function getCommitterName() { 91 return $this->committerName; 92 } 93 94 95 public function setAuthorEmail($author_email) { 96 $this->authorEmail = $author_email; 97 return $this; 98 } 99 100 public function getAuthorEmail() { 101 return $this->authorEmail; 102 } 103 104 105 public function setAuthorName($author_name) { 106 $this->authorName = $author_name; 107 return $this; 108 } 109 110 public function getAuthorName() { 111 return $this->authorName; 112 } 113 114 public function setMessage($message) { 115 $this->message = $message; 116 return $this; 117 } 118 119 public function getMessage() { 120 return $this->message; 121 } 122 123 public function getAuthor() { 124 return $this->formatUser($this->authorName, $this->authorEmail); 125 } 126 127 public function getCommitter() { 128 return $this->formatUser($this->committerName, $this->committerEmail); 129 } 130 131 public function getSummary() { 132 return PhabricatorRepositoryCommitData::summarizeCommitMessage( 133 $this->getMessage()); 134 } 135 136 private function formatUser($name, $email) { 137 $name = coalesce($name, ''); 138 $email = coalesce($email, ''); 139 if (strlen($name) && strlen($email)) { 140 return "{$name} <{$email}>"; 141 } else if (strlen($email)) { 142 return $email; 143 } else if (strlen($name)) { 144 return $name; 145 } else { 146 return null; 147 } 148 } 149 150}