diff --git a/src/Controller/RepoController.php b/src/Controller/RepoController.php index 4b4ba596..1eee1319 100644 --- a/src/Controller/RepoController.php +++ b/src/Controller/RepoController.php @@ -140,6 +140,24 @@ public function downloads(Request $request, Organization $organization): JsonRes return new JsonResponse(['status' => 'success'], JsonResponse::HTTP_CREATED); } + /** + * @Route("/p2/{package}~dev.json", + * host="{organization}{sep1}repo{sep2}{domain}", + * name="repo_package_provider_v2_dev", + * methods={"GET"}, + * defaults={"domain":"%domain%","sep1"="%organization_separator%","sep2"="%domain_separator%"}, + * requirements={"domain"="%domain%","package"="%package_name_pattern%","sep1"="%organization_separator%","sep2"="%domain_separator%"}) + * @Cache(public=false) + */ + public function providerV2Dev(Request $request, Organization $organization, string $package): JsonResponse + { + if (($package = preg_replace('/~dev$/', '', $package)) === null) { + throw new NotFoundHttpException(); + } + + return $this->providerV2($request, $organization, $package); + } + /** * @Route("/p2/{package}.json", * host="{organization}{sep1}repo{sep2}{domain}", @@ -160,7 +178,7 @@ public function providerV2(Request $request, Organization $organization, string throw new NotFoundHttpException(); } - $response = (new JsonResponse($providerData)) + $response = (new JsonResponse(['packages' => $providerData])) ->setLastModified($lastModified) ->setPrivate(); diff --git a/tests/Functional/Controller/RepoControllerTest.php b/tests/Functional/Controller/RepoControllerTest.php index 85ba6445..cb7a5225 100644 --- a/tests/Functional/Controller/RepoControllerTest.php +++ b/tests/Functional/Controller/RepoControllerTest.php @@ -207,14 +207,16 @@ public function testProviderV2Action(): void self::assertMatchesPattern(' { - "buddy-works/repman": { - "1.2.3": { - "version": "1.2.3", - "version_normalized": "1.2.3.0", - "dist": { - "type": "zip", - "url": "/path/to/reference.zip", - "reference": "ac7dcaf888af2324cd14200769362129c8dd8550" + "packages": { + "buddy-works/repman": { + "1.2.3": { + "version": "1.2.3", + "version_normalized": "1.2.3.0", + "dist": { + "type": "zip", + "url": "/path/to/reference.zip", + "reference": "ac7dcaf888af2324cd14200769362129c8dd8550" + } } } } @@ -254,4 +256,36 @@ public function testProviderV2ForMissingPackage(): void self::assertTrue($this->client->getResponse()->isNotFound()); } + + public function testProviderV2DevAction(): void + { + $adminId = $this->createAndLoginAdmin('test@buddy.works', 'secret'); + $this->fixtures->createToken($this->fixtures->createOrganization('buddy', $adminId), 'secret-org-token'); + + $this->client->request('GET', '/p2/buddy-works/repman~dev.json', [], [], [ + 'HTTP_HOST' => 'buddy.repo.repman.wip', + 'PHP_AUTH_USER' => 'token', + 'PHP_AUTH_PW' => 'secret-org-token', + ]); + + self::assertTrue($this->client->getResponse()->isOk()); + + self::assertMatchesPattern(' + { + "packages": { + "buddy-works/repman": { + "1.2.3": { + "version": "1.2.3", + "version_normalized": "1.2.3.0", + "dist": { + "type": "zip", + "url": "/path/to/reference.zip", + "reference": "ac7dcaf888af2324cd14200769362129c8dd8550" + } + } + } + } + } + ', $this->client->getResponse()->getContent()); + } }