Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Controller/OAuth/IntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ public function repos(#[Vars] OAuthIntegration $oauth): Response
$repos = [];
}

$pkgRepo = $this->registry->getRepository(Package::class);
$excludedRepos = array_values(
array_map(
function(Package $r) {
if( 1 === preg_match("/^https?:\/\/[a-z0-9-]+?\.[a-z]{2,}\/([a-z0-9_-]+\/[a-z0-9_-]+)\.git/i", $r->getRepository(), $matches)) {
return $matches[1];
}

return $r->getPackageName();
},
$pkgRepo->findAll()
)
);

$oauth->setExcludedRepos(array_merge($excludedRepos, $oauth->getExcludedRepos() ?? []));

return new JsonResponse($oauth->filteredRepos($repos, true));
}

Expand Down
4 changes: 3 additions & 1 deletion src/Entity/OAuthIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function setInstallationId(null|string|int $id = null): self
return $this->setSerialized('installation_id', $id ? (int) $id : null);
}

public function filteredRepos(array $repos, bool $short = false): array
public function filteredRepos(array $repos, bool $short = false ): array
{
$listOf = array_column($repos, 'name');
$filtered = PacketonUtils::matchGlobAll($listOf, $this->getGlobFilter(), $this->getExcludedRepos());
Expand All @@ -268,6 +268,8 @@ public function filteredRepos(array $repos, bool $short = false): array
if ($short) {
$repos = array_map(fn($r) => ['id' => $r['ext_ref'], 'text' => $r['name']], $repos);
}

usort($repos, fn($a, $b) => $a['text'] <=> $b['text']);
return $repos;
}

Expand Down
Loading