Skip to content

Commit

Permalink
rendering commits fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jun 5, 2015
1 parent 5e1c12a commit 3475a27
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
1 change: 1 addition & 0 deletions .hidev/commits.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ hiqdev/hidev commits history

- 2572447 2015-06-05 minor (sol@hiqdev.com)
- 8f37194 2015-06-05 minor (sol@hiqdev.com)
- 5e1c12a 2015-06-05 minor (sol@hiqdev.com)
- cool CHANGELOG.md generation
- 8546f09 2015-06-05 + skip 'minor' commits at addHistory (sol@hiqdev.com)
- 5474d01 2015-06-05 + handlers\Commits::renderLines (sol@hiqdev.com)
Expand Down
16 changes: 11 additions & 5 deletions goals/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public function getHistory()

public function addHistory($commit)
{
if ($commit['comment']==='minor') {
return;
}
$this->tag = $this->matchTag($commit['tag']) ?: $this->tag;
$commit['tag'] = $this->tag;
$this->_commits[$commit['hash']] = $commit;
if ($commit['comment']==='minor') {
return;
}
$this->_history[$this->tag][$commit['hash']] = $commit;
}

Expand All @@ -102,8 +102,14 @@ public function loadHistory()

public function matchTag($str)
{
preg_match('/^\(tag: (.*?)\)$/', $str, $t);
return (string)$t[1];
preg_match('/^\((.*?)\)$/', $str, $m);
$refs = explode(', ', $m[1]);
foreach ($refs as $ref) {
if (preg_match('/^tag: (.*)$/', $ref, $m)) {
return $m[1];
}
}
return false;
}

public function load()
Expand Down
5 changes: 2 additions & 3 deletions handlers/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public function parse($text)

public function render($data)
{
$header = '# ' . $this->goal->package->fullName . " changelog";
$res .= $header . "\n" . str_repeat('-', mb_strlen($header, Yii::$app->charset)) . "\n";
$res = Commits::renderHeader('changelog');

foreach ($data['history'] as $tag => $notes) {
$tag = Commits::arrayPop($notes, 'tag');
$tag = Commits::arrayPop($notes, 'tag') ?: $tag;
$new = Commits::arrayPop($notes, '');
$res .= Commits::renderTag($tag);
foreach ($notes as $note => $cs) {
Expand Down
30 changes: 19 additions & 11 deletions handlers/Commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function init()
protected $_tag;
protected $_note;
protected $_commit;
protected $_history;
protected $_commits;
protected $_history = [];
protected $_commits = [];

public function getTag()
{
Expand Down Expand Up @@ -94,11 +94,15 @@ public function hasCommit($hash)

public function parsePath($path)
{
if (!is_file($path)) {
return [];
}
$this->_history = [];
$this->tag = $this->lastTag;
foreach ($this->readArray($path) as $str) {
$str = rtrim($str);
if (!$str) {
$no++;
if (!$str || $no<3) {
continue;
}
if (preg_match('/^# /', $str)) {
Expand Down Expand Up @@ -143,7 +147,7 @@ public function getHistory()

public function render($data)
{
$res = '# ' . $this->goal->package->fullName . " commits history\n";
$res = static::renderHeader('commits history');

foreach ($this->goal->vcs->commits as $hash => $commit) {
if ($this->hasCommit($hash)) {
Expand All @@ -153,13 +157,11 @@ public function render($data)
}

foreach ($this->_history as $tag => $notes) {
$tag = static::arrayPop($notes, 'tag');
$new = static::arrayPop($notes, '');
$tag = static::arrayPop($notes, 'tag') ?: $tag;
$new = static::arrayPop($notes, '') ?: [];
$res .= static::renderTag($tag);
if ($new) {
foreach ($new as $hash => $lines) {
$res .= static::renderLines($lines);
}
foreach ($new as $hash => $lines) {
$res .= static::renderLines($lines);
}
foreach ($notes as $note => $cs) {
$note = static::arrayPop($cs, 'note');
Expand Down Expand Up @@ -198,7 +200,7 @@ public static function renderCommit($commit)
public static function renderTag($tag)
{
if (strpos($tag, ' ')===false) {
$tag .= static::renderDate($this->goal->vcs->tags[$tag]);
$tag .= static::renderDate(Yii::$app->config->vcs->tags[$tag]);
}
return "\n## $tag\n\n";
}
Expand All @@ -208,4 +210,10 @@ public static function renderDate($date)
return $date ? date(' F j, Y', strtotime($date)) : '';
}

public static function renderHeader($string)
{
$header = Yii::$app->config->package->fullName . ' ' . $string;
return $header . "\n" . str_repeat('-', mb_strlen($header, Yii::$app->charset)) . "\n";
}

}

0 comments on commit 3475a27

Please sign in to comment.