diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a83ef38..3c1d208 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,4 @@ updates: directory: / schedule: interval: daily + time: 00:00 diff --git a/dependabot.php b/dependabot.php index 8432b73..f297e47 100644 --- a/dependabot.php +++ b/dependabot.php @@ -2,31 +2,86 @@ declare(strict_types=1); -$target_path = './.github/dependabot.yml'; +class Dependabot +{ + protected array $update = [ + 'package-ecosystem' => 'github-actions', -$content = file_exists($target_path) ? yaml_parse_file($target_path) : []; + 'directory' => '/', -$updates = $content['updates'] ?? []; + 'schedule' => [ + 'interval' => 'daily', + ], + ]; -foreach ($updates as $update) { - if ($update['package-ecosystem'] === 'github-actions') { - exit(0); + protected array $content = []; + + protected int $version = 2; + + protected string $name = 'github-actions'; + + public function __construct( + protected string $path + ) { + $this->content = $this->parse(); + } + + public function handle(): void + { + $updates = $this->each($this->getUpdates()); + $version = $this->getVersion(); + + $this->store($version, $updates); + } + + protected function each(array $updates): array + { + $found = false; + + foreach ($updates as &$update) { + if ($update['package-ecosystem'] === $this->name) { + $update = $this->update; + $found = true; + break; + } + } + + return $found ? $updates : $this->put($updates); } -} -$updates[] = [ - 'package-ecosystem' => 'github-actions', + protected function put(array $updates): array + { + $updates[] = $this->update; - 'directory' => '/', + return $updates; + } + + protected function store(int $version, array $updates): void + { + yaml_emit_file($this->path, compact('version', 'updates')); + } - 'schedule' => [ - 'interval' => 'daily', - 'time' => '00:00', - 'timezone' => 'Etc/GMT', - ], -]; + protected function getUpdates(): array + { + return $this->content['updates'] ?? []; + } + + protected function getVersion(): int + { + return $this->version; + } + + protected function parse(): array + { + return $this->exists() ? yaml_parse_file($this->path) : []; + } + + protected function exists(): bool + { + return file_exists($this->path); + } +} -$content['version'] = 2; -$content['updates'] = $updates; +$dependabot = new Dependabot('./.github/dependabot.yml'); -yaml_emit_file($target_path, $content); +$dependabot->handle();