From ecbf410b50e0cd15859a9f0010b7de01275a2c22 Mon Sep 17 00:00:00 2001 From: Austin Best Date: Wed, 31 Jan 2024 21:48:07 -0500 Subject: [PATCH] Fix some issues with the overview and contributors pages Some organizational things --- root/app/www/public/ajax/contributors.php | 31 ++++++++----- root/app/www/public/ajax/overview.php | 8 ++-- .../www/public/classes/traits/Git/Commits.php | 2 +- .../classes/traits/Git/Contributors.php | 2 +- root/app/www/public/functions/common.php | 44 ------------------- .../www/public/functions/helpers/arrays.php | 23 ++++++++++ .../www/public/functions/helpers/filesize.php | 37 ++++++++++++++++ .../www/public/functions/helpers/strings.php | 13 ++++++ root/app/www/public/js/git.js | 1 + root/app/www/public/loader.php | 9 ++++ 10 files changed, 110 insertions(+), 60 deletions(-) create mode 100644 root/app/www/public/functions/helpers/arrays.php create mode 100644 root/app/www/public/functions/helpers/filesize.php create mode 100644 root/app/www/public/functions/helpers/strings.php diff --git a/root/app/www/public/ajax/contributors.php b/root/app/www/public/ajax/contributors.php index 14f1817..e8b4863 100644 --- a/root/app/www/public/ajax/contributors.php +++ b/root/app/www/public/ajax/contributors.php @@ -25,11 +25,20 @@ if (str_contains($author, '<')) { list($author, $email) = explode('<', $author); } - $author = trim($author); + $author = trim($author); + + if (!$author) { + continue; + } + $authorStats = $git->contributorStats($author); $commitHistory = $git->contributorCommits($author); $newestCommit = $commitHistory['shell'][1]; + if (empty($newestCommit)) { + continue; + } + $changed = $added = $removed = 0; foreach ($authorStats['shell'] as $line) { @@ -120,17 +129,19 @@
- - Commit:
- Date:
-
  • ', array_slice($newestCommit, 3)) ?>
- No commit information found.
+ Date:
+
    +
  • +
diff --git a/root/app/www/public/ajax/overview.php b/root/app/www/public/ajax/overview.php index ce1752a..cf90906 100644 --- a/root/app/www/public/ajax/overview.php +++ b/root/app/www/public/ajax/overview.php @@ -37,7 +37,7 @@ if (count($commits) > ($newest + $oldest)) { $newestCommits = $oldestCommits = []; - $hidden = count($commits) - ($newest + $oldest); + $hidden = $totalCommits['shell'] - ($newest + $oldest); $newestCommits = array_slice($commits, 0, $newest); $oldestCommits = array_slice($commits, ($oldest * -1)); @@ -127,15 +127,15 @@

Repository

-
Commits
+
Commits

-
Objects
+
Objects

-
Size
+
Size

diff --git a/root/app/www/public/classes/traits/Git/Commits.php b/root/app/www/public/classes/traits/Git/Commits.php index 689bb59..fa0c653 100644 --- a/root/app/www/public/classes/traits/Git/Commits.php +++ b/root/app/www/public/classes/traits/Git/Commits.php @@ -11,7 +11,7 @@ trait Commits { public function totalCommits() { - $cmd = $this->cd . 'git rev-list --count --all'; + $cmd = $this->cd . 'git rev-list --count --all --first-parent'; $shell = shell_exec($cmd); return ['cmd' => $cmd, 'shell' => $shell]; diff --git a/root/app/www/public/classes/traits/Git/Contributors.php b/root/app/www/public/classes/traits/Git/Contributors.php index 9df79be..81374df 100644 --- a/root/app/www/public/classes/traits/Git/Contributors.php +++ b/root/app/www/public/classes/traits/Git/Contributors.php @@ -21,7 +21,7 @@ public function contributorCommits($author) { $cmd = $this->cd . 'git log --author="' . $author . '"'; $shell = explode("\n", shell_exec($cmd)); - + $userCommits = []; $counter = 0; foreach ($shell as $index => $commitLine) { diff --git a/root/app/www/public/functions/common.php b/root/app/www/public/functions/common.php index f89cd0a..d1cebad 100644 --- a/root/app/www/public/functions/common.php +++ b/root/app/www/public/functions/common.php @@ -57,47 +57,3 @@ function randomColor($existingColors) return $color; } } - -function byteConversion($bytes, $measurement = false, $dec = 2) -{ - if (!$bytes || $bytes <= 0) { - return 0; - } - - //-- SEND LARGEST ONE - if (!$measurement) { - $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']; - $bytes = max($bytes, 0); - $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); - $pow = min($pow, count($units) - 1); - $bytes /= (1 << (10 * $pow)); - - return round($bytes, $dec) . ' ' . $units[$pow]; - } - - switch ($measurement) { - case 'KiB': - return round($bytes / 1024, $dec); - case 'MiB': - return round($bytes / pow(1024, 2), $dec); - case 'GiB': - return round($bytes / pow(1024, 3), $dec); - case 'TiB': - return round($bytes / pow(1024, 4), $dec); - } -} - -function array_sort_by_key(&$array, $field, $direction = 'asc') -{ - if (!is_array($array)) { - return $array; - } - - uasort($array, function ($a, $b) use ($field, $direction) { - if ($direction == 'asc') { - return $a[$field] <=> $b[$field]; - } else { - return $b[$field] <=> $a[$field]; - } - }); -} diff --git a/root/app/www/public/functions/helpers/arrays.php b/root/app/www/public/functions/helpers/arrays.php new file mode 100644 index 0000000..5995360 --- /dev/null +++ b/root/app/www/public/functions/helpers/arrays.php @@ -0,0 +1,23 @@ + $b[$field]; + } else { + return $b[$field] <=> $a[$field]; + } + }); +} diff --git a/root/app/www/public/functions/helpers/filesize.php b/root/app/www/public/functions/helpers/filesize.php new file mode 100644 index 0000000..bf56843 --- /dev/null +++ b/root/app/www/public/functions/helpers/filesize.php @@ -0,0 +1,37 @@ + $a || str_contains($haystack, $n), false); +} diff --git a/root/app/www/public/js/git.js b/root/app/www/public/js/git.js index 64864a6..518a808 100644 --- a/root/app/www/public/js/git.js +++ b/root/app/www/public/js/git.js @@ -1,6 +1,7 @@ function gitPull() { const repository = $('#active-repository').val(); + $('#page-content').html(' Gathering all the data, crunching all the numbers...'); $.ajax({ type: 'POST', diff --git a/root/app/www/public/loader.php b/root/app/www/public/loader.php index 4f30a13..af90f45 100644 --- a/root/app/www/public/loader.php +++ b/root/app/www/public/loader.php @@ -46,6 +46,15 @@ } closedir($handle); +$dir = ABSOLUTE_PATH . 'functions/helpers'; +$handle = opendir($dir); +while ($file = readdir($handle)) { + if ($file[0] != '.' && !is_dir($dir . '/' . $file)) { + require $dir . '/' . $file; + } +} +closedir($handle); + //-- INCLUDE CLASSES $dir = ABSOLUTE_PATH . 'classes'; $handle = opendir($dir);