Skip to content

Commit

Permalink
Merge pull request #141 from OpenCatalogi/fix/github-events-edpoint
Browse files Browse the repository at this point in the history
Bugfixes on organisations from the github event endpoint.
  • Loading branch information
rjzondervan authored Nov 7, 2023
2 parents 4d9b3d7 + 362c43f commit 4150b20
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
8 changes: 4 additions & 4 deletions 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.1",
"version": "0.1.2",
"type": "object",
"description": "extension of the publiccode standard ",
"properties": {
Expand All @@ -22,23 +22,23 @@
"uniqueItems": true,
"description": "A list of components supported by this organisation",
"items": {
"$ref": "https://opencatalogi.nl/oc.component.schema.json"
"$ref": "https://opencatalogi.nl/oc.repository.schema.json"
}
},
"owns": {
"type": "array",
"uniqueItems": true,
"description": "A list of components owned by this organisation",
"items": {
"$ref": "https://opencatalogi.nl/oc.component.schema.json"
"$ref": "https://opencatalogi.nl/oc.repository.schema.json"
}
},
"uses": {
"type": "array",
"uniqueItems": true,
"description": "A list of components used by this organisation",
"items": {
"$ref": "https://opencatalogi.nl/oc.component.schema.json"
"$ref": "https://opencatalogi.nl/oc.repository.schema.json"
},
"inversedBy": "usedBy"
},
Expand Down
2 changes: 2 additions & 0 deletions src/Service/EnrichPubliccodeFromGithubUrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public function enrichRepositoryWithPubliccode(ObjectEntity $repository, string
// Get the publiccode through the raw.githubusercontent source
$publiccode = $this->getPubliccodeFromRawUserContent($publiccodeUrl);

$this->pluginLogger->notice('Got publiccode from GitHub', $publiccode);

if ($publiccode !== null) {
$repository = $this->githubService->mapPubliccode($repository, $publiccode, $this->configuration, $publiccodeUrl);
}
Expand Down
40 changes: 28 additions & 12 deletions src/Service/FindGithubRepositoryThroughOrganizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public function getOrganisationRepo(string $url, ObjectEntity $organization, str
$component && $component->setValue('usedBy', [$organization]);
}

$this->entityManager->persist($repositoryObject);

return $repositoryObject;

}//end getOrganisationRepo()
Expand All @@ -270,7 +272,7 @@ public function getOrganisationRepo(string $url, ObjectEntity $organization, str
*
* @return void
*/
public function getOrganizationCatalogi(ObjectEntity $organization): void
public function getOrganizationCatalogi(ObjectEntity $organization): ObjectEntity
{
// Do we have a source?
// usercontentSource
Expand All @@ -280,24 +282,24 @@ public function getOrganizationCatalogi(ObjectEntity $organization): void
|| $usercontentSource === null
|| $this->githubApiService->checkGithubAuth($source) === false
) {
return;
return $organization;
}//end if

if (($githubRepo = $this->getGithubRepoFromOrganization($organization->getValue('name'), $source)) === null) {
return;
return $organization;
}//end if

$this->pluginLogger->debug('Github repo found and fetched for '.$organization->getName());

if (($openCatalogi = $this->getOpenCatalogiFromGithubRepo($organization->getValue('name'), $usercontentSource)) === null) {
return;
return $organization;
}//end if

$this->pluginLogger->debug('OpenCatalogi.yml or OpenCatalogi.yaml found and fetched for '.$organization->getName());

$mapping = $this->resourceService->getMapping($this->configuration['openCatalogiMapping'], 'open-catalogi/open-catalogi-bundle');
if ($mapping === null) {
return;
return $organization;
}

$organizationArray = $this->mappingService->mapping($mapping, $openCatalogi);
Expand All @@ -324,11 +326,21 @@ public function getOrganizationCatalogi(ObjectEntity $organization): void
if (key_exists('softwareUsed', $openCatalogi) === true) {
foreach ($openCatalogi['softwareUsed'] as $use) {
// Get organisation repos and set the property.
$uses[] = $this->getOrganisationRepo($use, $organization, 'use', $source);
$uses[] = $this->getOrganisationRepo($use, $organization, 'use', $source)->getId()->toString();
}
}

$organization->setValue('uses', $uses);
$organization->hydrate(['uses' => $uses]);

$owns = [];
if (key_exists('softwareOwned', $openCatalogi) === true) {
foreach ($openCatalogi['softwareOwned'] as $own) {
// Get organisation repos and set the property.
$owns[] = $this->getOrganisationRepo($own, $organization, 'own', $source)->getId()->toString();
}
}

$organization->hydrate(['owns' => $owns]);

$supports = [];
if (key_exists('softwareSupported', $openCatalogi) === true) {
Expand All @@ -338,25 +350,26 @@ public function getOrganizationCatalogi(ObjectEntity $organization): void
}

// Get organisation component and set the property.
$supports[] = $supportOrganisation = $this->getOrganisationRepo($support['software'], $organization, 'supports', $source);
$supportOrganisation = $this->getOrganisationRepo($support['software'], $organization, 'supports', $source);
$supports[] = $supportOrganisation->getId()->toString();

if (key_exists('contact', $support) === false) {
continue;
}

if (key_exists('email', $support['contact']) === true) {
$supportOrganisation->setValue('email', $support['contact']['email']);
$supportOrganisation->hydrate('email', $support['contact']['email']);
}

if (key_exists('phone', $support['contact']) === true) {
$supportOrganisation->setValue('email', $support['contact']['phone']);
$supportOrganisation->hydrate(['email' => $support['contact']['phone']]);
}

$this->entityManager->persist($supportOrganisation);
}//end foreach
}//end if

