Manage redirects, missing URLs, repositories and settings through the API

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 19:51:00 +02:00
parent 4c65604f04
commit 8d0f2e3639
20 changed files with 1581 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\V1\RepositoryRequest;
use App\Http\Resources\RepositoryResource;
use App\Jobs\SyncRepository;
use App\Models\Repository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
/**
* The collective's git repositories. Only which repository, whose project and
* whether to show it are written here; everything else is what the provider
* last reported.
*/
class RepositoryController extends Controller
{
/**
* Filters: provider, project_id, show_publicly, failing, search (full name).
*/
public function index(Request $request): AnonymousResourceCollection
{
$this->authorize('viewAny', Repository::class);
$repositories = Repository::query()
->when($request->filled('provider'), fn ($q) => $q->where('provider', $request->string('provider')))
->when($request->filled('project_id'), fn ($q) => $q->where('project_id', $request->integer('project_id')))
->when($request->has('show_publicly'), fn ($q) => $q->where('show_publicly', $request->boolean('show_publicly')))
->when($request->boolean('failing'), fn ($q) => $q->failing())
->when($request->filled('search'), fn ($q) => $q->where('full_name', 'like', '%'.$request->string('search').'%'))
->orderBy('full_name')
->paginate(perPage: min($request->integer('per_page', 25), 100))
->withQueryString();
return RepositoryResource::collection($repositories);
}
public function store(RepositoryRequest $request): JsonResponse
{
$this->authorize('create', Repository::class);
return RepositoryResource::make(Repository::create($request->validated())->refresh())->response()->setStatusCode(201);
}
public function show(Repository $repository): RepositoryResource
{
$this->authorize('view', $repository);
return RepositoryResource::make($repository);
}
public function update(RepositoryRequest $request, Repository $repository): RepositoryResource
{
$this->authorize('update', $repository);
$repository->update($request->validated());
return RepositoryResource::make($repository);
}
public function destroy(Repository $repository): JsonResponse
{
$this->authorize('delete', $repository);
$repository->delete();
return response()->json(status: 204);
}
/**
* Ask the provider again, on the queue: a sync spends a rate limit the
* whole application shares, and a caller should not wait on it.
*/
public function sync(Repository $repository): JsonResponse
{
$this->authorize('sync', $repository);
SyncRepository::dispatch($repository);
return RepositoryResource::make($repository)->response()->setStatusCode(202);
}
}