From b099ea3281b9c391515cbbea90e1c1d3c922e82a Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Wed, 22 Nov 2023 09:59:49 +0100 Subject: [PATCH 1/3] fix services --- src/Service/EnrichOrganizationService.php | 15 +++++++++++---- src/Service/GithubApiService.php | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Service/EnrichOrganizationService.php b/src/Service/EnrichOrganizationService.php index 4592cb44..b7fefc14 100644 --- a/src/Service/EnrichOrganizationService.php +++ b/src/Service/EnrichOrganizationService.php @@ -111,6 +111,10 @@ public function enrichOrganization(ObjectEntity $organization): ObjectEntity } $opencatalogiUrl = $organization->getValue('opencatalogiRepo'); + if ($opencatalogiUrl === null) { + return $organization; + } + $path = trim(\Safe\parse_url($opencatalogiUrl)['path'], '/'); // Call the search/code endpoint for publiccode files in this repository. @@ -144,9 +148,9 @@ public function enrichOrganization(ObjectEntity $organization): ObjectEntity * * @throws GuzzleException|Exception * - * @return ObjectEntity + * @return array */ - public function getOrganization(string $organizationId): ObjectEntity + public function getOrganization(string $organizationId): array { // Get the response. try { @@ -177,6 +181,8 @@ public function getOrganization(string $organizationId): ObjectEntity return $this->data; }//end if + return $this->data; + }//end getOrganization() @@ -197,12 +203,13 @@ public function enrichOrganizationHandler(?array $data=[], ?array $configuration // If there is an organization in the response. if ($organizationId !== null) { - $this->getOrganization(); + $this->getOrganization($organizationId); } // If there is no organization we get all the organizations and enrich it. if ($organizationId === null) { - $organizations = $this->entityManager->getRepository('App:ObjectEntity')->findAll(); + $organizationSchema = $this->resourceService->getSchema($this->configuration['organizationSchema'], 'open-catalogi/open-catalogi-bundle'); + $organizations = $this->entityManager->getRepository('App:ObjectEntity')->findBy(['entity' => $organizationSchema]); foreach ($organizations as $organization) { // Check if the name and github is not null. diff --git a/src/Service/GithubApiService.php b/src/Service/GithubApiService.php index 740a73b3..7412aaa3 100644 --- a/src/Service/GithubApiService.php +++ b/src/Service/GithubApiService.php @@ -176,6 +176,10 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr // Get the repository from the github api. $repositoryArray = $this->getRepository($repositoryUrl, $source); } + + if ($repositoryArray === null) { + return null; + } // Synchronize the github repository. $repositorySync = $this->syncService->synchronize($repositorySync, $repositoryArray); From 6287e572a40663bdb8552d75914150d85e52e9bb Mon Sep 17 00:00:00 2001 From: GitHub Actions <> Date: Wed, 22 Nov 2023 09:00:32 +0000 Subject: [PATCH 2/3] Update src from PHP Codesniffer --- src/Service/EnrichOrganizationService.php | 4 ++-- src/Service/GithubApiService.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Service/EnrichOrganizationService.php b/src/Service/EnrichOrganizationService.php index b7fefc14..5828bf48 100644 --- a/src/Service/EnrichOrganizationService.php +++ b/src/Service/EnrichOrganizationService.php @@ -115,7 +115,7 @@ public function enrichOrganization(ObjectEntity $organization): ObjectEntity return $organization; } - $path = trim(\Safe\parse_url($opencatalogiUrl)['path'], '/'); + $path = trim(\Safe\parse_url($opencatalogiUrl)['path'], '/'); // Call the search/code endpoint for publiccode files in this repository. $queryConfig['query'] = ['q' => "filename:opencatalogi extension:yaml extension:yml repo:{$path}"]; @@ -209,7 +209,7 @@ public function enrichOrganizationHandler(?array $data=[], ?array $configuration // If there is no organization we get all the organizations and enrich it. if ($organizationId === null) { $organizationSchema = $this->resourceService->getSchema($this->configuration['organizationSchema'], 'open-catalogi/open-catalogi-bundle'); - $organizations = $this->entityManager->getRepository('App:ObjectEntity')->findBy(['entity' => $organizationSchema]); + $organizations = $this->entityManager->getRepository('App:ObjectEntity')->findBy(['entity' => $organizationSchema]); foreach ($organizations as $organization) { // Check if the name and github is not null. diff --git a/src/Service/GithubApiService.php b/src/Service/GithubApiService.php index 7412aaa3..01870e83 100644 --- a/src/Service/GithubApiService.php +++ b/src/Service/GithubApiService.php @@ -176,7 +176,7 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr // Get the repository from the github api. $repositoryArray = $this->getRepository($repositoryUrl, $source); } - + if ($repositoryArray === null) { return null; } From 4c2976995e99b3eab9e994c4574c5dd468e283d9 Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Wed, 22 Nov 2023 10:08:05 +0100 Subject: [PATCH 3/3] fix actionHandler --- src/ActionHandler/GithubApiHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ActionHandler/GithubApiHandler.php b/src/ActionHandler/GithubApiHandler.php index 4fef0705..3b231b4c 100644 --- a/src/ActionHandler/GithubApiHandler.php +++ b/src/ActionHandler/GithubApiHandler.php @@ -139,7 +139,7 @@ public function getConfiguration(): array */ public function run(array $data, array $configuration): array { - return $this->service->findGithubRepositories(); + return $this->service->findGithubRepositories($data, $configuration); }//end run()