Skip to content

Commit

Permalink
Merge pull request #164 from OpenCatalogi/feature/OP-146/opencatalogi
Browse files Browse the repository at this point in the history
opencatalogi fix
  • Loading branch information
smisidjan authored Nov 20, 2023
2 parents 7211afd + 5ef71fc commit dbf5279
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 67 deletions.
6 changes: 5 additions & 1 deletion Installation/Schema/Organisation.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "Organisation",
"$id": "https://opencatalogi.nl/oc.organisation.schema.json",
"$schema": "https://docs.commongateway.nl/schemas/Entity.schema.json",
"version": "0.1.5",
"version": "0.1.6",
"type": "object",
"description": "extension of the publiccode standard ",
"properties": {
Expand Down Expand Up @@ -85,6 +85,10 @@
},
"catalogus": {
"$ref": "https://opencatalogi.nl/oc.catalogus.schema.json"
},
"opencatalogiRepo": {
"type": "string",
"description": "The url of the opencatalogi file."
}
}
}
33 changes: 20 additions & 13 deletions src/Service/EnrichOrganizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,30 @@ public function enrichOrganization(ObjectEntity $organization): ObjectEntity
$organizationArray = $this->githubApiService->getOrganization(trim($githubPath, '/'), $source);
}

if (isset($organizationArray) === false
|| isset($organizationArray) === true
&& $organizationArray === null
) {
return $organization;
if ($organization->getValue('type') === 'User') {
// Get the organization from the github api.
$organizationArray = $this->githubApiService->getUser(trim($githubPath, '/'), $source);
}

// If we get an empty string we set the description from the github api.
if ($organization->getValue('description') !== false
|| $organization->getValue('description') !== null
) {
$organization->hydrate(['description' => $organizationArray['description']]);
$this->entityManager->persist($organization);
$this->entityManager->flush();
$opencatalogiUrl = $organization->getValue('opencatalogiRepo');
$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}"];
$opencatalogiFiles = $this->githubApiService->getFilesFromRepo($source, $queryConfig);

$opencatalogiNames = [
'opencatalogi.yaml',
'opencatalogi.yml',
];

foreach ($opencatalogiFiles as $item) {
if (in_array($item['name'], $opencatalogiNames) === true) {
$organization = $this->githubApiService->handleOpencatalogiFile($organizationArray, $source, $item);
}
}

$this->pluginLogger->debug($organization->getName().' succesfully updated the organization with a description.');
$this->pluginLogger->debug($organization->getName().' succesfully updated the organization with the opencatalogi file.');

return $organization;

Expand Down
Loading

0 comments on commit dbf5279

Please sign in to comment.