gitlog.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // Check for Minor importance messages to ignore...
  36. if (strncasecmp($log['message'], 'Minor', 5) === 0) {
  37. //Skip minor messages
  38. continue;
  39. }
  40. //Skip language update messages (not important)
  41. $langMsg = 'Update language terms';
  42. if (strpos($log['message'], $langMsg) === 0) {
  43. continue;
  44. }
  45. // Look for tasks references
  46. $issueLink = '';
  47. $matches = array();
  48. if (preg_match_all('/((BT)?#(\d){2,5})/', $log['message'], $matches)) {
  49. $issue = $matches[0][0];
  50. if (substr($issue, 0, 1) == '#') {
  51. // not a BeezNest task
  52. $num = substr($issue, 1);
  53. if ($formatHTML) {
  54. $issueLink = ' - <a href="https://support.chamilo.org/issues/' . $num . '">#' . $num . '</a>';
  55. } else {
  56. $issueLink = ' - ' . $num;
  57. }
  58. } else {
  59. $num = substr($issue, 3);
  60. if ($formatHTML) {
  61. $issueLink = ' - <a href="https://task.beeznest.com/issues/' . $num . '">BT#' . $num . '</a>';
  62. } else {
  63. $issueLink = ' - ' . $num;
  64. }
  65. }
  66. if ($hasRefs = stripos($log['message'], ' see '.$issue)) {
  67. $log['message'] = substr($log['message'], 0, $hasRefs);
  68. }
  69. if ($hasRefs = stripos($log['message'], ' - ref')) {
  70. $log['message'] = substr($log['message'], 0, $hasRefs);
  71. }
  72. if ($hasRefs = stripos($log['message'], ' -refs ')) {
  73. $log['message'] = substr($log['message'], 0, $hasRefs);
  74. }
  75. }
  76. $commitLink = '';
  77. if ($formatHTML) {
  78. $commitLink = '<a href="https://github.com/chamilo/chamilo-lms/commit/' . $log['sha1'] . '">' .
  79. substr($log['sha1'], 0, 8) . '</a>';
  80. echo '<li>('.$commitLink.$issueLink.') '.$log['message'].'</li>'.PHP_EOL;
  81. } else {
  82. $commitLink = substr($log['sha1'], 0, 8);
  83. echo '('.$commitLink.$issueLink.') '.$log['message'].''.PHP_EOL;
  84. }
  85. $i++;
  86. }
  87. echo "Printed $i commits of $number requested (others were minor)".PHP_EOL;