/
Dependabot.php
83 lines (60 loc) · 1.73 KB
/
Dependabot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
declare(strict_types=1);
namespace DragonCode\CodeStyler\Processors;
use DragonCode\CodeStyler\Concerns\Files;
use DragonCode\Support\Facades\Helpers\Arr;
class Dependabot extends BaseProcessor
{
use Files;
protected const VERSION = 2;
protected const NAME = 'github-actions';
protected string $path = './.github/dependabot.yml';
protected array $update = [
'package-ecosystem' => self::NAME,
'directory' => '/',
'schedule' => [
'interval' => 'daily',
],
];
protected array $content = [];
public function run(): void
{
$this->content = $this->parse();
$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 (Arr::get($update, 'package-ecosystem') === self::NAME) {
$update = $this->update;
$found = true;
break;
}
}
return $found ? $updates : $this->put($updates);
}
protected function put(array $updates): array
{
$updates[] = $this->update;
return $updates;
}
protected function getUpdates(): array
{
return Arr::get($this->content, 'updates', []);
}
protected function getVersion(): int
{
return self::VERSION;
}
protected function parse(): array
{
return $this->filesystem()->load($this->path);
}
protected function store(int $version, array $updates): void
{
$this->filesystem()->store($this->path, compact('version', 'updates'));
}
}