git.class.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. class git
  3. {
  4. public static function getCommitHash(){
  5. return substr(trim(exec('git log --pretty="%H" -n1 HEAD')), 0, 10);
  6. }
  7. public static function getCommitDate(){
  8. $commitDate = new \DateTime(trim(exec('git log -n1 --pretty=%ci HEAD')));
  9. $commitDate->setTimezone(new \DateTimeZone('UTC'));
  10. return $commitDate->format('d/m/Y à H:i:s');
  11. }
  12. public static function getCommitAuthor(){
  13. return exec('git log --pretty="%cn" -n1 HEAD');
  14. }
  15. public static function getCommitName(){
  16. return exec('git log --pretty="%s" -n1 HEAD');
  17. }
  18. public static function getBranchName(){
  19. return exec('git rev-parse --abbrev-ref HEAD');
  20. }
  21. public static function printVersion(){
  22. echo sprintf(
  23. '<h6>%s <span class="badge bg-info">%s</span> <span class="badge bg-success">%s</span></h6>
  24. <code>%s</code>
  25. <div class="media-body pb-3 mb-0 small lh-125">Le %s</div>',
  26. self::getCommitAuthor(),
  27. self::getBranchName(),
  28. self::getCommitHash(),
  29. self::getCommitName(),
  30. self::getCommitDate()
  31. );
  32. }
  33. }