gitlog.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * @usage php gitlog.php [-t|some-commit|-max20171001]
  18. * @see https://github.com/ywarnier/git
  19. */
  20. require 'php-git/src/Git.php';
  21. $repository = __DIR__.'/../..';
  22. $number = 2000; //the number of commits to check (including minor)
  23. $formatHTML = true;
  24. $showDate = false;
  25. $endCommit = false;
  26. $isMaxDate = false;
  27. if (!empty($argv[1])) {
  28. if ($argv[1] == '-t') {
  29. $showDate = true;
  30. } else if (substr($argv[1], 0, 4) == '-max') {
  31. $isMaxDate = true;
  32. $tempDate = substr($argv[1], 4);
  33. $y = substr($tempDate, 0, 4);
  34. $m = substr($tempDate, 4, 2);
  35. $d = substr($tempDate, 6, 2);
  36. $maxDate = new DateTime($y.'-'.$m.'-'.$d);
  37. } else {
  38. $endCommit = $argv[1];
  39. echo "An initial commit has been defined as ".$endCommit.PHP_EOL;
  40. }
  41. }
  42. $git = new \YWarnier\PHPGit\Git($repository);
  43. echo "Log from branch: ".$git->getCurrentBranch().PHP_EOL;
  44. $logs = $git->getRevisions('DESC', $number);
  45. $i = 0;
  46. foreach ($logs as $log) {
  47. $commitDate = $log['date']->format('Y-m-d');
  48. if ($showDate) {
  49. echo $commitDate.' '.substr($log['sha1'],0,8).PHP_EOL;
  50. }
  51. if ($isMaxDate) {
  52. // if the commit date is older than the max date, just forget about it
  53. if ($log['date'] < $maxDate) {
  54. continue;
  55. }
  56. }
  57. // Check for Minor importance messages to ignore...
  58. if (strncasecmp($log['message'], 'Minor', 5) === 0) {
  59. //Skip minor messages
  60. continue;
  61. }
  62. //Skip language update messages (not important)
  63. $langMsg = array(
  64. 'Update language terms',
  65. 'Update language vars',
  66. 'Update lang vars',
  67. 'Merge',
  68. 'merge',
  69. 'Scrutinizer Auto-Fixes',
  70. 'Update changelog',
  71. 'Fix PHP Warning'
  72. );
  73. foreach ($langMsg as $msg) {
  74. if (strpos($log['message'], $msg) === 0) {
  75. continue 2;
  76. }
  77. }
  78. // Look for tasks references
  79. $issueLink = '';
  80. $matches = array();
  81. if (preg_match_all('/((BT)?#(\d){2,5})/', $log['message'], $matches)) {
  82. $issue = $matches[0][0];
  83. if (substr($issue, 0, 1) == '#') {
  84. // not a BeezNest task
  85. $num = substr($issue, 1);
  86. if ($num > 4000) {
  87. //should be Chamilo support site
  88. if ($formatHTML) {
  89. $issueLink = ' - <a href="https://support.chamilo.org/issues/' . $num . '">CT#' . $num . '</a>';
  90. } else {
  91. $issueLink = ' - ' . $num;
  92. }
  93. } else {
  94. //should be Github
  95. if ($formatHTML) {
  96. $issueLink = ' - <a href="https://github.com/chamilo/chamilo-lms/issues/' . $num . '">GH#' . $num . '</a>';
  97. } else {
  98. $issueLink = ' - ' . $num;
  99. }
  100. }
  101. } else {
  102. $num = substr($issue, 3);
  103. if ($num != '7683') {
  104. if ($formatHTML) {
  105. //7683 is an internal task at BeezNest for all general contributions to Chamilo - no use in adding this reference
  106. $issueLink = ' - <a href="https://task.beeznest.com/issues/' . $num . '">BT#' . $num . '</a>';
  107. } else {
  108. $issueLink = ' - ' . $num;
  109. }
  110. }
  111. }
  112. if ($hasRefs = stripos($log['message'], ' see '.$issue)) {
  113. $log['message'] = substr($log['message'], 0, $hasRefs);
  114. }
  115. if ($hasRefs = stripos($log['message'], ' - ref')) {
  116. $log['message'] = substr($log['message'], 0, $hasRefs);
  117. }
  118. if ($hasRefs = stripos($log['message'], ' -refs ')) {
  119. $log['message'] = substr($log['message'], 0, $hasRefs);
  120. }
  121. }
  122. $commitLink = '';
  123. if ($formatHTML) {
  124. $log['message'] = ucfirst($log['message']);
  125. $commitLink = '<a href="https://github.com/chamilo/chamilo-lms/commit/' . $log['sha1'] . '">' .
  126. substr($log['sha1'], 0, 8) . '</a>';
  127. echo '<li>['.$commitDate.'] ('.$commitLink.$issueLink.') '.$log['message'].'</li>'.PHP_EOL;
  128. } else {
  129. $commitLink = substr($log['sha1'], 0, 8);
  130. echo '('.$commitLink.$issueLink.') '.$log['message'].''.PHP_EOL;
  131. }
  132. // check end commit to stop processing
  133. if ($endCommit) {
  134. $length = strlen($endCommit);
  135. if (substr($log['sha1'], 0, $length) == $endCommit) {
  136. echo "Found the end commit ".$endCommit.", exiting...".PHP_EOL;
  137. break;
  138. }
  139. }
  140. $i++;
  141. }
  142. echo "Printed $i commits of $number requested (others were minor)".PHP_EOL;