~ubuntu-branches/ubuntu/vivid/phabricator/vivid-proposed

« back to all changes in this revision

Viewing changes to arcanist/src/differential/ArcanistDifferentialCommitMessage.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-10-23 20:49:26 UTC
  • mfrom: (0.2.1) (0.1.1)
  • Revision ID: package-import@ubuntu.com-20141023204926-vq80u1op4df44azb
Tags: 0~git20141023-1
Initial release (closes: #703046)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Represents a parsed commit message.
 
5
 */
 
6
final class ArcanistDifferentialCommitMessage {
 
7
 
 
8
  private $rawCorpus;
 
9
  private $revisionID;
 
10
  private $fields = array();
 
11
 
 
12
  private $gitSVNBaseRevision;
 
13
  private $gitSVNBasePath;
 
14
  private $gitSVNUUID;
 
15
 
 
16
  public static function newFromRawCorpus($corpus) {
 
17
    $obj = new ArcanistDifferentialCommitMessage();
 
18
    $obj->rawCorpus = $corpus;
 
19
 
 
20
    $match = null;
 
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');
 
29
        } else {
 
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]}'.");
 
34
        }
 
35
      }
 
36
    }
 
37
 
 
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];
 
43
    }
 
44
 
 
45
    return $obj;
 
46
  }
 
47
 
 
48
  public function getRawCorpus() {
 
49
    return $this->rawCorpus;
 
50
  }
 
51
 
 
52
  public function getRevisionID() {
 
53
    return $this->revisionID;
 
54
  }
 
55
 
 
56
  public function pullDataFromConduit(
 
57
    ConduitClient $conduit,
 
58
    $partial = false) {
 
59
 
 
60
    $result = $conduit->callMethodSynchronous(
 
61
      'differential.parsecommitmessage',
 
62
      array(
 
63
        'corpus'  => $this->rawCorpus,
 
64
        'partial' => $partial,
 
65
      ));
 
66
 
 
67
    $this->fields = $result['fields'];
 
68
 
 
69
    if (!empty($result['errors'])) {
 
70
      throw new ArcanistDifferentialCommitMessageParserException(
 
71
        $result['errors']);
 
72
    }
 
73
 
 
74
    return $this;
 
75
  }
 
76
 
 
77
  public function getFieldValue($key) {
 
78
    if (array_key_exists($key, $this->fields)) {
 
79
      return $this->fields[$key];
 
80
    }
 
81
    return null;
 
82
  }
 
83
 
 
84
  public function setFieldValue($key, $value) {
 
85
    $this->fields[$key] = $value;
 
86
    return $this;
 
87
  }
 
88
 
 
89
  public function getFields() {
 
90
    return $this->fields;
 
91
  }
 
92
 
 
93
  public function getGitSVNBaseRevision() {
 
94
    return $this->gitSVNBaseRevision;
 
95
  }
 
96
 
 
97
  public function getGitSVNBasePath() {
 
98
    return $this->gitSVNBasePath;
 
99
  }
 
100
 
 
101
  public function getGitSVNUUID() {
 
102
    return $this->gitSVNUUID;
 
103
  }
 
104
 
 
105
  public function getChecksum() {
 
106
    $fields = array_filter($this->fields);
 
107
    ksort($fields);
 
108
    $fields = json_encode($fields);
 
109
    return md5($fields);
 
110
  }
 
111
 
 
112
}