Created
December 24, 2016 08:13
-
-
Save f3ath/13592b4368c50ba63a0e315accde22e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace F3\Changelog; | |
use Composer\Semver\Semver; | |
use F3\Changelog\Exception\NoTagsFound; | |
use F3\Changelog\Exception\TagNotFound; | |
class ReleaseNotes | |
{ | |
/** | |
* @var GitGateway | |
*/ | |
private $git; | |
public function write(Printer $printer, string $tag = null) | |
{ | |
$tags = $this->git->getTags(); | |
if (empty($tags)) { | |
throw new NoTagsFound(); | |
} | |
$tags = Semver::rsort($tags); | |
$tag = $tag ?: reset($tags); | |
$index = array_search($tag, $tags); | |
if (false === $index) { | |
throw new TagNotFound($tag); | |
} | |
if (++$index < count($tags)) { | |
$release = new SubsequentRelease($this->git, $tags[$index], $tag); | |
} else { | |
$release = new Release($this->git, $tag); | |
} | |
$release->printHeader($printer); | |
$release->printChanges($printer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment