1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Changelog keeper |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/chkipper |
6
|
|
|
* @package chkipper |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\chkipper\lib; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* History builder class. |
15
|
|
|
* |
16
|
|
|
* @author Andrii Vasyliev <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class Builder |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string current tag |
22
|
|
|
*/ |
23
|
|
|
protected $_tag = ''; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string current note |
27
|
|
|
*/ |
28
|
|
|
protected $_note = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string current commit's hash |
32
|
|
|
*/ |
33
|
|
|
protected $_hash = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ConfigInterface config object |
37
|
|
|
*/ |
38
|
|
|
protected $_config; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var History history object |
42
|
|
|
*/ |
43
|
|
|
protected $_history; |
44
|
|
|
|
45
|
3 |
|
public function __construct(ConfigInterface $config, History $history = null) |
46
|
|
|
{ |
47
|
3 |
|
$this->_config = $config; |
48
|
3 |
|
$this->setHistory($history); |
49
|
3 |
|
} |
50
|
|
|
|
51
|
2 |
|
public function getConfig() |
52
|
|
|
{ |
53
|
2 |
|
return $this->_config; |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
public function setHistory(History $history = null) |
57
|
|
|
{ |
58
|
3 |
|
$this->_history = is_null($history) ? new History($this->_config) : $history; |
59
|
3 |
|
} |
60
|
|
|
|
61
|
3 |
|
public function getHistory() |
62
|
|
|
{ |
63
|
3 |
|
return $this->_history; |
64
|
|
|
} |
65
|
|
|
|
66
|
3 |
|
public function setTag($tag) |
67
|
|
|
{ |
68
|
3 |
|
$this->_tag = $tag; |
69
|
3 |
|
$this->setNote(''); |
70
|
3 |
|
} |
71
|
|
|
|
72
|
3 |
|
public function setNote($note) |
73
|
|
|
{ |
74
|
3 |
|
$this->_note = $note; |
75
|
3 |
|
$this->setHash(''); |
76
|
3 |
|
} |
77
|
|
|
|
78
|
3 |
|
public function setHash($hash) |
79
|
|
|
{ |
80
|
3 |
|
if ($hash) { |
81
|
3 |
|
$this->_hash = (string) $hash; |
82
|
3 |
|
$this->getHistory()->addHash($hash); |
83
|
3 |
|
} |
84
|
3 |
|
} |
85
|
|
|
|
86
|
3 |
|
public function getTag() |
87
|
|
|
{ |
88
|
3 |
|
return $this->_tag; |
89
|
|
|
} |
90
|
|
|
|
91
|
3 |
|
public function getNote() |
92
|
|
|
{ |
93
|
3 |
|
return $this->_note; |
94
|
|
|
} |
95
|
|
|
|
96
|
2 |
|
public function getHash() |
97
|
|
|
{ |
98
|
2 |
|
return $this->_hash; |
99
|
|
|
} |
100
|
|
|
|
101
|
2 |
|
public function addHeader($header) |
102
|
|
|
{ |
103
|
2 |
|
$this->getHistory()->addHeader($header); |
104
|
2 |
|
} |
105
|
|
|
|
106
|
3 |
|
public function addTag($tag, $date = null) |
107
|
|
|
{ |
108
|
3 |
|
$this->setTag($tag); |
109
|
|
|
|
110
|
3 |
|
return $this->getHistory()->addTag(new Tag($tag, $date)); |
111
|
|
|
} |
112
|
|
|
|
113
|
2 |
|
public function addNote($note) |
114
|
|
|
{ |
115
|
2 |
|
$this->setNote($note); |
116
|
2 |
|
$this->getHistory()->findTag($this->getTag())->findNote($note); |
117
|
2 |
|
} |
118
|
|
|
|
119
|
3 |
|
public function addCommit($hash, $label) |
120
|
|
|
{ |
121
|
3 |
|
$commit = new Commit($hash, $label); |
122
|
3 |
|
if (!$this->skipCommit($commit)) { |
123
|
3 |
|
$this->setHash($hash); |
124
|
3 |
|
$this->getHistory()->findTag($this->getTag())->findNote($this->getNote())->findCommit($hash)->setLabel($label); |
125
|
3 |
|
} |
126
|
3 |
|
} |
127
|
|
|
|
128
|
2 |
|
public function addComment($comment) |
129
|
|
|
{ |
130
|
2 |
|
$this->getHistory()->findTag($this->getTag())->findNote($this->getNote())->findCommit($this->getHash())->addComment($comment); |
131
|
2 |
|
} |
132
|
|
|
|
133
|
2 |
|
public function addLink($link, $href) |
134
|
|
|
{ |
135
|
2 |
|
$this->getHistory()->addLink($link, $href); |
136
|
2 |
|
} |
137
|
|
|
|
138
|
1 |
|
public function getLastTag() |
139
|
|
|
{ |
140
|
1 |
|
return $this->getHistory()->lastTag; |
141
|
|
|
} |
142
|
|
|
|
143
|
1 |
|
public function getInitTag() |
144
|
|
|
{ |
145
|
1 |
|
return $this->getHistory()->initTag; |
146
|
|
|
} |
147
|
|
|
|
148
|
3 |
|
public static function skipCommit(Commit $commit) |
149
|
|
|
{ |
150
|
3 |
|
$subject = $commit->getSubject(); |
151
|
|
|
|
152
|
|
|
static $equals = [ |
153
|
|
|
'' => 1, |
154
|
|
|
'bump' => 1, |
155
|
|
|
'minor' => 1, |
156
|
|
|
'bumped' => 1, |
157
|
3 |
|
]; |
158
|
3 |
|
if (isset($equals[$subject])) { |
159
|
1 |
|
return true; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
static $starts = [ |
163
|
|
|
'version bump', |
164
|
|
|
'bumped version', |
165
|
|
|
"merge branch 'master'", |
166
|
3 |
|
]; |
167
|
3 |
|
foreach ($starts as $start) { |
168
|
3 |
|
if (strtolower(substr($subject, 0, strlen($start))) === $start) { |
169
|
1 |
|
return true; |
170
|
|
|
} |
171
|
3 |
|
} |
172
|
|
|
|
173
|
3 |
|
return false; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|