Skip to content

Commit

Permalink
Merge pull request #170 from OpenCatalogi/feature/OP-149/github-api-s…
Browse files Browse the repository at this point in the history
…earch

Fix services
  • Loading branch information
smisidjan authored Nov 22, 2023
2 parents c7cccfc + 4c29769 commit cbafa83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ActionHandler/GithubApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
17 changes: 12 additions & 5 deletions src/Service/EnrichOrganizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public function enrichOrganization(ObjectEntity $organization): ObjectEntity
}

$opencatalogiUrl = $organization->getValue('opencatalogiRepo');
$path = trim(\Safe\parse_url($opencatalogiUrl)['path'], '/');
if ($opencatalogiUrl === null) {
return $organization;
}

$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}"];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -177,6 +181,8 @@ public function getOrganization(string $organizationId): ObjectEntity
return $this->data;
}//end if

return $this->data;

}//end getOrganization()


Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/Service/GithubApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr
$repositoryArray = $this->getRepository($repositoryUrl, $source);
}

if ($repositoryArray === null) {
return null;
}

// Synchronize the github repository.
$repositorySync = $this->syncService->synchronize($repositorySync, $repositoryArray);
$this->entityManager->persist($repositorySync);
Expand Down

0 comments on commit cbafa83

Please sign in to comment.