Skip to content

Commit

Permalink
Move git methods to the files that use them
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Feb 1, 2024
1 parent ecbf410 commit bd5ae51
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 40 deletions.
3 changes: 3 additions & 0 deletions root/app/www/public/ajax/branches.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
if ($_POST['m'] == 'init') {
?><h3>Branches <br><code><?= $repository ?></code></h3><hr><?php

$branches = $git->branches();
$branchHeads = $git->branchHeads();

$remoteLabel = false;
?>
<div class="row">
Expand Down
18 changes: 18 additions & 0 deletions root/app/www/public/ajax/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
if ($_POST['m'] == 'init') {
?><h3>Code <br><code><?= $repository ?></code></h3><hr><?php

$totalLines = $git->totalLines();
$fileTypes = [];

foreach ($totalLines['shell'] as $file) {
$fileParts = array_filter(explode(' ', $file));
sort($fileParts, SORT_NUMERIC);

if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) {
$filePathParts = explode('.', $fileParts[0]);
$extension = trim(end($filePathParts));

if (!in_array($extension, $ignoreCodePageExtensions) && !str_contains($extension, '/') && $extension) {
$fileTypes[$extension]['files']++;
$fileTypes[$extension]['lines'] += intval($fileParts[1]);
}
}
}

$labels = $dataFiles = $dataLines = $colors = '';
$usedColors = [];
array_sort_by_key($fileTypes, 'lines', 'desc');
Expand Down
2 changes: 2 additions & 0 deletions root/app/www/public/ajax/commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
if ($_POST['m'] == 'init') {
?><h3>Commits <br><code><?= $repository ?></code></h3><hr><?php

$overview = $git->log();

$regex = '/{(?<hash>(.*))}~{(?<date>(.*))}~{(?<relative>(.*))}~{(?<branch>(.*))}~{(?<note>(.*))}~{(?<authorName>(.*))}~{(?<authorEmail>(.*))}/';

$yearData = $monthData = $weekData = $dayData = [];
Expand Down
2 changes: 2 additions & 0 deletions root/app/www/public/ajax/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

require 'shared.php';

$branches = $git->branches();

if ($_POST['m'] == 'loadRepositoryBranches') {
foreach ($branches['shell'] as $branch) {
$branchOptions .= '<option ' . (str_contains($branch, '*') ? 'selected' : '') . ' value="' . trim($branch) . '">' . trim($branch) . '</option>';
Expand Down
3 changes: 3 additions & 0 deletions root/app/www/public/ajax/contributors.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
if ($_POST['m'] == 'init') {
?><h3>Contributors <br><code><?= $repository ?></code></h3><hr><?php

$contributors = $git->contributors();
$totalCommits = $git->totalCommits();

?><div class="row"><?php

foreach ($contributors['shell'] as $contributor) {
Expand Down
37 changes: 37 additions & 0 deletions root/app/www/public/ajax/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@
if ($_POST['m'] == 'init') {
?><h3>Overview <br><code><?= $repository ?></code></h3><hr><?php

$repoObjects = $git->size();
$overview = $git->log();
$branches = $git->branches();
$contributors = $git->contributors();
$totalFiles = $git->totalFiles();
$totalCommits = $git->totalCommits();
$totalLines = $git->totalLines();
$linesOfCode = 0;
$fileTypes = [];

foreach ($totalLines['shell'] as $file) {
$fileParts = array_filter(explode(' ', $file));
sort($fileParts, SORT_NUMERIC);
$linesOfCode += intval($fileParts[1]);

if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) {
$filePathParts = explode('.', $fileParts[0]);
$extension = trim(end($filePathParts));

if (!in_array($extension, $ignoreCodePageExtensions) && !str_contains($extension, '/') && $extension) {
$fileTypes[$extension]['files']++;
$fileTypes[$extension]['lines'] += intval($fileParts[1]);
}
}
}

foreach ($repoObjects['shell'] as $repoSizeObject) {
if (str_contains($repoSizeObject, 'count') || str_contains($repoSizeObject, 'in-pack')) {
$repoObjectCount += preg_replace("/[^0-9]/", '', $repoSizeObject);
}
if (str_contains($repoSizeObject, 'size') || str_contains($repoSizeObject, 'size-pack')) {
$repoSizeTotal += preg_replace("/[^0-9]/", '', $repoSizeObject);
}
}
$repoObjects = number_format(intval($repoObjectCount));
$repoSize = byteConversion(intval($repoSizeTotal) * 1000);

$regex = '/{(?<hash>(.*))}~{(?<date>(.*))}~{(?<relative>(.*))}~{(?<branch>(.*))}~{(?<note>(.*))}~{(?<authorName>(.*))}~{(?<authorEmail>(.*))}/';

//-- GET MAX WIDTH
Expand Down
40 changes: 0 additions & 40 deletions root/app/www/public/ajax/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,3 @@

$repository = $_POST['repository'];
$git = new Git($repository);

if ($_POST['page'] != 'settings') {
$repoObjects = $git->size();
$overview = $git->log();
$branches = $git->branches();
$contributors = $git->contributors();
$totalFiles = $git->totalFiles();
$totalCommits = $git->totalCommits();
$totalLines = $git->totalLines();
$branchHeads = $git->branchHeads();
$linesOfCode = 0;
$fileTypes = [];

foreach ($repoObjects['shell'] as $repoSizeObject) {
if (str_contains($repoSizeObject, 'count') || str_contains($repoSizeObject, 'in-pack')) {
$repoObjectCount += preg_replace("/[^0-9]/", '', $repoSizeObject);
}
if (str_contains($repoSizeObject, 'size') || str_contains($repoSizeObject, 'size-pack')) {
$repoSizeTotal += preg_replace("/[^0-9]/", '', $repoSizeObject);
}
}
$repoObjects = number_format(intval($repoObjectCount));
$repoSize = byteConversion(intval($repoSizeTotal) * 1000);

foreach ($totalLines['shell'] as $file) {
$fileParts = array_filter(explode(' ', $file));
sort($fileParts, SORT_NUMERIC);
$linesOfCode += intval($fileParts[1]);

if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) {
$filePathParts = explode('.', $fileParts[0]);
$extension = trim(end($filePathParts));

if (!in_array($extension, $ignoreCodePageExtensions) && !str_contains($extension, '/') && $extension) {
$fileTypes[$extension]['files']++;
$fileTypes[$extension]['lines'] += intval($fileParts[1]);
}
}
}
}

0 comments on commit bd5ae51

Please sign in to comment.