gitlog.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $git = new \SebastianBergmann\Git\Git($repository);
  24. echo $git->getCurrentBranch().PHP_EOL;
  25. $logs = $git->getRevisions('DESC', $number);
  26. $i = 0;
  27. foreach ($logs as $log) {
  28. //echo $log['date']->format('Y-m-d H:i:s').' '.substr($log['sha1'],0,8).PHP_EOL;
  29. if (strncasecmp($log['message'], 'Minor', 5) === 0) {
  30. //Skip minor messages
  31. continue;
  32. }
  33. $issueLink = '';
  34. $matches = array();
  35. if (preg_match_all('/((BT)?#(\d){2,5})/', $log['message'], $matches)) {
  36. $issue = $matches[0][0];
  37. if (substr($issue, 0, 1) == '#') {
  38. // not a BeezNest task
  39. $num = substr($issue, 1);
  40. if ($formatHTML) {
  41. $issueLink = ' - <a href="https://support.chamilo.org/issues/' . $num . '">#' . $num . '</a>';
  42. } else {
  43. $issueLink = ' - ' . $num;
  44. }
  45. } else {
  46. $num = substr($issue, 3);
  47. if ($formatHTML) {
  48. $issueLink = ' - <a href="https://task.beeznest.com/issues/' . $num . '">BT#' . $num . '</a>';
  49. } else {
  50. $issueLink = ' - ' . $num;
  51. }
  52. }
  53. if ($hasRefs = stripos($log['message'], ' see '.$issue)) {
  54. $log['message'] = substr($log['message'], 0, $hasRefs);
  55. }
  56. if ($hasRefs = stripos($log['message'], ' - ref')) {
  57. $log['message'] = substr($log['message'], 0, $hasRefs);
  58. }
  59. if ($hasRefs = stripos($log['message'], ' -refs ')) {
  60. $log['message'] = substr($log['message'], 0, $hasRefs);
  61. }
  62. }
  63. $commitLink = '';
  64. if ($formatHTML) {
  65. $commitLink = '<a href="https://github.com/chamilo/chamilo-lms/commit/' . $log['sha1'] . '">' .
  66. substr($log['sha1'], 0, 8) . '</a>';
  67. echo '<li>('.$commitLink.$issueLink.') '.$log['message'].'</li>'.PHP_EOL;
  68. } else {
  69. $commitLink = substr($log['sha1'], 0, 8);
  70. echo '('.$commitLink.$issueLink.') '.$log['message'].''.PHP_EOL;
  71. }
  72. $i++;
  73. }
  74. echo "Printed $i commits of $number requested (others were minor)".PHP_EOL;