Save to database #13

Merged
haylan merged 42 commits from save-to-database into main 2026-07-12 21:51:57 +00:00
35 changed files with 122 additions and 68 deletions
Showing only changes of commit 41e88144a4 - Show all commits
+1 -1
View File
@@ -184,7 +184,7 @@ PHP `max_execution_time` fatal can't be caught by `try/catch` at all, so
- [ ] `.env` — document `CONTRIBUTIONS_RETENTION_DAYS` (empty by default), - [ ] `.env` — document `CONTRIBUTIONS_RETENTION_DAYS` (empty by default),
same style as the existing `ALLOWED_HOSTS` comment. same style as the existing `ALLOWED_HOSTS` comment.
## 9. `app:contributions:refetch` console command ## 9. `graph:contributions:refetch` console command
Manual escape hatch for forcing a full or ranged re-fetch (e.g. after Manual escape hatch for forcing a full or ranged re-fetch (e.g. after
adding a new host, or if the store needs rebuilding) — bypasses step 5's adding a new host, or if the store needs rebuilding) — bypasses step 5's
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
use App\Kernel; use GitContributionGraph\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
+2 -2
View File
@@ -16,12 +16,12 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "src/" "GitContributionGraph\\": "src/"
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"App\\Tests\\": "tests/" "GitContributionGraph\\Tests\\": "tests/"
} }
}, },
"require-dev": { "require-dev": {
+1 -1
View File
@@ -1,5 +1,5 @@
controllers: controllers:
resource: resource:
path: ../src/Controller/ path: ../src/Controller/
namespace: App\Controller namespace: GitContributionGraph\Controller
type: attribute type: attribute
+6 -6
View File
@@ -16,32 +16,32 @@ services:
autoconfigure: true autoconfigure: true
public: false public: false
App\: GitContributionGraph\:
resource: "../src/" resource: "../src/"
exclude: exclude:
- "../src/Kernel.php" - "../src/Kernel.php"
_instanceof: _instanceof:
App\Service\Provider\ProviderInterface: GitContributionGraph\Service\Provider\ProviderInterface:
tags: ["app.provider"] tags: ["app.provider"]
App\Service\Provider\GitHubProvider: GitContributionGraph\Service\Provider\GitHubProvider:
arguments: arguments:
$username: "%env(GITHUB_USER)%" $username: "%env(GITHUB_USER)%"
$token: "%env(GITHUB_TOKEN)%" $token: "%env(GITHUB_TOKEN)%"
App\Service\Provider\GitLabProvider: GitContributionGraph\Service\Provider\GitLabProvider:
arguments: arguments:
$username: "%env(GITLAB_USER)%" $username: "%env(GITLAB_USER)%"
$token: "%env(GITLAB_TOKEN)%" $token: "%env(GITLAB_TOKEN)%"
$baseUrl: "%env(GITLAB_URL)%" $baseUrl: "%env(GITLAB_URL)%"
App\Service\Provider\GiteaProvider: GitContributionGraph\Service\Provider\GiteaProvider:
arguments: arguments:
$username: "%env(GITEA_USER)%" $username: "%env(GITEA_USER)%"
$token: "%env(GITEA_TOKEN)%" $token: "%env(GITEA_TOKEN)%"
$baseUrl: "%env(GITEA_URL)%" $baseUrl: "%env(GITEA_URL)%"
App\Service\ContributionStore: GitContributionGraph\Service\ContributionStore:
arguments: arguments:
$dbPath: "%kernel.project_dir%/var/data/contributions.db" $dbPath: "%kernel.project_dir%/var/data/contributions.db"
$retentionDays: "%env(int:CONTRIBUTIONS_RETENTION_DAYS)%" $retentionDays: "%env(int:CONTRIBUTIONS_RETENTION_DAYS)%"
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
use App\Kernel; use GitContributionGraph\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
use App\Kernel; use GitContributionGraph\Kernel;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
require_once dirname(__DIR__).'/vendor/autoload.php'; require_once dirname(__DIR__).'/vendor/autoload.php';
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace GitContributionGraph\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
#[AsCommand(name: 'graph:contributions:refetch')]
class RefetchContributionsCommand extends Command
{
private SymfonyStyle $io;
public function __construct(
#[AutowireIterator('app.provider')]
private readonly iterable $providers,
) {
parent::__construct();
}
public function initialize(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
}
public function __invoke(
//TODO: check if its possible to add the preview with real strings from the providers.
#[Option("(repeatable/comma-split, restricts to named provider(s), default = all configured", "provider", "p", "")]
string $providers = ""
) {
$requested = $providers === '' ? null : explode(',', $providers);
$byName = [];
foreach ($this->providers as $provider) {
$byName[$provider->getName()] = $provider;
}
if ($requested !== null) {
foreach ($requested as $name) {
if (!isset($byName[$name])) {
$this->io->error("Unknown provider: {$name}");
return Command::FAILURE;
}
}
$byName = array_intersect_key($byName, array_flip($requested));
}
}
}
+4 -4
View File
@@ -2,11 +2,11 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Controller; namespace GitContributionGraph\Controller;
use App\Service\ContributionAggregator; use GitContributionGraph\Service\ContributionAggregator;
use App\Service\Provider\ProviderHealthChecker; use GitContributionGraph\Service\Provider\ProviderHealthChecker;
use App\Service\Renderer\SvgRenderer; use GitContributionGraph\Service\Renderer\SvgRenderer;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Entity; namespace GitContributionGraph\Entity;
final class Contribution final class Contribution
{ {
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Entity; namespace GitContributionGraph\Entity;
/** /**
* @implements \IteratorAggregate<int, Contribution> * @implements \IteratorAggregate<int, Contribution>
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace App; namespace GitContributionGraph;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\HttpKernel\Kernel as BaseKernel;
+2 -2
View File
@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service; namespace GitContributionGraph\Service;
use App\Service\Provider\ProviderInterface; use GitContributionGraph\Service\Provider\ProviderInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
+3 -3
View File
@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service; namespace GitContributionGraph\Service;
use App\Entity\Contribution; use GitContributionGraph\Entity\Contribution;
use App\Entity\ContributionCollection; use GitContributionGraph\Entity\ContributionCollection;
use PDO; use PDO;
class ContributionStore class ContributionStore
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
enum ProviderErrorCode: string enum ProviderErrorCode: string
{ {
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
interface ProviderInterface interface ProviderInterface
{ {
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
final class ProviderStatus final class ProviderStatus
{ {
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Provider; namespace GitContributionGraph\Service\Provider;
enum ProviderStatusType: string enum ProviderStatusType: string
{ {
+1 -1
View File
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service\Renderer; namespace GitContributionGraph\Service\Renderer;
/** /**
* Renders a GitHub-style contribution heatmap as an inline SVG. * Renders a GitHub-style contribution heatmap as an inline SVG.
@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Entity; namespace GitContributionGraph\Tests\Unit\Entity;
use App\Entity\Contribution; use GitContributionGraph\Entity\Contribution;
use App\Entity\ContributionCollection; use GitContributionGraph\Entity\ContributionCollection;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
+2 -2
View File
@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Entity; namespace GitContributionGraph\Tests\Unit\Entity;
use App\Entity\Contribution; use GitContributionGraph\Entity\Contribution;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service; namespace GitContributionGraph\Tests\Unit\Service;
use App\Service\ContributionAggregator; use GitContributionGraph\Service\ContributionAggregator;
use App\Service\Provider\ProviderInterface; use GitContributionGraph\Service\Provider\ProviderInterface;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
+2 -2
View File
@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service; namespace GitContributionGraph\Tests\Unit\Service;
use App\Service\ContributionStore; use GitContributionGraph\Service\ContributionStore;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service\Provider; namespace GitContributionGraph\Tests\Unit\Service\Provider;
use App\Service\Provider\GitHubProvider; use GitContributionGraph\Service\Provider\GitHubProvider;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service\Provider; namespace GitContributionGraph\Tests\Unit\Service\Provider;
use App\Service\Provider\GitLabProvider; use GitContributionGraph\Service\Provider\GitLabProvider;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service\Provider; namespace GitContributionGraph\Tests\Unit\Service\Provider;
use App\Service\Provider\GiteaProvider; use GitContributionGraph\Service\Provider\GiteaProvider;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,12 +2,12 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service\Provider; namespace GitContributionGraph\Tests\Unit\Service\Provider;
use App\Service\Provider\ProbeTrait; use GitContributionGraph\Service\Provider\ProbeTrait;
use App\Service\Provider\ProviderErrorCode; use GitContributionGraph\Service\Provider\ProviderErrorCode;
use App\Service\Provider\ProviderInterface; use GitContributionGraph\Service\Provider\ProviderInterface;
use App\Service\Provider\ProviderStatusType; use GitContributionGraph\Service\Provider\ProviderStatusType;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,13 +2,13 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service\Provider; namespace GitContributionGraph\Tests\Unit\Service\Provider;
use App\Service\Provider\ProviderErrorCode; use GitContributionGraph\Service\Provider\ProviderErrorCode;
use App\Service\Provider\ProviderHealthChecker; use GitContributionGraph\Service\Provider\ProviderHealthChecker;
use App\Service\Provider\ProviderInterface; use GitContributionGraph\Service\Provider\ProviderInterface;
use App\Service\Provider\ProviderStatus; use GitContributionGraph\Service\Provider\ProviderStatus;
use App\Service\Provider\ProviderStatusType; use GitContributionGraph\Service\Provider\ProviderStatusType;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,11 +2,11 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service\Provider; namespace GitContributionGraph\Tests\Unit\Service\Provider;
use App\Service\Provider\ProviderErrorCode; use GitContributionGraph\Service\Provider\ProviderErrorCode;
use App\Service\Provider\ProviderStatus; use GitContributionGraph\Service\Provider\ProviderStatus;
use App\Service\Provider\ProviderStatusType; use GitContributionGraph\Service\Provider\ProviderStatusType;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Unit\Service\Renderer; namespace GitContributionGraph\Tests\Unit\Service\Renderer;
use App\Service\Renderer\SvgRenderer; use GitContributionGraph\Service\Renderer\SvgRenderer;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;