Skip to content

Instantly share code, notes, and snippets.

@iloris
Forked from joaoneto/changelog.php
Created March 1, 2013 18:20
Show Gist options
  • Save iloris/5066637 to your computer and use it in GitHub Desktop.
Save iloris/5066637 to your computer and use it in GitHub Desktop.
<?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) 2013 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];
}
}
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