Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(other): display commited date instead of the pull request creation date #1417

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cypht might not have a local git repo - there are other distribution channels than git pull... see Hm_Handler_process_server_info for more info on how it gets commit hash and tries to get the date from github API endpoint. I think you should change that class rather than add more code here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay noted.

$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
Loading