Skip to content

Commit

Permalink
feat: added repository:list command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Jul 15, 2024
1 parent 68ce4ab commit 632d2df
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
41 changes: 41 additions & 0 deletions app/Console/Commands/ListRepositories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Console\Commands;

use App\Models\Repository;
use Illuminate\Console\Command;

class ListRepositories extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'repository:list';

/**
* The console command description.
*
* @var string
*/
protected $description = 'List a table of all repositories in the database.';

/**
* Execute the console command.
*/
public function handle(): void
{
$this->table(
['Name', 'Delay (in days)', 'Repo Frozen', 'Serving Directory'],
Repository::all()->map(function (Repository $repository) {
return [
$repository->name,
$repository->delay,
$repository->freeze ? 'Yes' : 'No',
$repository->getStablePath(),
];
})
);
}
}
13 changes: 12 additions & 1 deletion tests/Feature/CommandLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use App\Jobs\SyncRepository;
use App\Models\Repository;
use Illuminate\Support\Facades\Queue;

use function Pest\Laravel\artisan;
use function Pest\Laravel\assertDatabaseHas;

Expand Down Expand Up @@ -31,3 +30,15 @@
assertDatabaseHas('repositories', $repository->toArray());
Queue::assertPushed(SyncRepository::class);
});

it('can list repositories', function () {
$repositories = Repository::factory()->create([
'name' => 'test',
'delay' => 1,
]);
artisan('repository:list')
->expectsTable(
['Name', 'Delay (in days)', 'Repo Frozen', 'Serving Directory'],
[['test', 1, 'No', 'snapshots/test/']],
);
});

0 comments on commit 632d2df

Please sign in to comment.