-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.php
213 lines (184 loc) · 5.06 KB
/
gen.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
$ignore = [
"SymconBC",
"SymconBroken",
"SymconHelper",
"SymconIncompatible",
"SymconMisc",
"SymconTest",
"SymconWebinar",
"WeidmannEmlog",
"re",
"baresip"
];
$store = [
"Energiezaehler",
"Gardena",
"HomeConnect",
"Rechenmodule",
"SymconConfiguration",
"SymconGraph",
"SymconLJ",
"SymconMH",
"SymconREHAU",
"SymconReport",
"SymconSpotify"
];
$extern = [
"SyncMySQL",
"SymconREHAU",
"SymconMH",
"SymconLJ",
"FIWARE"
];
$unfinished = [
"Sonos",
"WaermemengenZaehler",
];
$url = [
"Alexa",
"Assistant",
"Gardena",
"HomeConnect",
"SymconLJ"
];
$opts = [
"http" => [
"method" => "GET",
"header" => "User-Agent: Awesome-PHP\r\n"
]
];
$context = stream_context_create($opts);
$repos = json_decode(file_get_contents("https://api.github.com/user/14051084/repos?per_page=100", false, $context), true);
if(sizeof($repos) == 100) {
die("We need to implement pagination");
}
$modules = json_decode(file_get_contents("https://symcon-store.s3.eu-west-1.amazonaws.com/modules.json"));
function hasURL($name)
{
global $modules, $url;
foreach ($modules as $module) {
if (!isset($module->url)) {
continue;
}
if (strpos($module->url, "/symcon/" . $name) !== false) {
return true;
}
}
// Fallback to manually checked modules
return in_array($name, $url);
}
function isInStore($name)
{
global $modules, $store;
foreach ($modules as $module) {
if ($module->name == $name) {
return true;
}
}
// Fallback to manually checked modules
return in_array($name, $store);
}
function filterRepo($repo)
{
if (substr($repo, 0, 4) == "Skin") {
return true;
}
if (substr($repo, 0, 5) == "Style") {
return true;
}
if (substr($repo, 0, 7) == "action-") {
return true;
}
if (in_array($repo, ["AndroidSDK", "Status"])) {
return true;
}
return false;
}
$content = "### Übersicht aller PHP-Module der Symcon GmbH und deren Check Status" . PHP_EOL;
$content .= PHP_EOL;
$content .= "Name | Style | Tests | Store | URL" . PHP_EOL;
$content .= "---- | ----- | ----- | ----- | ---" . PHP_EOL;
$count = 0;
foreach($repos as $repo) {
if (filterRepo($repo["name"])) {
continue;
}
if (!in_array($repo["name"], $ignore)
&& !in_array($repo["name"], $unfinished)
&& !in_array($repo["name"], $extern)
) {
$content .= "[" . $repo["name"] . "](https://github.com/symcon/" . $repo["name"] . "/) | ";
$content .= "[![Check Style](https://github.com/symcon/" . $repo["name"] . "/workflows/Check%20Style/badge.svg)](https://github.com/symcon/" . $repo["name"] . "/actions)" . " | ";
$content .= "[![Run Tests](https://github.com/symcon/" . $repo["name"] . "/workflows/Run%20Tests/badge.svg)](https://github.com/symcon/" . $repo["name"] . "/actions)" . " | ";
if (isInStore($repo["name"])) {
$content .= " ✅";
}
$content .= " | ";
if (hasURL($repo["name"])) {
$content .= " ✅";
}
$content .= PHP_EOL;
$count++;
}
}
$content .= "Aktuelle Anzahl der PHP-Module: " . $count . PHP_EOL;
$content .= PHP_EOL;
$content .= "### Veraltete/Besondere PHP-Module" . PHP_EOL;
$content .= PHP_EOL;
$content .= "Name |" . PHP_EOL;
$content .= "---- |" . PHP_EOL;
foreach($repos as $repo) {
if (filterRepo($repo["name"])) {
continue;
}
if (in_array($repo["name"], $ignore)) {
$content .= "[" . $repo["name"] . "](https://github.com/symcon/" . $repo["name"] . "/) |" . PHP_EOL;
}
}
$content .= PHP_EOL;
$content .= PHP_EOL;
$content .= "### Externe PHP-Module" . PHP_EOL;
$content .= PHP_EOL;
$content .= "Name |" . PHP_EOL;
$content .= "---- |" . PHP_EOL;
foreach($repos as $repo) {
if (filterRepo($repo["name"])) {
continue;
}
if (in_array($repo["name"], $extern)) {
$content .= "[" . $repo["name"] . "](https://github.com/symcon/" . $repo["name"] . "/) |" . PHP_EOL;
}
}
$content .= PHP_EOL;
$content .= PHP_EOL;
$content .= "### Unvollständige PHP-Module" . PHP_EOL;
$content .= PHP_EOL;
$content .= "Name |" . PHP_EOL;
$content .= "---- |" . PHP_EOL;
foreach($repos as $repo) {
if (filterRepo($repo["name"])) {
continue;
}
if (in_array($repo["name"], $unfinished)) {
$content .= "[" . $repo["name"] . "](https://github.com/symcon/" . $repo["name"] . "/) |" . PHP_EOL;
}
}
file_put_contents("README.md", $content);
//Copy&Paste: https://www.php.net/manual/de/reserved.variables.httpresponseheader.php
function parseHeaders($headers)
{
$head = array();
foreach($headers as $k => $v) {
$t = explode(':', $v, 2);
if(isset($t[1])) {
$head[ trim($t[0]) ] = trim($t[1]);
} else {
$head[] = $v;
if(preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $v, $out)) {
$head['reponse_code'] = intval($out[1]);
}
}
}
return $head;
}