forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiffusionCommitRef.php
125 lines (97 loc) · 2.79 KB
/
DiffusionCommitRef.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
final class DiffusionCommitRef extends Phobject {
private $message;
private $authorEpoch;
private $authorName;
private $authorEmail;
private $committerName;
private $committerEmail;
private $hashes = array();
public static function newFromConduitResult(array $result) {
$ref = id(new DiffusionCommitRef())
->setAuthorEpoch(idx($result, 'authorEpoch'))
->setCommitterEmail(idx($result, 'committerEmail'))
->setCommitterName(idx($result, 'committerName'))
->setAuthorEmail(idx($result, 'authorEmail'))
->setAuthorName(idx($result, 'authorName'))
->setMessage(idx($result, 'message'));
$hashes = array();
foreach (idx($result, 'hashes', array()) as $hash_result) {
$hashes[] = id(new DiffusionCommitHash())
->setHashType(idx($hash_result, 'type'))
->setHashValue(idx($hash_result, 'value'));
}
$ref->setHashes($hashes);
return $ref;
}
public function setHashes(array $hashes) {
$this->hashes = $hashes;
return $this;
}
public function getHashes() {
return $this->hashes;
}
public function setAuthorEpoch($author_epoch) {
$this->authorEpoch = $author_epoch;
return $this;
}
public function getAuthorEpoch() {
return $this->authorEpoch;
}
public function setCommitterEmail($committer_email) {
$this->committerEmail = $committer_email;
return $this;
}
public function getCommitterEmail() {
return $this->committerEmail;
}
public function setCommitterName($committer_name) {
$this->committerName = $committer_name;
return $this;
}
public function getCommitterName() {
return $this->committerName;
}
public function setAuthorEmail($author_email) {
$this->authorEmail = $author_email;
return $this;
}
public function getAuthorEmail() {
return $this->authorEmail;
}
public function setAuthorName($author_name) {
$this->authorName = $author_name;
return $this;
}
public function getAuthorName() {
return $this->authorName;
}
public function setMessage($message) {
$this->message = $message;
return $this;
}
public function getMessage() {
return $this->message;
}
public function getAuthor() {
return $this->formatUser($this->authorName, $this->authorEmail);
}
public function getCommitter() {
return $this->formatUser($this->committerName, $this->committerEmail);
}
public function getSummary() {
return PhabricatorRepositoryCommitData::summarizeCommitMessage(
$this->getMessage());
}
private function formatUser($name, $email) {
if (strlen($name) && strlen($email)) {
return "{$name} <{$email}>";
} else if (strlen($email)) {
return $email;
} else if (strlen($name)) {
return $name;
} else {
return null;
}
}
}