Skip to content

Commit

Permalink
fix(server-info): display commited date instead of the pull request c…
Browse files Browse the repository at this point in the history
…reation date
  • Loading branch information
Baraka24 committed Jan 2, 2025
1 parent 32d2d9c commit fe144a8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions modules/developer/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ class Hm_Output_server_information extends Hm_Output_Module {
protected function output() {
$server_info = $this->get('server_info', array());
if (!empty($server_info)) {
$commit_hash = $server_info['commit_hash'];
$commit_date = $this->getCommitDate($commit_hash);
$server_info['commit_date'] = $this->formatCommitDate($commit_date);

return '<div class="server_info p-3"><table class="info table table-borderless">'.
'<tr><th class="text-secondary fw-light text-nowrap">Server Name</th><td>'.$server_info['HTTP_HOST'].'</td></tr>'.
'<tr><th class="text-secondary fw-light text-nowrap">Server Scheme</th><td>'.$server_info['REQUEST_SCHEME'].'</td></tr>'.
Expand All @@ -182,6 +186,27 @@ protected function output() {
}
return '';
}

/**
* Fetches the commit date based on the commit hash
* @param string $commit_hash The commit hash
* @return string The commit date
*/
protected function getCommitDate($commit_hash) {
$command = 'git log -1 --format=%cd ' . escapeshellarg($commit_hash);
$commit_date = shell_exec($command);
return trim($commit_date);
}

/**
* Formats the commit date to a more readable format like "Nov 27, 2024"
* @param string $commit_date The original commit date
* @return string The formatted commit date
*/
protected function formatCommitDate($commit_date) {
$date = new DateTime($commit_date);
return $date->format('M d, Y');
}
}

/**
Expand Down

0 comments on commit fe144a8

Please sign in to comment.