Skip to content

Commit

Permalink
Fix some issues with the overview and contributors pages
Browse files Browse the repository at this point in the history
Some organizational things
  • Loading branch information
austinwbest committed Feb 1, 2024
1 parent 17764dc commit ecbf410
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 60 deletions.
31 changes: 21 additions & 10 deletions root/app/www/public/ajax/contributors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -120,17 +129,19 @@
<div class="col-lg-4 col-sm-12">
<div class="card mt-2">
<div class="card-body">
<?php
if (!empty($newestCommit)) {
?>
Commit: <?= substr(trim(str_replace('commit', '', $newestCommit[0])), 0, 7) ?><br>
Date: <?= trim(str_replace('Date:', '', $newestCommit[2])) ?><br>
<ul><li><?= implode('</li><li>', array_slice($newestCommit, 3)) ?></li></ul>
<?php
} else {
?>No commit information found.<?php
Commit: <?= substr(trim(str_replace('commit', '', $newestCommit[0])), 0, 7) ?><br>
Date: <?= trim(str_replace('Date:', '', $newestCommit[2])) ?><br>
<ul>
<?php
$notes = array_slice($newestCommit, 3);
foreach ($notes as $note) {
if (str_contains_any($note, ['Author:', 'Date:', 'Merge:', 'Signed-off-by:', 'Co-authored-by:']) || substr($note, 0, 7) == 'commit ') {
continue;
}
?><li><?= $note ?></li><?php
}
?>
</ul>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions root/app/www/public/ajax/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -127,15 +127,15 @@
<h4 class="card-title">Repository</h4>
<div class="bg-gray-dark d-flex d-md-block d-xl-flex flex-row py-3 px-4 px-md-3 px-xl-4 rounded mt-3">
<div class="text-md-center text-xl-left me-5">
<h6 class="mb-1">Commits</h6>
<h6 class="mb-1">Commits <i class="far fa-question-circle text-primary" title="Unique commits; no merges, etc"></i></h6>
<p class="text-muted mb-0"><?= number_format($totalCommits['shell']) ?></p>
</div>
<div class="text-md-center text-xl-left me-5">
<h6 class="mb-1">Objects</h6>
<h6 class="mb-1">Objects <i class="far fa-question-circle text-primary" title="Packed & loose objects"></i></h6>
<p class="text-muted mb-0"><?= $repoObjects ?></p>
</div>
<div class="text-md-center text-xl-left me-5">
<h6 class="mb-1">Size</h6>
<h6 class="mb-1">Size <i class="far fa-question-circle text-primary" title="Packed & loose files"></i></h6>
<p class="text-muted mb-0"><?= $repoSize ?></p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion root/app/www/public/classes/traits/Git/Commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion root/app/www/public/classes/traits/Git/Contributors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
44 changes: 0 additions & 44 deletions root/app/www/public/functions/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
}
23 changes: 23 additions & 0 deletions root/app/www/public/functions/helpers/arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
----------------------------------
------ Created: 013124 ------
------ Austin Best ------
----------------------------------
*/

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];
}
});
}
37 changes: 37 additions & 0 deletions root/app/www/public/functions/helpers/filesize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
----------------------------------
------ Created: 013124 ------
------ Austin Best ------
----------------------------------
*/

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);
}
}
13 changes: 13 additions & 0 deletions root/app/www/public/functions/helpers/strings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/*
----------------------------------
------ Created: 013124 ------
------ Austin Best ------
----------------------------------
*/

function str_contains_any(string $haystack, array $needles): bool
{
return array_reduce($needles, fn($a, $n) => $a || str_contains($haystack, $n), false);
}
1 change: 1 addition & 0 deletions root/app/www/public/js/git.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function gitPull()
{
const repository = $('#active-repository').val();
$('#page-content').html('<i class="fas fa-cog fa-spin"></i> Gathering all the data, crunching all the numbers...');

$.ajax({
type: 'POST',
Expand Down
9 changes: 9 additions & 0 deletions root/app/www/public/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ecbf410

Please sign in to comment.