gitlog.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. $endCommit = false;
  25. if (!empty($argv[1])) {
  26. if ($argv[1] == '-t') {
  27. $showDate = true;
  28. } else {
  29. $endCommit = $argv[1];
  30. echo "End commit has been defined as ".$endCommit.PHP_EOL;
  31. }
  32. }
  33. $git = new \SebastianBergmann\Git\Git($repository);
  34. echo "Log from branch: ".$git->getCurrentBranch().PHP_EOL;
  35. $logs = $git->getRevisions('DESC', $number);
  36. $i = 0;
  37. foreach ($logs as $log) {
  38. if ($showDate) {
  39. echo $log['date']->format('Y-m-d H:i:s').' '.substr($log['sha1'],0,8).PHP_EOL;
  40. }
  41. // Check for Minor importance messages to ignore...
  42. if (strncasecmp($log['message'], 'Minor', 5) === 0) {
  43. //Skip minor messages
  44. continue;
  45. }
  46. //Skip language update messages (not important)
  47. $langMsg = array(
  48. 'Update language terms',
  49. 'Update language vars',
  50. 'Update lang vars',
  51. 'Merge',
  52. 'merge'
  53. );
  54. foreach ($langMsg as $msg) {
  55. if (strpos($log['message'], $msg) === 0) {
  56. continue 2;
  57. }
  58. }
  59. // Look for tasks references
  60. $issueLink = '';
  61. $matches = array();
  62. if (preg_match_all('/((BT)?#(\d){2,5})/', $log['message'], $matches)) {
  63. $issue = $matches[0][0];
  64. if (substr($issue, 0, 1) == '#') {
  65. // not a BeezNest task
  66. $num = substr($issue, 1);
  67. if ($num > 4000) {
  68. //should be Chamilo support site
  69. if ($formatHTML) {
  70. $issueLink = ' - <a href="https://support.chamilo.org/issues/' . $num . '">CT#' . $num . '</a>';
  71. } else {
  72. $issueLink = ' - ' . $num;
  73. }
  74. } else {
  75. //should be Github
  76. if ($formatHTML) {
  77. $issueLink = ' - <a href="https://github.com/chamilo/chamilo-lms/issues/' . $num . '">GH#' . $num . '</a>';
  78. } else {
  79. $issueLink = ' - ' . $num;
  80. }
  81. }
  82. } else {
  83. $num = substr($issue, 3);
  84. if ($num != '7683') {
  85. if ($formatHTML) {
  86. //7683 is an internal task at BeezNest for all general contributions to Chamilo - no use in adding this reference
  87. $issueLink = ' - <a href="https://task.beeznest.com/issues/' . $num . '">BT#' . $num . '</a>';
  88. } else {
  89. $issueLink = ' - ' . $num;
  90. }
  91. }
  92. }
  93. if ($hasRefs = stripos($log['message'], ' see '.$issue)) {
  94. $log['message'] = substr($log['message'], 0, $hasRefs);
  95. }
  96. if ($hasRefs = stripos($log['message'], ' - ref')) {
  97. $log['message'] = substr($log['message'], 0, $hasRefs);
  98. }
  99. if ($hasRefs = stripos($log['message'], ' -refs ')) {
  100. $log['message'] = substr($log['message'], 0, $hasRefs);
  101. }
  102. }
  103. $commitLink = '';
  104. if ($formatHTML) {
  105. $log['message'] = ucfirst($log['message']);
  106. $commitLink = '<a href="https://github.com/chamilo/chamilo-lms/commit/' . $log['sha1'] . '">' .
  107. substr($log['sha1'], 0, 8) . '</a>';
  108. echo '<li>('.$commitLink.$issueLink.') '.$log['message'].'</li>'.PHP_EOL;
  109. } else {
  110. $commitLink = substr($log['sha1'], 0, 8);
  111. echo '('.$commitLink.$issueLink.') '.$log['message'].''.PHP_EOL;
  112. }
  113. // check end commit to stop processing
  114. if ($endCommit) {
  115. $length = strlen($endCommit);
  116. if (substr($log['sha1'], 0, $length) == $endCommit) {
  117. echo "Found the end commit ".$endCommit.", exiting...".PHP_EOL;
  118. break;
  119. }
  120. }
  121. $i++;
  122. }
  123. echo "Printed $i commits of $number requested (others were minor)".PHP_EOL;