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

Merged
merged 1 commit into from
Jan 20, 2025
Merged
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
fix(other): display commited date instead of the pull request creatio…
…n date
Baraka24 committed Jan 17, 2025
commit 4c1b97c5b0039240755ed1f0cfeb1babf848be8d
19 changes: 18 additions & 1 deletion modules/developer/modules.php
Original file line number Diff line number Diff line change
@@ -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);
@@ -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;
}
}
}
}
}
}