2
0

git.class.php 1011 B

12345678910111213141516171819202122232425262728293031323334
  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 printVersion(){
  19. echo sprintf(
  20. '<h6>%s <span class="badge bg-success">%s</span></h6>
  21. <code>%s</code>
  22. <div class="media-body pb-3 mb-0 small lh-125">Le %s</div>',
  23. self::getCommitAuthor(),
  24. self::getCommitHash(),
  25. self::getCommitName(),
  26. self::getCommitDate()
  27. );
  28. }
  29. }