Skip to content
This repository was archived by the owner on Apr 12, 2020. It is now read-only.

Commit d159d61

Browse files
committed
add stable boolean in version filter
1 parent 635162f commit d159d61

3 files changed

Lines changed: 88 additions & 3 deletions

File tree

src/Gitonomy/ChangeLog/Filter/FilterFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ static function createFromRequest(Request $request)
1111
$parameters = $request->query;
1212

1313
$version = $parameters->get('from_version', 0.0);
14-
$filter = new VersionFilter($version);
14+
$stable = $parameters->get('stable', true);
15+
$filter = new VersionFilter($version, ($stable === 'false' ? false : $stable));
1516

1617
return new ChangeLogFilter($filter);
1718
}

src/Gitonomy/ChangeLog/Filter/VersionFilter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
class VersionFilter
88
{
99
protected $minimumVersion;
10+
protected $stable;
1011

11-
public function __construct($minimumVersion)
12+
public function __construct($minimumVersion, $stable = true)
1213
{
1314
$this->minimumVersion = $minimumVersion;
15+
$this->stable = (bool)$stable;
1416
}
1517

1618
public function filter(Version $version)
@@ -30,6 +32,9 @@ public function filter(Version $version)
3032

3133
protected function isTrue(Version $version)
3234
{
33-
return version_compare($this->minimumVersion, $version->getVersion()) < 0;
35+
return (
36+
(!$this->stable && null === $version->getDate()) ||
37+
(version_compare($this->minimumVersion, $version->getVersion()) < 0 && null !== $version->getDate())
38+
);
3439
}
3540
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Gitonomy.
5+
*
6+
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
7+
* (c) Julien DIDIER <genzo.wm@gmail.com>
8+
*
9+
* This source file is subject to the GPL license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace Gitonomy\ChangeLog\Parser;
14+
15+
use Gitonomy\ChangeLog\ChangeLog;
16+
use Gitonomy\ChangeLog\Node\Version;
17+
use Gitonomy\ChangeLog\Node\Feature;
18+
19+
class ChangeLogParser extends Parser
20+
{
21+
public function parse($content)
22+
{
23+
$this->cursor = 0;
24+
$this->content = $content;
25+
$this->length = strlen($this->content);
26+
27+
$changeLog = new ChangeLog();
28+
29+
while (!$this->isFinished()) {
30+
31+
if ($this->expects('* ')) {
32+
$version = $this->parseVersion($changeLog);
33+
}
34+
35+
if (null !== $version && $this->expects(' * ')) {
36+
$this->parseFeature($version);
37+
}
38+
39+
$this->consumeNewLine();
40+
}
41+
42+
return $changeLog;
43+
}
44+
45+
protected function parseVersion(ChangeLog $changeLog)
46+
{
47+
$version = $this->consumeTo("\n");
48+
49+
preg_match('/^v([0-9\.]+)(?: \((\d{4}-\d{2}-\d{2})\))?$/', $version, $versionData);
50+
51+
if (!$versionData) {
52+
$version = new Version($version);
53+
}
54+
elseif (isset($versionData[2])) {
55+
$version = new Version($versionData[1], $versionData[2]);
56+
} else {
57+
$version = new Version($versionData[1]);
58+
}
59+
60+
$changeLog->addVersion($version);
61+
62+
return $version;
63+
}
64+
65+
protected function parseFeature(Version $version)
66+
{
67+
$feature = $this->consumeTo("\n");
68+
69+
preg_match('#(\w*) (.*)#', $feature, $featureData);
70+
71+
if (!$featureData) {
72+
return;
73+
}
74+
75+
$version->addFeature(new Feature($featureData[1], $featureData[2]));
76+
77+
return $feature;
78+
}
79+
}

0 commit comments

Comments
 (0)