Skip to content

Commit

Permalink
Fixes on OC errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Mar 6, 2024
1 parent d531f00 commit d6de9a8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CommonGateway\CoreBundle\Service\GatewayResourceService;
use OpenCatalogi\OpenCatalogiBundle\Service\FindGithubRepositoryThroughOrganizationService;
use OpenCatalogi\OpenCatalogiBundle\Service\FindRepositoryThroughOrganizationService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -38,7 +39,7 @@ class FindGithubRepositoryThroughOrganizationCommand extends Command
* @param GatewayResourceService $resourceService The Gateway Resource Service
*/
public function __construct(
FindGithubRepositoryThroughOrganizationService $findGitService,
FindRepositoryThroughOrganizationService $findGitService,
GatewayResourceService $resourceService
) {
$this->findGitService = $findGitService;
Expand Down Expand Up @@ -76,12 +77,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$organizationId = $input->getOption('organizationId', false);

if ($organizationId === null) {
if (empty($this->findGitService->findGithubRepositoryThroughOrganizationHandler([], $configuration)) === true) {
if (empty($this->findGitService->findRepositoryThroughOrganizationHandler([], $configuration)) === true) {
return Command::FAILURE;
}
}

if (empty($this->findGitService->findGithubRepositoryThroughOrganizationHandler([], $configuration, $organizationId)) === true) {
if (empty($this->findGitService->findRepositoryThroughOrganizationHandler([], $configuration, $organizationId)) === true) {

Check warning on line 85 in src/Command/FindGithubRepositoryThroughOrganizationCommand.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 131 characters

Check warning on line 85 in src/Command/FindGithubRepositoryThroughOrganizationCommand.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 131 characters
return Command::FAILURE;
}

Expand Down
88 changes: 44 additions & 44 deletions src/Service/PubliccodeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use App\Service\SynchronizationService;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Exception\ClientException;
use phpDocumentor\Reflection\Types\This;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\YamlEncoder;

Expand Down Expand Up @@ -234,7 +234,7 @@ public function handleContacts(Source $source, ObjectEntity $component, array $p
$contacts = [];
foreach ($publiccode['maintenance']['contacts'] as $contact) {
// The name property is mandatory, so only set the contact if this is given.
if (key_exists('name', $contact) === true) {
if (is_array($contact) && key_exists('name', $contact) === true) {
// $contactSchema = $this->resourceService->getSchema($this->configuration['contactSchema'], 'open-catalogi/open-catalogi-bundle');
$contactSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.contact.schema.json', 'open-catalogi/open-catalogi-bundle');
if ($contactSchema instanceof Entity === false) {
Expand Down Expand Up @@ -705,59 +705,59 @@ public function switchLogo(array $componentArray, Source $source, string $reposi
switch ($domain) {
// Check if the logo is as option 1, a logo from https://avatars.githubusercontent.com.
// Check if the domain is https://avatars.githubusercontent.com. If so we don't have to do anything and return the publiccodeArray logo.
case 'avatars.githubusercontent.com':
// TODO: Validate the avatar url. Call the source with path and check is the status code is 200. The function handleRawLogo can be used for this.
$this->pluginLogger->info('The logo from the publiccode file is from https://avatars.githubusercontent.com. Do nothing and return the url.');
case 'avatars.githubusercontent.com':
// TODO: Validate the avatar url. Call the source with path and check is the status code is 200. The function handleRawLogo can be used for this.
$this->pluginLogger->info('The logo from the publiccode file is from https://avatars.githubusercontent.com. Do nothing and return the url.');

// Return the given avatar logo url.
return $componentArray['logo'];
// Return the given avatar logo url.
return $componentArray['logo'];
// Check if the logo is as option 2, a logo from https://raw.githubusercontent.com.
// Check if the domain is https://raw.githubusercontent.com. If so, the user content source must be called with the path of the given logo URL as endpoint.
case 'raw.githubusercontent.com':
// Get the usercontent source.
$usercontentSource = $this->resourceService->getSource($this->configuration['usercontentSource'], 'open-catalogi/open-catalogi-bundle');
// Check if the given source is not an instance of a Source return null and create a log.
if ($usercontentSource instanceof Source === false) {
$this->pluginLogger->error('The source with reference: '.$usercontentSource->getReference().' cannot be found.', ['open-catalogi/open-catalogi-bundle']);

// Cannot validate the raw usercontent url if the source cannot be found.
break;
}
case 'raw.githubusercontent.com':
// Get the usercontent source.
$usercontentSource = $this->resourceService->getSource($this->configuration['usercontentSource'], 'open-catalogi/open-catalogi-bundle');
// Check if the given source is not an instance of a Source return null and create a log.
if ($usercontentSource instanceof Source === false) {
$this->pluginLogger->error('The source with reference: '.$usercontentSource->getReference().' cannot be found.', ['open-catalogi/open-catalogi-bundle']);

// Cannot validate the raw usercontent url if the source cannot be found.
break;
}

// Handle the logo if the logo is as option 2, the raw github link for the logo.
return $this->handleRawLogo($componentArray, $usercontentSource, 'raw');
// Handle the logo if the logo is as option 2, the raw github link for the logo.
return $this->handleRawLogo($componentArray, $usercontentSource, 'raw');
// Check if the domain is https://github.com, the key path exist in the parsed logo url and if the parsed logo url path is not null.
// If so we need to get an url that the frontend can use.
case 'github.com':
if (key_exists('path', $parsedLogo) === true
&& $parsedLogo['path'] !== null
) {
// Handle the logo if the logo is as option 3, the file fom github where the image can be found.
return $this->handleLogoFromGithub($componentArray, $source, $parsedLogo, $repositoryName);
}
break;
case 'github.com':
if (key_exists('path', $parsedLogo) === true
&& $parsedLogo['path'] !== null
) {
// Handle the logo if the logo is as option 3, the file fom github where the image can be found.
return $this->handleLogoFromGithub($componentArray, $source, $parsedLogo, $repositoryName);
}
break;
// Check if the logo is as option 5, a logo from https://www.gravatar.com.
// Check if the domain is https://www.gravatar.com. If so we don't have to do anything and return the publiccodeArray logo.
case 'www.gravatar.com':
// TODO: Validate the gravatar url. Call the source with path and check is the status code is 200. The function handleRawLogo can be used for this.
$this->pluginLogger->info('The logo from the publiccode file is from https://www.gravatar.com. Do nothing and return the url.');
case 'www.gravatar.com':
// TODO: Validate the gravatar url. Call the source with path and check is the status code is 200. The function handleRawLogo can be used for this.
$this->pluginLogger->info('The logo from the publiccode file is from https://www.gravatar.com. Do nothing and return the url.');

// Return the given gravatar logo url.
return $componentArray['logo'];
// Return the given gravatar logo url.
return $componentArray['logo'];
// Check if the domain is https://gitlab.com, the key path exist in the parsed logo url and if the parsed logo url path is not null.
// If so we need to get an url that the frontend can use.
case 'gitlab.com':
if (key_exists('path', $parsedLogo) === true
&& $parsedLogo['path'] !== null
) {
// For option 6 and 7:
// Handle the logo if the logo is as option 6 or 7, the file fom gitlab where the image can be found.
return $this->handleLogoFromGitlab($componentArray, $source, $parsedLogo, $repositoryName, $repositoryId);
}
break;
default:
$this->pluginLogger->warning('The domain: '.$domain.' is not valid. The logo url can be from https://avatars.githubusercontent.com, https://raw.githubusercontent.com and https://github.com. It can also be a relative path from the root of the repository from github can be given.', ['open-catalogi/open-catalogi-bundle']);
break;
case 'gitlab.com':
if (key_exists('path', $parsedLogo) === true
&& $parsedLogo['path'] !== null
) {
// For option 6 and 7:
// Handle the logo if the logo is as option 6 or 7, the file fom gitlab where the image can be found.
return $this->handleLogoFromGitlab($componentArray, $source, $parsedLogo, $repositoryName, $repositoryId);
}
break;
default:
$this->pluginLogger->warning('The domain: '.$domain.' is not valid. The logo url can be from https://avatars.githubusercontent.com, https://raw.githubusercontent.com and https://github.com. It can also be a relative path from the root of the repository from github can be given.', ['open-catalogi/open-catalogi-bundle']);
break;
}//end switch

return null;
Expand Down

0 comments on commit d6de9a8

Please sign in to comment.