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,7 +1,15 @@
<?php <?php
function getResumeReleases() {
class Gitea {
private $giteaToken;
public function __construct(String $token) {
$this->giteaToken = $token;
}
public function getResumeReleases() : String {
$curl = curl_init(); $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_URL, "https://git.clortox.com/api/v1/repos/tyler/Resume/releases?per_page=1&access_token=" . $this->giteaToken);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl); $result = curl_exec($curl);
@ -14,11 +22,11 @@ function getResumeReleases() {
return $result; return $result;
} }
function getRecentProjects() { public function getRecentProjects() : array {
$curl = curl_init(); $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_URL, "https://git.clortox.com/api/v1/user/repos?page=1&limit=100&access_token=" . $this->giteaToken);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl); $result = curl_exec($curl);
@ -42,11 +50,11 @@ function getRecentProjects() {
usort($ret, "datecmp"); usort($ret, "datecmp");
return $ret; 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){