forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorRepositoryCommitData.php
95 lines (78 loc) · 2.47 KB
/
PhabricatorRepositoryCommitData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
final class PhabricatorRepositoryCommitData extends PhabricatorRepositoryDAO {
protected $commitID;
protected $authorName = '';
protected $commitMessage = '';
protected $commitDetails = array();
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_SERIALIZATION => array(
'commitDetails' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
'authorName' => 'text',
'commitMessage' => 'text',
),
self::CONFIG_KEY_SCHEMA => array(
'commitID' => array(
'columns' => array('commitID'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function getSummary() {
$message = $this->getCommitMessage();
return self::summarizeCommitMessage($message);
}
public static function summarizeCommitMessage($message) {
$max_bytes = id(new PhabricatorRepositoryCommit())
->getColumnMaximumByteLength('summary');
$summary = phutil_split_lines($message, $retain_endings = false);
$summary = head($summary);
$summary = id(new PhutilUTF8StringTruncator())
->setMaximumBytes($max_bytes)
->setMaximumGlyphs(80)
->truncateString($summary);
return $summary;
}
public function getCommitDetail($key, $default = null) {
return idx($this->commitDetails, $key, $default);
}
public function setCommitDetail($key, $value) {
$this->commitDetails[$key] = $value;
return $this;
}
public function toDictionary() {
return array(
'commitID' => $this->commitID,
'authorName' => $this->authorName,
'commitMessage' => $this->commitMessage,
'commitDetails' => json_encode($this->commitDetails),
);
}
public static function newFromDictionary(array $dict) {
return id(new PhabricatorRepositoryCommitData())
->loadFromArray($dict);
}
public function newPublisherHoldReasons() {
$holds = $this->getCommitDetail('holdReasons');
// Look for the legacy "autocloseReason" if we don't have a modern list
// of hold reasons.
if (!$holds) {
$old_hold = $this->getCommitDetail('autocloseReason');
if ($old_hold) {
$holds = array($old_hold);
}
}
if (!$holds) {
$holds = array();
}
foreach ($holds as $key => $reason) {
$holds[$key] = PhabricatorRepositoryPublisherHoldReason::newForHoldKey(
$reason);
}
return array_values($holds);
}
}