From bd966f576b16c093f76268f08734497b36e81e2b Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Thu, 22 Dec 2022 20:08:33 -0500 Subject: [PATCH] Refactor git and resume --- src/common/git.php | 70 ++++++++++++++++------------ src/common/header.php | 2 +- src/index.php | 3 +- src/{resume.php => resume/index.php} | 6 ++- 4 files changed, 46 insertions(+), 35 deletions(-) rename src/{resume.php => resume/index.php} (76%) diff --git a/src/common/git.php b/src/common/git.php index ca31a3a..898e2d1 100644 --- a/src/common/git.php +++ b/src/common/git.php @@ -1,52 +1,60 @@ giteaToken = $token; } - curl_close($curl); + public function getResumeReleases() : String { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/repos/tyler/Resume/releases?per_page=1&access_token=" . $this->giteaToken); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - return $result; + $result = curl_exec($curl); + if(!$result){ + header('HTTP/1.1 500 Internal Server Error'); + die(); + } -} + curl_close($curl); -function getRecentProjects() { - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/user/repos?page=1&limit=100&access_token=" . getenv("GITEA_TOKEN")); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + return $result; - $result = curl_exec($curl); - if(!$result){ - header('HTTP/1.1 500 Internal Server Error'); - die(); } - curl_close($curl); - //now we need to parse out the results into a nice array containing the - //most recent items + public function getRecentProjects() : array { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/user/repos?page=1&limit=100&access_token=" . $this->giteaToken); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - $parsed = json_decode($result, true); + $result = curl_exec($curl); + if(!$result){ + header('HTTP/1.1 500 Internal Server Error'); + die(); + } - $ret = array(); + curl_close($curl); + //now we need to parse out the results into a nice array containing the + //most recent items + + $parsed = json_decode($result, true); + + $ret = array(); + + foreach($parsed as $item){ + array_push($ret, $item); + } + + usort($ret, "datecmp"); + return $ret; - foreach($parsed as $item){ - array_push($ret, $item); } - usort($ret, "datecmp"); - return $ret; - } function datecmp($lhs, $rhs) { return $lhs["updated_at"] < $rhs["updated_at"]; } - - ?> diff --git a/src/common/header.php b/src/common/header.php index 27974dd..9c667a5 100644 --- a/src/common/header.php +++ b/src/common/header.php @@ -2,7 +2,7 @@