4
* Represents a parsed commit message.
6
final class ArcanistDifferentialCommitMessage {
10
private $fields = array();
12
private $gitSVNBaseRevision;
13
private $gitSVNBasePath;
16
public static function newFromRawCorpus($corpus) {
17
$obj = new ArcanistDifferentialCommitMessage();
18
$obj->rawCorpus = $corpus;
21
if (preg_match('/^Differential Revision:\s*(.*)/im', $corpus, $match)) {
22
$revision_id = trim($match[1]);
23
if (strlen($revision_id)) {
24
$uri = new PhutilURI($revision_id);
25
$path = $uri->getPath();
26
$path = trim($path, '/');
27
if (preg_match('/^D\d+$/', $path)) {
28
$obj->revisionID = (int)trim($path, 'D');
30
throw new ArcanistUsageException(
31
"Invalid 'Differential Revision' field. The field should have a ".
32
"Phabricator URI like 'http://phabricator.example.com/D123', ".
33
"but has '{$match[1]}'.");
38
$pattern = '/^git-svn-id:\s*([^@]+)@(\d+)\s+(.*)$/m';
39
if (preg_match($pattern, $corpus, $match)) {
40
$obj->gitSVNBaseRevision = $match[1].'@'.$match[2];
41
$obj->gitSVNBasePath = $match[1];
42
$obj->gitSVNUUID = $match[3];
48
public function getRawCorpus() {
49
return $this->rawCorpus;
52
public function getRevisionID() {
53
return $this->revisionID;
56
public function pullDataFromConduit(
57
ConduitClient $conduit,
60
$result = $conduit->callMethodSynchronous(
61
'differential.parsecommitmessage',
63
'corpus' => $this->rawCorpus,
64
'partial' => $partial,
67
$this->fields = $result['fields'];
69
if (!empty($result['errors'])) {
70
throw new ArcanistDifferentialCommitMessageParserException(
77
public function getFieldValue($key) {
78
if (array_key_exists($key, $this->fields)) {
79
return $this->fields[$key];
84
public function setFieldValue($key, $value) {
85
$this->fields[$key] = $value;
89
public function getFields() {
93
public function getGitSVNBaseRevision() {
94
return $this->gitSVNBaseRevision;
97
public function getGitSVNBasePath() {
98
return $this->gitSVNBasePath;
101
public function getGitSVNUUID() {
102
return $this->gitSVNUUID;
105
public function getChecksum() {
106
$fields = array_filter($this->fields);
108
$fields = json_encode($fields);