-
Notifications
You must be signed in to change notification settings - Fork 0
osslifecycle page #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bidi47
wants to merge
6
commits into
develop
Choose a base branch
from
issue-12
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env php | ||
| <?php | ||
|
|
||
| /** | ||
| * Rebuilds the Dotkernel packages listing from the GitHub organisation. | ||
| * | ||
| * Intended to run from cron, e.g. daily: | ||
| * 0 4 * * * cd /path/to/dotkernel.com && /usr/bin/php bin/generate-packages >> log/generate-packages.log 2>&1 | ||
| * | ||
| * Exits non-zero without touching the data file when the run cannot be trusted, so the | ||
| * previously generated listing keeps serving. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Light\App\Service\PackageGenerator; | ||
|
|
||
| chdir(__DIR__ . '/../'); | ||
|
|
||
| require 'vendor/autoload.php'; | ||
|
|
||
| $container = require 'config/container.php'; | ||
| $packageGenerator = $container->get(PackageGenerator::class); | ||
|
|
||
| try { | ||
| $report = $packageGenerator->write(); | ||
| } catch (Throwable $exception) { | ||
| fwrite(STDERR, sprintf( | ||
| '[%s] generate-packages failed: %s%s', | ||
| date('c'), | ||
| $exception->getMessage(), | ||
| PHP_EOL | ||
| )); | ||
| exit(1); | ||
| } | ||
|
|
||
| printf( | ||
| '[%s] Done. %d package%s written to %s%s', | ||
| date('c'), | ||
| $report['written'], | ||
| $report['written'] === 1 ? '' : 's', | ||
| $packageGenerator->getDataFile(), | ||
| PHP_EOL | ||
| ); | ||
|
|
||
| if ($report['skipped'] !== []) { | ||
| printf('Skipped by ignoreRepos: %s%s', implode(', ', $report['skipped']), PHP_EOL); | ||
| } | ||
|
|
||
| if ($report['ignoredMisses'] !== []) { | ||
| printf( | ||
| 'WARNING: ignoreRepos entries matched nothing (renamed or deleted?): %s%s', | ||
| implode(', ', $report['ignoredMisses']), | ||
| PHP_EOL | ||
| ); | ||
| } | ||
|
|
||
| foreach ($report['warnings'] as $warning) { | ||
| printf('WARNING: %s%s', $warning, PHP_EOL); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Dotkernel packages listing. | ||
| * | ||
| * Consumed by `bin/generate-packages`, which queries the GitHub organisation and writes the | ||
| * result to `dataFile`. Credentials are intentionally NOT stored here - the GitHub token lives | ||
| * in `config/autoload/local.php` under the `github` key, which is ignored by git. | ||
| * | ||
| * `local.php` is merged after every `*.global.php`, so any value below can be overridden locally. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| return [ | ||
| 'packages' => [ | ||
| /** | ||
| * ignored repositories | ||
| * matched on the bare repository name (case-insensitive) | ||
| */ | ||
| 'ignoreRepos' => [ | ||
| '.github', | ||
| 'admin', | ||
| 'admin-documentation', | ||
| 'apidemia.com', | ||
| 'api', | ||
| 'api-documentation', | ||
| 'app-packages', | ||
| 'api-tools-migration', | ||
| 'core', | ||
| 'development', | ||
| 'documentation', | ||
| 'documentation-theme', | ||
| 'dotboost', | ||
| 'dotkernel', | ||
| 'dotkernel.com', | ||
| 'dotkernel.github.io', | ||
| 'dotkernel.org', | ||
| 'dotkernel-v1', | ||
| 'dot-opensearch', | ||
| 'dot-privy', | ||
| 'dot-queue', | ||
| 'dot-sso-entra', | ||
| 'frontend', | ||
| 'frontend-documentation', | ||
| 'fullview', | ||
| 'headless-documentation', | ||
| 'light', | ||
| 'light-documentation', | ||
| 'mezzio-hal', | ||
| 'ng-admin', | ||
| 'ngx-admin', | ||
| 'php-llm-examples', | ||
| 'pingu', | ||
| 'plugin-mail-transporter', | ||
| 'pong', | ||
| 'presentation', | ||
| 'queue', | ||
| 'queue-documentation', | ||
| 'template', | ||
| 'template-expressive', | ||
| 'tutorial-101', | ||
| 'vue', | ||
| 'workflow-automatic-releases', | ||
| 'workflow-continuous-integration', | ||
| 'workshops', | ||
| 'ws-entities-collections', | ||
| 'zend', | ||
| 'zend-expressive-hal', | ||
| 'zf1', | ||
| ], | ||
| 'dataFile' => __DIR__ . '/../../public/packages.json', | ||
| 'includeArchived' => true, | ||
| 'timeout' => 10, | ||
| 'connectTimeout' => 5, | ||
| ], | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Light\App\Factory; | ||
|
|
||
| use Light\App\Handler\GetPackagesViewHandler; | ||
| use Light\App\Service\PackageGenerator; | ||
| use Light\Blog\Repository\CategoryRepository; | ||
| use Light\Blog\Repository\PostRepository; | ||
| use Mezzio\Template\TemplateRendererInterface; | ||
| use Psr\Container\ContainerInterface; | ||
|
|
||
| use function assert; | ||
|
|
||
| class GetPackagesViewHandlerFactory | ||
| { | ||
| public function __invoke(ContainerInterface $container): GetPackagesViewHandler | ||
| { | ||
| $template = $container->get(TemplateRendererInterface::class); | ||
| assert($template instanceof TemplateRendererInterface); | ||
|
|
||
| $categoryRepository = $container->get(CategoryRepository::class); | ||
| assert($categoryRepository instanceof CategoryRepository); | ||
|
|
||
| $postRepository = $container->get(PostRepository::class); | ||
| assert($postRepository instanceof PostRepository); | ||
|
|
||
| $packageGenerator = $container->get(PackageGenerator::class); | ||
| assert($packageGenerator instanceof PackageGenerator); | ||
|
|
||
| return new GetPackagesViewHandler($template, $categoryRepository, $postRepository, $packageGenerator); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Light\App\Factory; | ||
|
|
||
| use Light\App\Service\GitHubClient; | ||
| use Psr\Container\ContainerInterface; | ||
|
|
||
| use function is_array; | ||
|
|
||
| class GitHubClientFactory | ||
| { | ||
| public function __invoke(ContainerInterface $container): GitHubClient | ||
| { | ||
| $config = $container->get('config'); | ||
| if (! is_array($config)) { | ||
| $config = []; | ||
| } | ||
| // the token is in `config/autoload/local.php` | ||
| // if unauthenticated, the client has a lower call limit | ||
| $github = isset($config['github']) && is_array($config['github']) | ||
| ? $config['github'] | ||
| : []; | ||
| $packages = isset($config['packages']) && is_array($config['packages']) | ||
| ? $config['packages'] | ||
| : []; | ||
|
bidi47 marked this conversation as resolved.
|
||
|
|
||
| return new GitHubClient( | ||
| (string) ($github['authBearer'] ?? ''), | ||
| (string) ($github['userAgent'] ?? 'dotkernel.com'), | ||
| (int) ($packages['timeout'] ?? 10), | ||
| (int) ($packages['connectTimeout'] ?? 5), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Light\App\Factory; | ||
|
|
||
| use Light\App\Service\GitHubClientInterface; | ||
| use Light\App\Service\PackageGenerator; | ||
| use Psr\Container\ContainerInterface; | ||
|
|
||
| use function assert; | ||
| use function is_array; | ||
| use function is_scalar; | ||
|
|
||
| class PackageGeneratorFactory | ||
| { | ||
| public function __invoke(ContainerInterface $container): PackageGenerator | ||
| { | ||
| $client = $container->get(GitHubClientInterface::class); | ||
| assert($client instanceof GitHubClientInterface); | ||
|
|
||
| $config = $container->get('config'); | ||
| if (! is_array($config)) { | ||
| $config = []; | ||
| } | ||
| $github = isset($config['github']) && is_array($config['github']) | ||
| ? $config['github'] | ||
| : []; | ||
| $packages = isset($config['packages']) && is_array($config['packages']) | ||
| ? $config['packages'] | ||
| : []; | ||
|
bidi47 marked this conversation as resolved.
|
||
|
|
||
| $ignoreRepos = []; | ||
| if (isset($packages['ignoreRepos']) && is_array($packages['ignoreRepos'])) { | ||
| foreach ($packages['ignoreRepos'] as $repository) { | ||
| if (is_scalar($repository)) { | ||
| $ignoreRepos[] = (string) $repository; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return new PackageGenerator( | ||
| $client, | ||
| (string) ($packages['dataFile'] ?? 'data/packages.json'), | ||
| (string) ($github['org'] ?? 'dotkernel'), | ||
| $ignoreRepos, | ||
| (bool) ($packages['includeArchived'] ?? true), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Light\App\Handler; | ||
|
|
||
| use Laminas\Diactoros\Response\HtmlResponse; | ||
| use Light\App\Service\PackageGenerator; | ||
| use Light\Blog\Repository\CategoryRepository; | ||
| use Light\Blog\Repository\PostRepository; | ||
| use Mezzio\Template\TemplateRendererInterface; | ||
| use Psr\Http\Message\ResponseInterface; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
| use Psr\Http\Server\RequestHandlerInterface; | ||
|
|
||
| use function is_array; | ||
| use function is_string; | ||
|
|
||
| class GetPackagesViewHandler implements RequestHandlerInterface | ||
| { | ||
| public const string TEMPLATE = 'page::dotkernel-packages-oss-lifecycle'; | ||
|
|
||
| public function __construct( | ||
| private readonly TemplateRendererInterface $template, | ||
| private readonly CategoryRepository $categoryRepository, | ||
| private readonly PostRepository $postRepository, | ||
| private readonly PackageGenerator $packageGenerator, | ||
| ) { | ||
| } | ||
|
|
||
| public function handle(ServerRequestInterface $request): ResponseInterface | ||
| { | ||
| // no inline regeneration | ||
| // data is cached in `public/packages.json` by `bin/generate-packages` | ||
| $data = $this->packageGenerator->read(); | ||
| if (! is_array($data)) { | ||
| $data = []; | ||
| } | ||
| $packages = isset($data['packages']) && is_array($data['packages']) | ||
| ? $data['packages'] | ||
| : []; | ||
| $generatedAt = isset($data['generated_at']) && is_string($data['generated_at']) | ||
| ? $data['generated_at'] | ||
| : null; | ||
|
bidi47 marked this conversation as resolved.
|
||
|
|
||
| return new HtmlResponse( | ||
| $this->template->render(self::TEMPLATE, [ | ||
| 'posts' => $this->postRepository->getRecentPosts(3), | ||
| 'categories' => $this->categoryRepository->getCategories(), | ||
| 'packages' => $packages, | ||
| 'generatedAt' => $generatedAt, | ||
| ]) | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.