3 final class PhabricatorRepositoryCommitData
extends PhabricatorRepositoryDAO
{
6 protected $authorName = '';
7 protected $commitMessage = '';
8 protected $commitDetails = array();
11 protected function getConfiguration() {
13 self
::CONFIG_TIMESTAMPS
=> false,
14 self
::CONFIG_SERIALIZATION
=> array(
15 'commitDetails' => self
::SERIALIZATION_JSON
,
17 self
::CONFIG_COLUMN_SCHEMA
=> array(
18 'authorName' => 'text',
19 'commitMessage' => 'text',
21 self
::CONFIG_KEY_SCHEMA
=> array(
23 'columns' => array('commitID'),
27 ) + parent
::getConfiguration();
30 public function getSummary() {
31 $message = $this->getCommitMessage();
32 return self
::summarizeCommitMessage($message);
35 public static function summarizeCommitMessage($message) {
36 $max_bytes = id(new PhabricatorRepositoryCommit())
37 ->getColumnMaximumByteLength('summary');
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);
49 public function getCommitDetail($key, $default = null) {
50 return idx($this->commitDetails
, $key, $default);
53 public function setCommitDetail($key, $value) {
54 $this->commitDetails
[$key] = $value;
58 public function toDictionary() {
60 'commitID' => $this->commitID
,
61 'authorName' => $this->authorName
,
62 'commitMessage' => $this->commitMessage
,
63 'commitDetails' => json_encode($this->commitDetails
),
67 public static function newFromDictionary(array $dict) {
68 return id(new PhabricatorRepositoryCommitData())
69 ->loadFromArray($dict);
72 public function newPublisherHoldReasons() {
73 $holds = $this->getCommitDetail('holdReasons');
75 // Look for the legacy "autocloseReason" if we don't have a modern list
78 $old_hold = $this->getCommitDetail('autocloseReason');
80 $holds = array($old_hold);
88 foreach ($holds as $key => $reason) {
89 $holds[$key] = PhabricatorRepositoryPublisherHoldReason
::newForHoldKey(
93 return array_values($holds);
96 public function getAuthorString() {
97 $ref = $this->getCommitRef();
99 $author = $ref->getAuthor();
100 if ($author !== null && strlen($author)) {
104 $author = phutil_string_cast($this->authorName
);
105 if (strlen($author)) {
112 public function getAuthorDisplayName() {
113 return $this->getCommitRef()->getAuthorName();
116 public function getAuthorEmail() {
117 return $this->getCommitRef()->getAuthorEmail();
120 public function getAuthorEpoch() {
121 $epoch = $this->getCommitRef()->getAuthorEpoch();
130 public function getCommitterString() {
131 $ref = $this->getCommitRef();
133 $committer = $ref->getCommitter();
134 if ($committer !== null && strlen($committer)) {
138 return $this->getCommitDetailString('committer');
141 public function getCommitterDisplayName() {
142 return $this->getCommitRef()->getCommitterName();
145 public function getCommitterEmail() {
146 return $this->getCommitRef()->getCommitterEmail();
149 private function getCommitDetailString($key) {
150 $string = $this->getCommitDetail($key);
151 $string = phutil_string_cast($string);
153 if (strlen($string)) {
160 public function setCommitRef(DiffusionCommitRef
$ref) {
161 $this->setCommitDetail('ref', $ref->newDictionary());
162 $this->commitRef
= null;
167 public function getCommitRef() {
168 if ($this->commitRef
=== null) {
169 $map = $this->getCommitDetail('ref', array());
171 if (!is_array($map)) {
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(),
184 $ref = DiffusionCommitRef
::newFromDictionary($map);
185 $this->commitRef
= $ref;
188 return $this->commitRef
;