@iobroker/repochecker 3.0.0-alpha.0 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+ /*
3
+ This module is a support module for iobroker.repochecker
4
+
5
+ Area checked: NPM
6
+ Numbering : 200 - 299
7
+
8
+ */
9
+
10
+ const axios = require('axios');
11
+
12
+ // disable axios caching
13
+ axios.defaults.headers = {
14
+ 'Cache-Control': 'no-cache',
15
+ 'Pragma': 'no-cache',
16
+ 'Expires': '0',
17
+ };
18
+
19
+
20
+ // const common = require('./common.js');
21
+
22
+ async function checkNpm(context) {
23
+ console.log('\ncheckNpm [E2xx]');
24
+ const response = await axios(`https://registry.npmjs.org/iobroker.${context.adapterName}`)
25
+ let body = response.data;
26
+ // bug in NPM some modules could be accessed via normal web page, but not by API
27
+ if (!body) {
28
+ try {
29
+ const _response = await axios(`https://www.npmjs.com/package/iobroker.${context.adapterName}`);
30
+ if (!_response.data) {
31
+ context.errors.push('[E200] Not found on npm. Please publish');
32
+ return context;
33
+ } else {
34
+ body = _response.data;
35
+
36
+ context.checks.push('Adapter found on npm');
37
+ if (!body.includes('href="/~bluefox"') && body.includes('href="/~iobluefox"')) {
38
+ context.errors.push(`[E201] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`);
39
+ } else {
40
+ context.checks.push('Bluefox found in collaborators on NPM');
41
+ }
42
+ }
43
+ } catch (error) {
44
+ context.errors.push('[E200] Not found on npm. Please publish');
45
+ return context;
46
+ }
47
+ } else {
48
+ context.checks.push('Adapter found on npm');
49
+ if (!body.maintainers ||
50
+ !body.maintainers.length ||
51
+ !body.maintainers.find(user => user.name === 'bluefox' || user.name === 'iobluefox')) {
52
+ context.errors.push(`[E201] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`);
53
+ } else {
54
+ context.checks.push('Bluefox found in collaborators on NPM');
55
+ }
56
+
57
+ if (!body['dist-tags'] ||
58
+ context.packageJson.version !== body['dist-tags'].latest
59
+ ) {
60
+ if ( compareVersions.compare( body['dist-tags'].latest, context.packageJson.version, '>=' )) {
61
+ context.errors.push(`[E203] Version of package.json (${context.packageJson.version}) lower than latest version on NPM (${
62
+ (body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
63
+ } else {
64
+ context.warnings.push(`[W202] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${
65
+ (body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
66
+ }
67
+ } else {
68
+ context.checks.push(`Version of package.json ${context.packageJson.version} matches latest version on NPM`);
69
+ }
70
+ }
71
+
72
+ if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.news) {
73
+ const missingVersions = [];
74
+ for (const vers in context.ioPackageJson.common.news) {
75
+ //console.log(`[DEBUG] news for ${vers}`);
76
+ if (!body.versions[vers]) {
77
+ missingVersions.push(vers);
78
+ }
79
+ }
80
+ if (missingVersions.length) {
81
+ if (missingVersions.length === 1) {
82
+ context.errors.push(`[E204] Version "${missingVersions.join(', ')}" listed at common.news at io-package.json does not exist at NPM. Please remove from news section.`);
83
+ } else {
84
+ context.errors.push(`[E204] Versions "${missingVersions.join(', ')}" listed at common.news at io-package.json do not exist at NPM. Please remove from news section.`);
85
+ }
86
+ } else {
87
+ context.checks.push(`All versions listed at news exist at npm`);
88
+ }
89
+ }
90
+
91
+ return context;
92
+ }
93
+
94
+ exports.checkNpm = checkNpm;
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+ /*
3
+ This module is a support module for iobroker.repochecker
4
+
5
+ Area checked: Testing
6
+ Numbering : 300 - 399
7
+
8
+ */
9
+
10
+ // const common = require('./common.js');
11
+
12
+ async function checkTests(context) {
13
+ console.log('\ncheckTests [E3xx]');
14
+ // if found some file in `\.github\workflows` with the test inside => it is OK too
15
+ if (context && context.filesList.find(name => name.startsWith('.github/workflows/') && name.endsWith('.yml') && name.toLowerCase().includes('test'))) {
16
+ context.checks.push('Tests found on github actions');
17
+ return context;
18
+ }
19
+
20
+ // const travisURL = `${context.githubUrlOriginal.replace('github.com', 'api.travis-ci.org')}.png`;
21
+ //
22
+ // return axios(travisURL)
23
+ // .then(response => {
24
+ // if (!response.data) {
25
+ // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
26
+ // return context;
27
+ // }
28
+ // if (!response.headers || !response.headers['content-disposition']) {
29
+ // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
30
+ // return context;
31
+ // }
32
+ // // inline; filename="passing.png"
33
+ // const m = response.headers['content-disposition'].match(/filename="(.+)"$/);
34
+ // if (!m) {
35
+ // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
36
+ // return context;
37
+ // }
38
+ //
39
+ // if (m[1] === 'unknown.png') {
40
+ // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
41
+ // return context;
42
+ // }
43
+ //
44
+ // context.checks.push('Found on travis-ci');
45
+ //
46
+ // context.warnings.push('[W302] Use github actions instead of travis-ci');
47
+ //
48
+ // if (m[1] !== 'passing.png') {
49
+ // context.errors.push('[E301] Tests on Travis-ci.org are broken. Please fix.');
50
+ // } else {
51
+ // context.checks.push('Tests are OK on travis-ci');
52
+ // }
53
+ //
54
+ // return context;
55
+ // // max number is E302
56
+ // });
57
+ // return Promise.resolve(context);
58
+
59
+ return context;
60
+ }
61
+
62
+ exports.checkTests = checkTests;
@@ -0,0 +1,247 @@
1
+ 'use strict';
2
+ /*
3
+ This module is a support module for iobroker.repochecker
4
+
5
+ Area checked: Adapter Repository
6
+ Numbering : 400 - 499
7
+
8
+ */
9
+
10
+ const axios = require('axios');
11
+ const compareVersions = require('compare-versions');
12
+
13
+ // disable axios caching
14
+ axios.defaults.headers = {
15
+ 'Cache-Control': 'no-cache',
16
+ 'Pragma': 'no-cache',
17
+ 'Expires': '0',
18
+ };
19
+
20
+ const common = require('./common.js');
21
+
22
+ async function checkRepository(context) {
23
+ console.log('\ncheckRepository [E4xx]');
24
+ if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.type) { /* TODO: why check type here ? */
25
+ // download latest repo
26
+ const response = await axios('https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist.json')
27
+ let body = response.data;
28
+ if (!body) {
29
+ context.errors.push('[E400] Cannot download https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist.json');
30
+ } else {
31
+ context.latestRepo = body;
32
+ if (!context.latestRepo[context.adapterName]) {
33
+ context.warnings.push(`[W400] Cannot find "${context.adapterName}" in latest repository`);
34
+
35
+ if (context.adapterName.includes('_')) {
36
+ context.errors.push('[E429] Adapter name should use "-" instead of "_"');
37
+ } else {
38
+ context.checks.push('Adapter name does not have "_"');
39
+ }
40
+ } else {
41
+ context.checks.push('Adapter found in latest repository');
42
+
43
+ if (context.latestRepo[context.adapterName].type !== context.ioPackageJson.common.type) {
44
+ context.errors.push(`[E402] Types of adapter in latest repository and in io-package.json are different "${context.latestRepo[context.adapterName].type}" !== "${context.ioPackageJson.common.type}"`);
45
+ } else {
46
+ context.checks.push(`Types of adapter in latest repository and in io-package.json are equal: "${context.latestRepo[context.adapterName].type}"`);
47
+ }
48
+
49
+ if (context.latestRepo[context.adapterName].version) {
50
+ context.errors.push('[E403] Version set in latest repository');
51
+ } else {
52
+ context.checks.push('Version not set in latest repository');
53
+ }
54
+
55
+ const url = `https://raw.githubusercontent.com/${context.authorName}/ioBroker.${context.adapterName}/${context.branch}/`;
56
+
57
+ if (!context.latestRepo[context.adapterName].icon) {
58
+ context.errors.push('[E404] Icon not found in latest repository');
59
+ } else {
60
+ context.checks.push('Icon found in latest repository');
61
+
62
+ if (!context.latestRepo[context.adapterName].icon.startsWith(url)) {
63
+ context.errors.push(`[E405] Icon must be in the following path: ${url}; correct sources-dist.json`);
64
+ } else {
65
+ context.checks.push('Icon found in latest repository');
66
+ }
67
+ }
68
+ if (!context.latestRepo[context.adapterName].meta) {
69
+ context.errors.push('[E406] Meta URL not found in latest repository; correct sources-dist.json');
70
+ } else {
71
+ context.checks.push('Meta URL(latest) found in latest repository');
72
+
73
+ if (context.latestRepo[context.adapterName].meta !== `${url}io-package.json`) {
74
+ context.errors.push(`[E407] Meta URL must be equal to ${url}io-package.json; correct sources-dist.json`);
75
+ } else {
76
+ context.checks.push('Meta URL (latest) is OK in latest repository');
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ // download stable repo
83
+ let _response = await axios('https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist-stable.json');
84
+ body = _response.data;
85
+ if (!body) {
86
+ context.errors.push('[E420] Cannot download https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist-stable.json');
87
+ } else {
88
+ context.stableRepo = body;
89
+ if (context.stableRepo[context.adapterName]) {
90
+ if (context.stableRepo[context.adapterName].type !== context.ioPackageJson.common.type) {
91
+ context.errors.push(`[E422] Types of adapter in stable repository and in io-package.json are different "${context.stableRepo[context.adapterName].type}" !== "${context.ioPackageJson.common.type}"`);
92
+ } else {
93
+ context.checks.push(`Types of adapter in stable repository and in io-package.json are equal: "${context.stableRepo[context.adapterName].type}"`);
94
+ }
95
+
96
+ if (!context.latestRepo[context.adapterName]) {
97
+ context.errors.push('[E423] Adapter was found in stable repository but not in latest repo');
98
+ } else {
99
+ context.checks.push('Adapter was found in stable repository and in latest repo');
100
+ }
101
+
102
+ if (!context.stableRepo[context.adapterName].version) {
103
+ context.errors.push('[E424] No version set in stable repository');
104
+ } else {
105
+ context.checks.push('Version found in stable repository');
106
+ }
107
+
108
+ const url = `https://raw.githubusercontent.com/${context.authorName}/ioBroker.${context.adapterName}/${context.branch}/`;
109
+
110
+ if (!context.stableRepo[context.adapterName].icon) {
111
+ context.errors.push('[E425] Icon not found in stable repository');
112
+ } else {
113
+ context.checks.push('Icon found in stable repository');
114
+
115
+ if (!context.stableRepo[context.adapterName].icon.startsWith(url)) {
116
+ context.errors.push(`[E426] Icon must be in the following path: ${url}; correct sources-dist-stable.json`);
117
+ } else {
118
+ context.checks.push('Icon (stable) found in latest repository');
119
+ }
120
+ }
121
+
122
+ if (!context.stableRepo[context.adapterName].meta) {
123
+ context.errors.push('[E427] Meta URL not found in latest repository; correct sources-dist.json');
124
+ } else {
125
+ context.checks.push('Meta URL (stable) found in latest repository');
126
+
127
+ if (context.stableRepo[context.adapterName].meta !== `${url}io-package.json`) {
128
+ context.errors.push(`[E428] Meta URL must be equal to ${url}io-package.json; correct sources-dist-stable.json`);
129
+ } else {
130
+ context.checks.push('Meta URL (stable) is OK in latest repository');
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ _response = await axios('http://repo.iobroker.live/sources-dist-latest.json');
137
+ body = _response.data;
138
+ if (!body) {
139
+ context.errors.push('[E429] Cannot download http://repo.iobroker.live/sources-dist-latest.json');
140
+ } else {
141
+ context.latestRepoLive = body;
142
+ }
143
+
144
+ _response = await axios('http://repo.iobroker.live/sources-dist.json');
145
+ body = _response.data;
146
+ if (!body) {
147
+ context.errors.push('[E430] Cannot download http://repo.iobroker.live/sources-dist.json');
148
+ } else {
149
+ context.stableRepoLive = body;
150
+ }
151
+
152
+ if (context.latestRepo && context.latestRepoLive && context.stableRepo && context.stableRepoLive) {
153
+ if (context.ioPackageJson.common.dependencies) {
154
+ const dependencies = common.getDependencies(context.ioPackageJson.common.dependencies);
155
+ for ( const dependency in dependencies ) {
156
+
157
+ if ( !context.latestRepoLive[dependency] ) {
158
+ context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
159
+ } else {
160
+ const versDependency = dependencies[dependency];
161
+ const versRepository = context.latestRepoLive[dependency].version;
162
+ //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
163
+ if (!versDependency.startsWith('>=')) {
164
+ context.warnings.push(`[W432] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
165
+ } else {
166
+ if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
167
+ context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
168
+ } else {
169
+ context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at latest repository`);
170
+ }
171
+ }
172
+ }
173
+
174
+ if ( !context.stableRepoLive[dependency] ) {
175
+ context.warnings.push(`[W433] Dependency ${dependency} not available at stable repository`);
176
+ } else {
177
+ const versDependency = dependencies[dependency];
178
+ const versRepository = context.stableRepoLive[dependency].version;
179
+ //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
180
+ if (!versDependency.startsWith('>=')) {
181
+ context.warnings.push(`[W434] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
182
+ } else {
183
+ if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
184
+ context.errors.push(`[E433] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
185
+ } else {
186
+ context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at stable repository`);
187
+ }
188
+ }
189
+ }
190
+
191
+ }
192
+ } else {
193
+ context.checks.push('common.dependency check skipped');
194
+ }
195
+
196
+ if (context.ioPackageJson.common.globalDependencies) {
197
+ const dependencies = common.getDependencies(context.ioPackageJson.common.globalDependencies);
198
+ for ( const dependency in dependencies ) {
199
+
200
+ if ( !context.latestRepoLive[dependency] ) {
201
+ context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
202
+ } else {
203
+ const versDependency = dependencies[dependency];
204
+ const versRepository = context.latestRepoLive[dependency].version;
205
+ //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
206
+ if (!versDependency.startsWith('>=')) {
207
+ context.warnings.push(`[W432] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
208
+ } else {
209
+ if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
210
+ context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
211
+ } else {
212
+ context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at latest repository`);
213
+ }
214
+ }
215
+ }
216
+
217
+ if ( !context.stableRepoLive[dependency] ) {
218
+ context.warnings.push(`[W433] Dependency ${dependency} not available at stable repository`);
219
+ } else {
220
+ const versDependency = dependencies[dependency];
221
+ const versRepository = context.stableRepoLive[dependency].version;
222
+ //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
223
+ if (!versDependency.startsWith('>=')) {
224
+ context.warnings.push(`[W434] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
225
+ } else {
226
+ if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
227
+ context.errors.push(`[E433] Dependency '${dependency}':'${dependencies[dependency]}' not available at stable repository`);
228
+ } else {
229
+ context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at stable repository`);
230
+ }
231
+ }
232
+ }
233
+
234
+ }
235
+ } else {
236
+ context.checks.push('common.globalDependency check skipped');
237
+ }
238
+
239
+ } else {
240
+ context.checks.push(`Dependency checks skipped due to repository access errors`);
241
+ }
242
+ }
243
+ return context;
244
+ // max number is E429
245
+ }
246
+
247
+ exports.checkRepository = checkRepository;