|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Task runner, code generator and build tool for easier continuos integration |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hidev |
|
7
|
|
|
* @package hidev |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hidev\controllers; |
|
13
|
|
|
|
|
14
|
|
|
use yii\base\InvalidParamException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Controller for reading and writing commits history to build CHANGELOG.md. |
|
18
|
|
|
*/ |
|
19
|
|
|
class CommitsController extends FileController |
|
20
|
|
|
{ |
|
21
|
|
|
protected $_before = ['git']; /// TODO must be 'vcs' or detected |
|
22
|
|
|
|
|
23
|
|
|
protected $_file = '.hidev/commits.md'; |
|
24
|
|
|
|
|
25
|
|
|
public $fileType = 'commits'; |
|
26
|
|
|
|
|
27
|
|
|
protected $_version; |
|
28
|
|
|
|
|
29
|
|
|
public function actionBump($version = null) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->_version = $version ?: $this->takeGoal('bump')->version; |
|
32
|
|
|
|
|
33
|
|
|
return $this->runActions(['load', 'do-bump', 'save']); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function actionDoBump() |
|
37
|
|
|
{ |
|
38
|
|
|
$history = $this->getHistory(); |
|
39
|
|
|
$new = []; |
|
40
|
|
|
$first = true; |
|
41
|
|
|
foreach ($history as $tag => $value) { |
|
42
|
|
|
if (substr($tag, 0, strlen($this->_version)) === $this->_version) { |
|
43
|
|
|
throw new InvalidParamException('Version already there: ' . $this->_version); |
|
44
|
|
|
} |
|
45
|
|
|
if ($first) { |
|
46
|
|
|
$first = false; |
|
47
|
|
|
$new[$tag] = ['tag' => $tag]; |
|
48
|
|
|
$tag = $this->_version . $this->getHandler()->renderDate('today'); |
|
49
|
|
|
$value['tag'] = $tag; |
|
50
|
|
|
} |
|
51
|
|
|
$new[$tag] = $value; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->getHandler()->setHistory($new); |
|
55
|
|
|
|
|
56
|
|
|
/// TODO strange shouldn't be needed |
|
57
|
|
|
$this->actionSave(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getHistory() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getHandler()->getHistory(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getHandler() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getFile()->getHandler(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|