Last active
December 11, 2015 23:48
-
-
Save joaoneto/4679151 to your computer and use it in GitHub Desktop.
Transform GIT LOG into a cute format Changelog.md
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 | |
/** | |
* Changelog Markdown | |
* | |
* This is a script to transform GIT LOG into a cute format Changelog.md | |
* | |
* To use, set executable permissions to this file and execute: | |
* $ php changelog.php > CHANGELOG.md | |
* | |
* Copyright (c) 2014 João Pinto Neto | |
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php | |
* | |
* | |
*/ | |
$cmd = 'git log --pretty="%ad: [%an] <%ae> %s" --date="short" --no-merges'; | |
$process = shell_exec($cmd); | |
$result = array(); | |
foreach (preg_split("/((\r?\n)|(\r\n?))/", $process) as $line) { | |
if (preg_match('/(^\d{4}-\d{2}-\d{2})\:\s\[(.*)\]\s(\<.*\>)\s(.*)/', $line, $match)) { | |
if (!isset($result[$match[1]])) { | |
$result[$match[1]] = array(); | |
} | |
$result[$match[1]][] = $match[4] . ' (by ' . $match[2] . ' '. $match[3] . ')'; | |
} | |
} | |
echo '# Changelog' . PHP_EOL; | |
foreach ($result as $date => $data) { | |
echo '## ' . $date . PHP_EOL; | |
foreach ($data as $change) { | |
echo '- ' . $change . PHP_EOL; | |
} | |
echo PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment