Skip to content

Commit

Permalink
Merge pull request cypht-org#1417 from Baraka24/fix-server-info-commi…
Browse files Browse the repository at this point in the history
…t_date

fix(other): display commited date instead of the pull request creation date
  • Loading branch information
kroky authored Jan 20, 2025
2 parents bbb1e89 + 4c1b97c commit 84232a2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion modules/developer/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function process() {
}

if ($commit_hash != '-') {
// Get right commit date (not merge date) if not a local commit
// Get the correct commit date (merged PR date or commit date)
$ch = Hm_Functions::c_init();
if ($ch) {
Hm_Functions::c_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/cypht-org/cypht/commits/'.$commit_hash);
Expand All @@ -63,6 +63,23 @@ public function process() {
if (!mb_strstr($curl_result, 'No commit found for SHA')) {
$json_commit = json_decode($curl_result);
$commit_date = $json_commit->commit->author->date;

// Now check if this commit is part of a PR and if it was merged
$pr_ch = Hm_Functions::c_init();
if ($pr_ch) {
Hm_Functions::c_setopt($pr_ch, CURLOPT_URL, 'https://api.github.com/repos/cypht-org/cypht/commits/'.$commit_hash.'/pulls');
Hm_Functions::c_setopt($pr_ch, CURLOPT_RETURNTRANSFER, 1);
Hm_Functions::c_setopt($pr_ch, CURLOPT_CONNECTTIMEOUT, 1);
Hm_Functions::c_setopt($pr_ch, CURLOPT_USERAGENT, $this->request->server["HTTP_USER_AGENT"]);
$pr_curl_result = Hm_Functions::c_exec($pr_ch);

if (trim($pr_curl_result)) {
$json_pr = json_decode($pr_curl_result);
if (isset($json_pr[0]->merged_at)) {
$commit_date = $json_pr[0]->merged_at;
}
}
}
}
}
}
Expand Down

0 comments on commit 84232a2

Please sign in to comment.