Refactor git and resume
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tyler Perkins 2022-12-22 20:08:33 -05:00
parent cbb7490069
commit bd966f576b
4 changed files with 46 additions and 35 deletions

View File

@ -1,52 +1,60 @@
<?php
function getResumeReleases() {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/repos/tyler/Resume/releases?per_page=1&access_token=" . getenv("GITEA_TOKEN"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if(!$result){
header('HTTP/1.1 500 Internal Server Error');
die();
class Gitea {
private $giteaToken;
public function __construct(String $token) {
$this->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"];
}
?>

View File

@ -2,7 +2,7 @@
<link rel="stylesheet" href="/common/header.css">
<nav class="navbar sticky">
<a href="/">Home</a>
<a href="/resume.php">Resume</a>
<a href="/resume">Resume</a>
<a href="https://git.clortox.com">Git</a>
<a href="/utilities/">Utilities</a>
<a href="https://wiki.clortox.com">Wiki</a>

View File

@ -32,7 +32,8 @@
<h3>Projects</h3>
<div>
<?php
$result = getRecentProjects();
$giteaClient = new Gitea(getenv("GITEA_TOKEN"));
$result = $giteaClient->getRecentProjects();
array_splice($result, 6, -1);
foreach($result as $item){
if($item["private"])

View File

@ -1,8 +1,10 @@
<?php
include 'common/git.php';
include '../common/git.php';
$parsed = json_decode(getResumeReleases(), true);
$giteaClient = new Gitea(getenv('GITEA_TOKEN'));
$parsed = json_decode($giteaClient->getResumeReleases(), true);
$url = $parsed[0]["assets"][0]["browser_download_url"];
if(!$url){