2
0

git.class.php 920 B

1234567891011121314151617181920212223242526272829303132
  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</h6></div><div>%s (%s)</div>',
  21. self::getCommitAuthor(),
  22. self::getCommitHash(),
  23. self::getCommitName(),
  24. self::getCommitDate()
  25. );
  26. }
  27. }