Skip to content

Instantly share code, notes, and snippets.

@joaoneto
Last active December 11, 2015 23:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save joaoneto/4679151 to your computer and use it in GitHub Desktop.
Save joaoneto/4679151 to your computer and use it in GitHub Desktop.
Transform GIT LOG into a cute format Changelog.md
<?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