Skip to content

Commit

Permalink
Update src from PHP Codesniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Nov 20, 2023
1 parent 876170b commit 5ef71fc
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions src/Service/GithubApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr
return $this->data;
}//end if


$source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubAPI.source.json', 'open-catalogi/open-catalogi-bundle');
// Do we have the api key set of the source.
if ($this->checkGithubAuth($source) === false
Expand Down Expand Up @@ -191,7 +190,7 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr
$path = trim(\Safe\parse_url($repositoryUrl)['path'], '/');
// Call the search/code endpoint for publiccode files in this repository.
$queryConfig['query'] = ['q' => "filename:publiccode filename:opencatalogi extension:yaml extension:yml repo:{$path}"];
$dataArray = $this->getFilesFromRepo($source, $queryConfig);
$dataArray = $this->getFilesFromRepo($source, $queryConfig);
if ($dataArray !== null) {
// Import the publiccode/opencatalogi files and connect it to the repository.
$repository = $this->importRepoFiles($dataArray, $source, $repository);
Expand Down Expand Up @@ -302,7 +301,7 @@ public function enrichWithComponent(ObjectEntity $repository, array $repositoryA

$data = [
'name' => $repository->getValue('name'),
'url' => $repository
'url' => $repository,
];

$componentSync = $this->syncService->findSyncBySource($source, $componentSchema, $repositoryArray['html_url']);
Expand Down Expand Up @@ -575,12 +574,11 @@ public function handleOpencatalogiFile(array $organizationArray, Source $source,
$organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $organizationArray['html_url']);
// Check the sha of the sync with the url reference in the array.
if ($this->syncService->doesShaMatch($organizationSync, $urlReference) === true) {

return null;
}

$opencatalogi['github'] = $organizationArray['html_url'];
$opencatalogi['type'] = $organizationArray['type'];
$opencatalogi['github'] = $organizationArray['html_url'];
$opencatalogi['type'] = $organizationArray['type'];
$opencatalogi['opencatalogiRepo'] = $organizationSync->getObject()->getValue('opencatalogiRepo');

$organizationSync->setMapping($opencatalogiMapping);
Expand Down Expand Up @@ -687,7 +685,7 @@ public function handlePubliccodeFile(array $publiccodeArray, Source $source, Obj
// The urlReference and the git_url changes when the file changes.
$sourceId = "https://raw.githubusercontent.com/{$publiccodeArray['repository']['full_name']}/{$publiccodeArray['path']}";

$this->pluginLogger->info('Map the publiccode file with url: '.$publiccodeUrl .' and source id: '.$sourceId);
$this->pluginLogger->info('Map the publiccode file with url: '.$publiccodeUrl.' and source id: '.$sourceId);

// Get the file from the usercontent or github api source
$publiccode = $this->getFileFromRawUserContent($publiccodeUrl, $publiccodeArray['git_url']);
Expand Down Expand Up @@ -770,23 +768,20 @@ public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $
// Check if the item name is the same as the openCatalogiNames array.
// If so go the the function for the opencatalogi file.
if (in_array($item['name'], $opencatalogiNames) === true) {
$organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle');
$organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle');
$this->pluginLogger->info('The item is a opencatalogi file.');

// // Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent.
// $opencatalogiUrlQuery = \Safe\parse_url($item['url'])['query'];
// // Remove the ref= part of the query.
// $urlReference = explode('ref=', $opencatalogiUrlQuery)[1];


// Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent.
// $opencatalogiUrlQuery = \Safe\parse_url($item['url'])['query'];
// Remove the ref= part of the query.
// $urlReference = explode('ref=', $opencatalogiUrlQuery)[1];
$organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $item['repository']['owner']['html_url']);
// $this->syncService->doesShaMatch($organizationSync, $urlReference);

$data = [
'name' => $item['repository']['full_name'],
'type' => $item['repository']['owner']['type'],
'github' => $item['repository']['owner']['html_url'],
'opencatalogiRepo' => $item['repository']['html_url']
// $this->syncService->doesShaMatch($organizationSync, $urlReference);
$data = [
'name' => $item['repository']['full_name'],
'type' => $item['repository']['owner']['type'],
'github' => $item['repository']['owner']['html_url'],
'opencatalogiRepo' => $item['repository']['html_url'],
];
$organizationSync = $this->syncService->synchronize($organizationSync, $data);
$this->entityManager->persist($organizationSync->getObject());
Expand All @@ -796,16 +791,15 @@ public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $
$repository->hydrate(['organisation' => $organizationSync->getObject()]);
$this->entityManager->persist($repository);
$this->entityManager->flush();

}
}//end if

// Check if the item name is the same as the publiccodeNames array.
// If so go the the function for the publiccode file.
if (in_array($item['name'], $publiccodeNames) === true) {
$this->pluginLogger->info('The item is a publiccode file.');
$repository = $this->handlePubliccodeFile($item, $source, $repository);
}
}
}//end foreach

return $repository;

Expand All @@ -819,7 +813,7 @@ public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $
*
* @return array|null
*/
public function getFileFromGithubApi(string $gitUrl, ?string $query = null): ?array
public function getFileFromGithubApi(string $gitUrl, ?string $query=null): ?array
{
$source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubAPI.source.json', 'open-catalogi/open-catalogi-bundle');
if ($source === null) {
Expand Down Expand Up @@ -861,13 +855,13 @@ public function getFileFromGithubApi(string $gitUrl, ?string $query = null): ?ar
/**
* This function gets the publiccode/opencatalogi file from the github user content.
*
* @param string $repositoryUrl The url of the repository
* @param string $repositoryUrl The url of the repository
* @param string|null $gitUrl The git url of the repository
*
* @return array|null
* @throws GuzzleException
*/
public function getFileFromRawUserContent(string $repositoryUrl, ?string $gitUrl = null): ?array
public function getFileFromRawUserContent(string $repositoryUrl, ?string $gitUrl=null): ?array
{
$source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubusercontent.source.json', 'open-catalogi/open-catalogi-bundle');
if ($source === null) {
Expand All @@ -894,6 +888,7 @@ public function getFileFromRawUserContent(string $repositoryUrl, ?string $gitUrl
}

return null;

}//end getFileFromRawUserContent()


Expand Down Expand Up @@ -941,8 +936,8 @@ public function getRepository(string $repositoryUrl, Source $source): ?array
/**
* Get the publiccode/opencatalogi files of the given repository
*
* @param Source $source The source to sync from.
* @param array $queryConfig The query config of the call.
* @param Source $source The source to sync from.
* @param array $queryConfig The query config of the call.
*
* @return array|null The publiccode/opencatalogi files as array.
*/
Expand Down Expand Up @@ -1072,6 +1067,7 @@ public function getOrganizationRepos(string $name, Source $source): ?array

}//end getOrganizationRepos()


/**
* Get a organization with type Organization from the github api.
*
Expand Down Expand Up @@ -1104,8 +1100,7 @@ public function getUser(string $name, Source $source): ?array

return $organization;

}//end getOrganization()

}//end getUser()


/**
Expand Down

0 comments on commit 5ef71fc

Please sign in to comment.