Created
November 1, 2010 15:23
-
-
Save predominant/658338 to your computer and use it in GitHub Desktop.
Automatically generate changelogs for CakePHP
This file contains 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 | |
$options = array( | |
'repo' => '/Users/predominant/Projects/cakephp/2.0/.git', | |
'titleOrder' => array( | |
'dev', 'alpha', 'beta', 'rc', | |
), | |
'regex' => '/(?<version>[\d\.]+)(?:-(?<title>[a-zA-Z]+)(?:(?<iteration>\d)?))?/', | |
'formats' => array( | |
'plaintext' => '| awk \'{print "Commit: ["$1"]\n"; $1=""; print "-"$0"\n"}\'', | |
'lighthouse' => '| awk \'{print "#### Commit: ["$1"](http://github.com/cakephp/cakephp/commit/"$1")\n"; $1=""; print $0"\n"}\'', | |
'compact-md' => '| awk \'{print "* [Commit "$1"](http://github.com/cakephp/cakephp/commit/"$1"): "; $1=""; print $0}\'', | |
), | |
); | |
$options['git-dir'] = '--git-dir=' . $options['repo']; | |
$options['format'] = !empty($_GET['format']) && array_key_exists($_GET['format'], $options['formats']) ? $_GET['format'] : 'plaintext'; | |
$tags = explode("\n", trim(`git ${options['git-dir']} tag`)); | |
usort($tags, function($from, $to) use ($options) { | |
preg_match($options['regex'], $from, $fromMatches); | |
preg_match($options['regex'], $to, $toMatches); | |
$version = version_compare($fromMatches['version'], $toMatches['version']); | |
if ($version !== 0) { | |
return $version; | |
} | |
if (!isset($fromMatches['title'])) { | |
return 1; | |
} | |
if (!isset($toMatches['title'])) { | |
return -1; | |
} | |
$title = array_search(strtolower($fromMatches['title']), $options['titleOrder']) - array_search(strtolower($toMatches['title']), $options['titleOrder']); | |
if ($title !== 0) { | |
return $title; | |
} | |
return version_compare($fromMatches['iteration'], $toMatches['iteration']); | |
}); | |
$tags = array_reverse($tags); | |
$previous = null; | |
echo '<h2>Format: ' . $options['format'] . '</h2>'; | |
$format = $options['formats'][$options['format']]; | |
foreach ($tags as $tag) { | |
if (!$previous) { | |
$previous = $tag; | |
continue; | |
} | |
echo '<h3>Version ' . $tag . '</h3>'; | |
echo '<pre>' . htmlentities(`git ${options['git-dir']} rev-list --no-merges --oneline ${previous} ^${tag} ${format}`) . '</pre>'; | |
$previous = $tag; | |
} |
This is designed to generate changelogs for the CakePHP project. It was never designed or intended to suit any other project.
It relies on tags for listing the versions, and doesn't care what branches you are using.
make sense i'm going to test this on a current app i have with a bunch of a tags and various branches. thanks for the feedback though
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The only thing wrong with this, it requires you are doing branches. What if your just doing a lot of bug updates, your not going to be versioning a production application that much though. So if you never version it causes issue