Skip to content

Instantly share code, notes, and snippets.

@f3ath
Created December 24, 2016 08:13
Show Gist options
  • Save f3ath/13592b4368c50ba63a0e315accde22e6 to your computer and use it in GitHub Desktop.
Save f3ath/13592b4368c50ba63a0e315accde22e6 to your computer and use it in GitHub Desktop.
<?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