$organization->setValue('supports', $supports);
$organization->hydrate(['supports' => $supports]);

$members = [];
if (isset($openCatalogi['members']) === true) {
Expand Down Expand Up @@ -387,6 +400,8 @@ public function getOrganizationCatalogi(ObjectEntity $organization): void

$this->pluginLogger->debug($organization->getName().' succesfully updated with fetched openCatalogi info');

return $organization;

}//end getOrganizationCatalogi()


Expand Down Expand Up @@ -468,12 +483,13 @@ public function createOrganization(string $organizationName, Source $source): ?O
$mapping = $this->resourceService->getMapping($this->configuration['organizationMapping'], 'open-catalogi/open-catalogi-bundle');

$synchronization = $this->syncService->findSyncBySource($source, $organizationSchema, $organizationArray['id']);

$synchronization->setMapping($mapping);
$synchronization = $this->syncService->synchronize($synchronization, $organizationArray);

$organizationObject = $synchronization->getObject();

$this->getOrganizationCatalogi($organizationObject);
$organizationObject = $this->getOrganizationCatalogi($organizationObject);

return $organizationObject;

Expand Down
12 changes: 10 additions & 2 deletions src/Service/GithubEventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function importOrganizationThroughRepo(Source $source, array $repositoryA
$this->pluginLogger->debug('Checking organization '.$ownerName.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']);

$orgSync->setMapping($orgMapping);

$orgSync = $this->syncService->synchronize($orgSync, $repositoryArray['owner']);
$this->pluginLogger->debug('Organization synchronization created with id: '.$orgSync->getId()->toString().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']);

Expand Down Expand Up @@ -243,12 +244,14 @@ public function createRepository(Source $source, string $name, string $repositor

$repository = $synchronization->getObject();

$repository = $this->importComponentsThroughRepo($repository, $repositoryUrl);
$repository = $this->importComponentsThroughRepo($repository, $repositoryUrl);

$organization = $this->importOrganizationThroughRepo($source, $repositoryArray, $repositoryUrl);

$repository->hydrate(['organisation' => $organization]);

$this->entityManager->persist($repository);
$this->entityManager->flush();

return $organization;

Expand Down Expand Up @@ -298,9 +301,14 @@ public function githubEvent(array $githubEvent): ?array

$organizationObject = $this->organizationService->createOrganization($organizationName, $source);

$this->entityManager->persist($organizationObject);
$this->entityManager->flush();

$organizationObject = $this->entityManager->find(get_class($organizationObject), $organizationObject->getId());

$organizatioResponse['organization'] = $organizationObject->toArray();

$this->data['response'] = new Response(json_encode($organizatioResponse), 200);
$this->data['response'] = new Response(json_encode($organizatioResponse), 200, ['Content-Type' => 'application/json']);

return $this->data;
}
Expand Down

0 comments on commit 4150b20

Please sign in to comment.