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 <?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); class Gitea {
if(!$result){ private $giteaToken;
header('HTTP/1.1 500 Internal Server Error');
die(); 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() { return $result;
$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);
$result = curl_exec($curl);
if(!$result){
header('HTTP/1.1 500 Internal Server Error');
die();
} }
curl_close($curl); public function getRecentProjects() : array {
//now we need to parse out the results into a nice array containing the $curl = curl_init();
//most recent items 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) { function datecmp($lhs, $rhs) {
return $lhs["updated_at"] < $rhs["updated_at"]; return $lhs["updated_at"] < $rhs["updated_at"];
} }
?> ?>

View File

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

View File

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

View File

@ -1,8 +1,10 @@
<?php <?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"]; $url = $parsed[0]["assets"][0]["browser_download_url"];
if(!$url){ if(!$url){