gitlog.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * This script pre-generates a list of commits to generate a changelog in the
  4. * form (branch, then commits in HTML form, then a final feedback):
  5. *
  6. * @example
  7. * 1.9.x
  8. * <li>(<a href="https://github.com/chamilo/chamilo-lms/commit/7333997ce358870bac139d15816dcaa7dd7794fa">7333997c</a> - <a href="https://task.beeznest.com/issues/8680">BT#8680</a>) Fixing custom lost password to work as classic Chamilo</li>
  9. * ...
  10. * <li>(<a href="https://github.com/chamilo/chamilo-lms/commit/acdc14c47997315b151efda9a530c47a53100d68">acdc14c4</a> - <a href="https://task.beeznest.com/issues/8676">BT#8676</a>) Adding unique email validation option</li>
  11. * Printed 367 commits of 500 requested (others were minor)
  12. *
  13. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  14. */
  15. /**
  16. * Includes a modified version of Git lib by Sebastian Bergmann of PHPUnit
  17. * @see https://github.com/ywarnier/git
  18. */
  19. require 'php-git/src/Git.php';
  20. $repository = __DIR__.'/../..';
  21. $number = 500; //the number of commits to check (including minor)
  22. $formatHTML = true;
  23. $showDate = false;
  24. if (!empty($argv[1]) && $argv[1] == '-t') {
  25. $showDate = true;
  26. }
  27. $git = new \SebastianBergmann\Git\Git($repository);
  28. echo "Log from branch: ".$git->getCurrentBranch().PHP_EOL;
  29. $logs = $git->getRevisions('DESC', $number);
  30. $i = 0;
  31. foreach ($logs as $log) {
  32. if ($showDate) {
  33. echo $log['date']->format('Y-m-d H:i:s').' '.substr($log['sha1'],0,8).PHP_EOL;
  34. }
  35. if (strncasecmp($log['message'], 'Minor', 5) === 0) {
  36. //Skip minor messages
  37. continue;
  38. }
  39. $issueLink = '';
  40. $matches = array();
  41. if (preg_match_all('/((BT)?#(\d){2,5})/', $log['message'], $matches)) {
  42. $issue = $matches[0][0];
  43. if (substr($issue, 0, 1) == '#') {
  44. // not a BeezNest task
  45. $num = substr($issue, 1);
  46. if ($formatHTML) {
  47. $issueLink = ' - <a href="https://support.chamilo.org/issues/' . $num . '">#' . $num . '</a>';
  48. } else {
  49. $issueLink = ' - ' . $num;
  50. }
  51. } else {
  52. $num = substr($issue, 3);
  53. if ($formatHTML) {
  54. $issueLink = ' - <a href="https://task.beeznest.com/issues/' . $num . '">BT#' . $num . '</a>';
  55. } else {
  56. $issueLink = ' - ' . $num;
  57. }
  58. }
  59. if ($hasRefs = stripos($log['message'], ' see '.$issue)) {
  60. $log['message'] = substr($log['message'], 0, $hasRefs);
  61. }
  62. if ($hasRefs = stripos($log['message'], ' - ref')) {
  63. $log['message'] = substr($log['message'], 0, $hasRefs);
  64. }
  65. if ($hasRefs = stripos($log['message'], ' -refs ')) {
  66. $log['message'] = substr($log['message'], 0, $hasRefs);
  67. }
  68. }
  69. $commitLink = '';
  70. if ($formatHTML) {
  71. $commitLink = '<a href="https://github.com/chamilo/chamilo-lms/commit/' . $log['sha1'] . '">' .
  72. substr($log['sha1'], 0, 8) . '</a>';
  73. echo '<li>('.$commitLink.$issueLink.') '.$log['message'].'</li>'.PHP_EOL;
  74. } else {
  75. $commitLink = substr($log['sha1'], 0, 8);
  76. echo '('.$commitLink.$issueLink.') '.$log['message'].''.PHP_EOL;
  77. }
  78. $i++;
  79. }
  80. echo "Printed $i commits of $number requested (others were minor)".PHP_EOL;