Skip to content

Commit

Permalink
+ bump goal for version bumping
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jan 15, 2016
1 parent a2db3f7 commit 1a4bfac
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/controllers/BumpController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* Task runner, code generator and build tool for easier continuos integration
*
* @link https://github.com/hiqdev/hidev
* @package hidev
* @license BSD-3-Clause
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
*/

namespace hidev\controllers;

/**
* Controller for version bump.
*/
class BumpController extends AbstractController
{
protected $_before = ['commits'];

public $version;

public function actionPerform($version = null)
{
$this->version = $version;
return $this->runActions(['before', 'make', 'after']);
}

public function actionMake()
{
return $this->runRequests(['commits/bump', 'CHANGELOG.md']);
}

}
42 changes: 41 additions & 1 deletion src/controllers/CommitsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace hidev\controllers;

use yii\base\InvalidParamException;

/**
* Controller for reading and writing commits history to build CHANGELOG.md.
*/
Expand All @@ -22,8 +24,46 @@ class CommitsController extends FileController

public $fileType = 'commits';

protected $_version;

public function actionBump($version = null)
{
$this->_version = $version ?: $this->takeGoal('bump')->version;

return $this->runActions(['load', 'do-bump', 'save']);
}

public function actionDoBump()
{
$history = $this->getHistory();
$new = [];
$first = true;
foreach ($history as $tag => $value) {
if (substr($tag, 0, strlen($this->_version)) === $this->_version) {
throw new InvalidParamException('Version already there: ' . $this->version);
}
if ($first) {
$first = false;
$new[$tag] = ['tag' => $tag];
$tag = $this->_version . $this->getHandler()->renderDate('today');
$value['tag'] = $tag;
}
$new[$tag] = $value;
}

$this->getHandler()->setHistory($new);

/// TODO strange shouldn't be needed
$this->actionSave();
}

public function getHistory()
{
return $this->getFile()->getHandler()->getHistory();
return $this->getHandler()->getHistory();
}

public function getHandler()
{
return $this->getFile()->getHandler();
}
}
5 changes: 5 additions & 0 deletions src/handlers/CommitsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public function hasHistory($tag)
return array_key_exists($tag, $this->_history);
}

public function setHistory($value)
{
$this->_history = $value;
}

public function getHistory()
{
return $this->_history;
Expand Down

0 comments on commit 1a4bfac

Please sign in to comment.