@iobroker/repochecker 5.2.2 → 5.3.0

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.
package/README.md CHANGED
@@ -25,6 +25,16 @@ Example:
25
25
  Placeholder for the next version (at the beginning of the line):
26
26
  ### **WORK IN PROGRESS**
27
27
  -->
28
+ ### 5.3.0 (2026-03-11)
29
+ - (@copilot) Added validation for dependabot configuration: checks for required ecosystems (github-actions, npm), schedule settings, open-pull-requests-limit, and automerge workflow configuration (checks S8901–S8914).
30
+ - (@copilot) Extended W5034 check to also warn when `.ts` and `.js`/`.cjs`/`.mjs` versions of the same file exist in the same directory.
31
+ - (@copilot) E3003 YAML parse error for workflow files now logs only the first line (without the file excerpt).
32
+ - (@copilot) Added DEPENDABOT issue template for GitHub Copilot tasks.
33
+ - (@copilot) Extended testing checks (M3000_Testing.js): added checks for testing devDependency, test-and-release.yml workflow file presence, validity and required configuration.
34
+
35
+ ### 5.2.3 (2026-02-26)
36
+ - (@copilot) Fixed crash when `devDependencies` is missing from package.json. [#675]
37
+
28
38
  ### 5.2.2 (2026-02-25)
29
39
  - (mcm1957) Add warning if fa-icon entry still exists.
30
40
  - (@copilot) Added W6011/W7004 checks: warn when copyright lines in README.md or LICENSE are separated by an empty line instead of trailing two spaces.
@@ -995,8 +995,9 @@ async function checkPackageJson(context) {
995
995
  const alternatives = dependenciesPackageJson[dependency].alternatives || [];
996
996
  const optional = !!dependenciesPackageJson[dependency].optional;
997
997
  const suggested = !!dependenciesPackageJson[dependency].suggested;
998
- const exists = !!context.packageJson.dependencies[`${dependency}`];
999
- let dependencyVersion = context.packageJson.dependencies[`${dependency}`] || '';
998
+ const exists = !!(context.packageJson.dependencies && context.packageJson.dependencies[`${dependency}`]);
999
+ let dependencyVersion =
1000
+ (context.packageJson.dependencies && context.packageJson.dependencies[`${dependency}`]) || '';
1000
1001
  dependencyVersion = dependencyVersion.replace(/[\^~]/, '').trim();
1001
1002
 
1002
1003
  common.debug(` exists: ${exists}, optional: ${optional}, alternatives: [${alternatives}]`);
@@ -1022,7 +1023,7 @@ async function checkPackageJson(context) {
1022
1023
  // if dependency does not exist check if alternate exists
1023
1024
  let found = '';
1024
1025
  for (const alternative of alternatives) {
1025
- if (context.packageJson.dependencies[`${alternative}`]) {
1026
+ if (context.packageJson.dependencies && context.packageJson.dependencies[`${alternative}`]) {
1026
1027
  found = alternative;
1027
1028
  }
1028
1029
  }
@@ -1056,8 +1057,9 @@ async function checkPackageJson(context) {
1056
1057
  const alternatives = devDependenciesPackageJson[dependency].alternatives || [];
1057
1058
  const optional = !!devDependenciesPackageJson[dependency].optional;
1058
1059
  const suggested = !!devDependenciesPackageJson[dependency].suggested;
1059
- const exists = !!context.packageJson.devDependencies[`${dependency}`];
1060
- let dependencyVersion = context.packageJson.devDependencies[`${dependency}`] || '';
1060
+ const exists = !!(context.packageJson.devDependencies && context.packageJson.devDependencies[`${dependency}`]);
1061
+ let dependencyVersion =
1062
+ (context.packageJson.devDependencies && context.packageJson.devDependencies[`${dependency}`]) || '';
1061
1063
  dependencyVersion = dependencyVersion.replace(/[\^~]/, '');
1062
1064
 
1063
1065
  common.debug(` exists: ${exists}, optional: ${optional}, alternatives: [${alternatives}]`);
@@ -1083,7 +1085,7 @@ async function checkPackageJson(context) {
1083
1085
  // if dependency does not exist - check if alternate exists
1084
1086
  let found = '';
1085
1087
  for (const alternative of alternatives) {
1086
- if (context.packageJson.devDependencies[`${alternative}`]) {
1088
+ if (context.packageJson.devDependencies && context.packageJson.devDependencies[`${alternative}`]) {
1087
1089
  found = alternative;
1088
1090
  }
1089
1091
  }
@@ -1104,7 +1106,7 @@ async function checkPackageJson(context) {
1104
1106
  context.checks.push('required devDependencies have been checked.');
1105
1107
 
1106
1108
  // Check for unneeded devDependencies when @iobroker/testing >= 5.1.1 is installed
1107
- if (context.packageJson.devDependencies['@iobroker/testing']) {
1109
+ if (context.packageJson.devDependencies && context.packageJson.devDependencies['@iobroker/testing']) {
1108
1110
  const testingVersion = context.packageJson.devDependencies['@iobroker/testing'].replace(/[\^~]/, '').trim();
1109
1111
  try {
1110
1112
  if (compareVersions.compare(testingVersion, '5.1.1', '>=')) {
@@ -1157,7 +1159,7 @@ async function checkPackageJson(context) {
1157
1159
  '@iobroker/adapter-dev',
1158
1160
  '@iobroker/testing',
1159
1161
  ];
1160
- const expandedDependencies = expandNpmAliases(context.packageJson.dependencies);
1162
+ const expandedDependencies = expandNpmAliases(context.packageJson.dependencies || {});
1161
1163
  let forcedDependencyFlag = false;
1162
1164
  for (const dependency in expandedDependencies) {
1163
1165
  const dependencyVersion = expandedDependencies[dependency];
@@ -1197,7 +1199,7 @@ async function checkPackageJson(context) {
1197
1199
  );
1198
1200
  }
1199
1201
 
1200
- const expandedDevDependencies = expandNpmAliases(context.packageJson.devDependencies);
1202
+ const expandedDevDependencies = expandNpmAliases(context.packageJson.devDependencies || {});
1201
1203
  let forcedDevDependencyFlag = false;
1202
1204
  for (const dependency in expandedDevDependencies) {
1203
1205
  const dependencyVersion = expandedDevDependencies[dependency];
@@ -98,7 +98,7 @@ const blacklistIOPackageJson = {
98
98
  },
99
99
  'common.adminTab.fa-icon': {
100
100
  msg: '"common.adminTab.fa-icon" is deprecated and ignored. Please remove from io-package.json.',
101
- err: false,
101
+ err: true,
102
102
  },
103
103
  };
104
104
 
@@ -7,60 +7,281 @@
7
7
 
8
8
  */
9
9
 
10
- // const common = require('./common.js');
10
+ const yaml = require('js-yaml');
11
+ const common = require('./common.js');
12
+
13
+ const WORKFLOW_FILE = '/.github/workflows/test-and-release.yml';
14
+
15
+ /**
16
+ * Returns true if the given file path exists in the context's filesList,
17
+ * handling both the leading-slash (remote) and no-leading-slash (local) formats.
18
+ *
19
+ * @param {object} context - The checker context
20
+ * @param {string} filePath - File path with leading slash (e.g. '/.github/workflows/test-and-release.yml')
21
+ * @returns {boolean} true if file is found in filesList
22
+ */
23
+ function fileExistsInList(context, filePath) {
24
+ if (!context.filesList) {
25
+ return false;
26
+ }
27
+ // remote mode: paths have leading slash; local mode: paths don't have leading slash
28
+ return context.filesList.includes(filePath) || context.filesList.includes(filePath.replace(/^\//, ''));
29
+ }
30
+
31
+ /**
32
+ * Returns true if any step in a job uses the given action (prefix match).
33
+ *
34
+ * @param {object} job - A GitHub Actions job object
35
+ * @param {string} actionPrefix - The action name prefix to look for (e.g. 'ioBroker/testing-action-check@')
36
+ * @returns {boolean} true if a matching step is found
37
+ */
38
+ function jobHasStepWithAction(job, actionPrefix) {
39
+ if (!job || !Array.isArray(job.steps)) {
40
+ return false;
41
+ }
42
+ return job.steps.some(step => typeof step.uses === 'string' && step.uses.startsWith(actionPrefix));
43
+ }
44
+
45
+ /**
46
+ * Returns true if the given job declares that it needs all of the specified jobs.
47
+ *
48
+ * @param {object} job - A GitHub Actions job object
49
+ * @param {string[]} requiredJobs - Job names that must be listed in job.needs
50
+ * @returns {boolean} true if all required jobs are listed in needs
51
+ */
52
+ function jobNeedsAll(job, requiredJobs) {
53
+ if (!job) {
54
+ return false;
55
+ }
56
+ const needs = job.needs;
57
+ if (!needs) {
58
+ return false;
59
+ }
60
+ const needsArr = Array.isArray(needs) ? needs : [needs];
61
+ return requiredJobs.every(req => needsArr.includes(req));
62
+ }
11
63
 
12
64
  async function checkTests(context) {
13
65
  console.log('\n[E3000 - E3999] checking tests');
14
- // if found some file in `\.github\workflows` with the test inside => it is OK too
15
- if (
16
- context &&
17
- context.filesList.find(
18
- name =>
19
- name.startsWith('.github/workflows/') && name.endsWith('.yml') && name.toLowerCase().includes('test'),
20
- )
21
- ) {
22
- context.checks.push('Tests found on github actions');
66
+
67
+ // --- E3000: check for testing devDependency ---
68
+ const devDeps = (context.packageJson && context.packageJson.devDependencies) || {};
69
+ const hasTesting = Object.prototype.hasOwnProperty.call(devDeps, '@iobroker/testing');
70
+ const hasLegacyTesting = Object.prototype.hasOwnProperty.call(devDeps, '@iobroker/legacy-testing');
71
+
72
+ if (!hasTesting && !hasLegacyTesting) {
73
+ context.errors.push(
74
+ '[E3000] Neither "@iobroker/testing" nor "@iobroker/legacy-testing" is listed as a devDependency in package.json. Please add one of them.',
75
+ );
76
+ // Without a testing framework, skip further workflow checks
77
+ return context;
78
+ }
79
+ context.checks.push('Testing devDependency found in package.json.');
80
+
81
+ if (hasLegacyTesting && !hasTesting) {
82
+ context.warnings.push(
83
+ '[S3001] "@iobroker/legacy-testing" is used. Consider migrating to "@iobroker/testing" for better support.',
84
+ );
85
+ // Skip further workflow checks for legacy-testing adapters
86
+ return context;
87
+ }
88
+
89
+ // --- E3002: check that test-and-release.yml exists ---
90
+ if (!fileExistsInList(context, WORKFLOW_FILE)) {
91
+ context.errors.push(
92
+ `[E3002] Workflow file "${WORKFLOW_FILE}" not found. Please create it for standard CI/CD testing.`,
93
+ );
94
+ return context;
95
+ }
96
+
97
+ context.checks.push(`Workflow file "${WORKFLOW_FILE}" found.`);
98
+
99
+ // --- Load the workflow file ---
100
+ let workflowContent;
101
+ try {
102
+ workflowContent = await common.getFile(context, WORKFLOW_FILE);
103
+ } catch (e) {
104
+ context.errors.push(`[E3003] Could not read workflow file "${WORKFLOW_FILE}": ${e}`);
105
+ return context;
106
+ }
107
+
108
+ if (!workflowContent) {
109
+ context.errors.push(`[E3003] Workflow file "${WORKFLOW_FILE}" is empty or could not be read.`);
110
+ return context;
111
+ }
112
+
113
+ // --- E3003: validate workflow YAML ---
114
+ let workflow;
115
+ try {
116
+ workflow = yaml.load(workflowContent);
117
+ } catch (e) {
118
+ context.errors.push(`[E3003] Workflow file "${WORKFLOW_FILE}" is not valid YAML: ${e.message.split('\n')[0]}`);
23
119
  return context;
24
120
  }
25
121
 
26
- // const travisURL = `${context.githubUrlOriginal.replace('github.com', 'api.travis-ci.org')}.png`;
27
- //
28
- // return axios(travisURL)
29
- // .then(response => {
30
- // if (!response.data) {
31
- // context.errors.push('[E3000] Not found on travis. Please setup travis or use github actions (preferred)');
32
- // return context;
33
- // }
34
- // if (!response.headers || !response.headers['content-disposition']) {
35
- // context.errors.push('[E3000] Not found on travis. Please setup travis or use github actions (preferred)');
36
- // return context;
37
- // }
38
- // // inline; filename="passing.png"
39
- // const m = response.headers['content-disposition'].match(/filename="(.+)"$/);
40
- // if (!m) {
41
- // context.errors.push('[E3000] Not found on travis. Please setup travis or use github actions (preferred)');
42
- // return context;
43
- // }
44
- //
45
- // if (m[1] === 'unknown.png') {
46
- // context.errors.push('[E3000] Not found on travis. Please setup travis or use github actions (preferred)');
47
- // return context;
48
- // }
49
- //
50
- // context.checks.push('Found on travis-ci');
51
- //
52
- // context.warnings.push('[W3002] Use github actions instead of travis-ci');
53
- //
54
- // if (m[1] !== 'passing.png') {
55
- // context.errors.push('[E3001] Tests on Travis-ci.org are broken. Please fix.');
56
- // } else {
57
- // context.checks.push('Tests are OK on travis-ci');
58
- // }
59
- //
60
- // return context;
61
- // // max number is E302
62
- // });
63
- // return Promise.resolve(context);
122
+ if (!workflow || typeof workflow !== 'object') {
123
+ context.errors.push(`[E3003] Workflow file "${WORKFLOW_FILE}" does not contain valid workflow content.`);
124
+ return context;
125
+ }
126
+
127
+ context.checks.push(`Workflow file "${WORKFLOW_FILE}" is valid YAML.`);
128
+
129
+ // --- W3004: check workflow name ---
130
+ if (workflow.name !== 'Test and Release') {
131
+ context.warnings.push(
132
+ `[W3004] Workflow "name" in "${WORKFLOW_FILE}" should be "Test and Release" (found: "${workflow.name || '(not set)'}" ).`,
133
+ );
134
+ } else {
135
+ context.checks.push('Workflow name is "Test and Release".');
136
+ }
137
+
138
+ // --- Check the 'on' attribute ---
139
+ const onAttr = workflow['on'] || workflow.on;
140
+
141
+ // --- W3005: check for pull_request in 'on' ---
142
+ if (!onAttr || !Object.prototype.hasOwnProperty.call(onAttr, 'pull_request')) {
143
+ context.warnings.push(
144
+ `[W3005] Workflow "${WORKFLOW_FILE}" should have "pull_request: {}" in the "on" trigger configuration.`,
145
+ );
146
+ } else {
147
+ context.checks.push('Workflow trigger includes "pull_request".');
148
+ }
149
+
150
+ // --- E3006 / E3007 / E3008: check for push in 'on' ---
151
+ if (!onAttr || !Object.prototype.hasOwnProperty.call(onAttr, 'push')) {
152
+ context.errors.push(
153
+ `[E3006] Workflow "${WORKFLOW_FILE}" is missing the "push" trigger in the "on" configuration.`,
154
+ );
155
+ } else {
156
+ context.checks.push('Workflow trigger includes "push".');
157
+
158
+ const pushConfig = onAttr.push || {};
159
+
160
+ // E3007: check push branches
161
+ const branches = pushConfig.branches;
162
+ if (!branches || !Array.isArray(branches) || branches.length === 0) {
163
+ context.errors.push(
164
+ `[E3007] Workflow "${WORKFLOW_FILE}": "push" trigger is missing "branches" configuration. ` +
165
+ `Must include "*" or the default branch ("${context.branch}").`,
166
+ );
167
+ } else {
168
+ const defaultBranch = context.branch || 'main';
169
+ const hasWildcard = branches.includes('*');
170
+ const hasDefaultBranch = branches.includes(defaultBranch);
171
+ if (!hasWildcard && !hasDefaultBranch) {
172
+ context.errors.push(
173
+ `[E3007] Workflow "${WORKFLOW_FILE}": "push" trigger "branches" must include "*" or the default branch "${defaultBranch}". ` +
174
+ `Found: ${JSON.stringify(branches)}`,
175
+ );
176
+ } else {
177
+ context.checks.push('Workflow "push" trigger branches are correctly configured.');
178
+ }
179
+ }
180
+
181
+ // E3008: check push tags
182
+ const tags = pushConfig.tags;
183
+ const requiredTagPatterns = ['v[0-9]+.[0-9]+.[0-9]+', 'v[0-9]+.[0-9]+.[0-9]+-**'];
184
+ if (!tags || !Array.isArray(tags)) {
185
+ context.errors.push(
186
+ `[E3008] Workflow "${WORKFLOW_FILE}": "push" trigger is missing "tags" configuration. ` +
187
+ `Required tag patterns: ${requiredTagPatterns.join(', ')}`,
188
+ );
189
+ } else {
190
+ const missingPatterns = requiredTagPatterns.filter(pat => !tags.includes(pat));
191
+ if (missingPatterns.length > 0) {
192
+ context.errors.push(
193
+ `[E3008] Workflow "${WORKFLOW_FILE}": "push" trigger "tags" is missing required pattern(s): ${missingPatterns.join(', ')}`,
194
+ );
195
+ } else {
196
+ context.checks.push('Workflow "push" trigger tags are correctly configured.');
197
+ }
198
+ }
199
+ }
200
+
201
+ // --- W3009: check concurrency ---
202
+ const concurrency = workflow.concurrency;
203
+ if (!concurrency || concurrency.group !== '${{ github.ref }}' || concurrency['cancel-in-progress'] !== true) {
204
+ context.warnings.push(
205
+ `[W3009] Workflow "${WORKFLOW_FILE}" is missing the recommended concurrency configuration:\n` +
206
+ ` concurrency:\n group: \${{ github.ref }}\n cancel-in-progress: true`,
207
+ );
208
+ } else {
209
+ context.checks.push('Workflow concurrency configuration is correct.');
210
+ }
211
+
212
+ // skip detailled tests if adapter uses legacy testing
213
+ if (!hasLegacyTesting) {
214
+ // --- Check jobs ---
215
+ const jobs = workflow.jobs || {};
216
+
217
+ // E3010: check-and-lint job
218
+ if (!jobs['check-and-lint']) {
219
+ context.errors.push(`[E3010] Workflow "${WORKFLOW_FILE}": job "check-and-lint" is missing. Please add it.`);
220
+ } else {
221
+ context.checks.push('Job "check-and-lint" found.');
222
+
223
+ // W3013: check-and-lint must use ioBroker/testing-action-check@v1
224
+ if (!jobHasStepWithAction(jobs['check-and-lint'], 'ioBroker/testing-action-check@')) {
225
+ context.warnings.push(
226
+ `[W3013] Workflow "${WORKFLOW_FILE}": job "check-and-lint" should contain a step using "ioBroker/testing-action-check@v1".`,
227
+ );
228
+ } else {
229
+ context.checks.push('Job "check-and-lint" uses "ioBroker/testing-action-check@v1".');
230
+ }
231
+ }
232
+
233
+ // E3011: adapter-tests job
234
+ if (!jobs['adapter-tests']) {
235
+ context.errors.push(`[E3011] Workflow "${WORKFLOW_FILE}": job "adapter-tests" is missing. Please add it.`);
236
+ } else {
237
+ context.checks.push('Job "adapter-tests" found.');
238
+
239
+ // S3014: adapter-tests should need check-and-lint
240
+ if (!jobNeedsAll(jobs['adapter-tests'], ['check-and-lint'])) {
241
+ context.warnings.push(
242
+ `[S3014] Workflow "${WORKFLOW_FILE}": job "adapter-tests" should declare "needs: check-and-lint" to run after linting.`,
243
+ );
244
+ } else {
245
+ context.checks.push('Job "adapter-tests" correctly requires "check-and-lint".');
246
+ }
247
+
248
+ // W3015: adapter-tests must use ioBroker/testing-action-adapter@v1
249
+ if (!jobHasStepWithAction(jobs['adapter-tests'], 'ioBroker/testing-action-adapter@')) {
250
+ context.warnings.push(
251
+ `[W3015] Workflow "${WORKFLOW_FILE}": job "adapter-tests" should contain a step using "ioBroker/testing-action-adapter@v1".`,
252
+ );
253
+ } else {
254
+ context.checks.push('Job "adapter-tests" uses "ioBroker/testing-action-adapter@v1".');
255
+ }
256
+ }
257
+
258
+ // S3012: deploy job (suggestion if missing)
259
+ if (!jobs['deploy']) {
260
+ context.warnings.push(
261
+ `[S3012] Workflow "${WORKFLOW_FILE}": job "deploy" is not defined. Consider adding it for automated releases.`,
262
+ );
263
+ } else {
264
+ context.checks.push('Job "deploy" found.');
265
+
266
+ // E3016: deploy must need check-and-lint and adapter-tests
267
+ if (!jobNeedsAll(jobs['deploy'], ['check-and-lint', 'adapter-tests'])) {
268
+ context.errors.push(
269
+ `[E3016] Workflow "${WORKFLOW_FILE}": job "deploy" must declare "needs" for both "check-and-lint" and "adapter-tests".`,
270
+ );
271
+ } else {
272
+ context.checks.push('Job "deploy" correctly requires "check-and-lint" and "adapter-tests".');
273
+ }
274
+
275
+ // W3017: deploy must use ioBroker/testing-action-deploy@v1
276
+ if (!jobHasStepWithAction(jobs['deploy'], 'ioBroker/testing-action-deploy@')) {
277
+ context.warnings.push(
278
+ `[W3017] Workflow "${WORKFLOW_FILE}": job "deploy" should contain a step using "ioBroker/testing-action-deploy@v1".`,
279
+ );
280
+ } else {
281
+ context.checks.push('Job "deploy" uses "ioBroker/testing-action-deploy@v1".');
282
+ }
283
+ }
284
+ }
64
285
 
65
286
  return context;
66
287
  }
package/lib/M5000_Code.js CHANGED
@@ -210,8 +210,8 @@ async function checkCode(context) {
210
210
  }
211
211
 
212
212
  // Check for conflicting JavaScript file extensions in the same directory
213
- // E5034: Files with the same base name but different extensions (.js, .cjs, .mjs) in the same directory
214
- const jsExtensions = ['.js', '.cjs', '.mjs'];
213
+ // W5034: Files with the same base name but different extensions (.ts, .js, .cjs, .mjs) in the same directory
214
+ const jsExtensions = ['.ts', '.js', '.cjs', '.mjs'];
215
215
  const filesByDirectory = new Map();
216
216
 
217
217
  // Group files by directory and base name
@@ -243,7 +243,7 @@ async function checkCode(context) {
243
243
  .sort()
244
244
  .join(', ');
245
245
  context.warnings.push(
246
- `[W5034] Files with conflicting extensions found in directory "${dir}": ${filePaths} - Only one JavaScript file extension (.js, .cjs, or .mjs) should be used per file name.`,
246
+ `[W5034] Files with conflicting extensions found in directory "${dir}": ${filePaths} - Only one JavaScript/TypeScript file extension (.ts, .js, .cjs, or .mjs) should be used per file name.`,
247
247
  );
248
248
  }
249
249
  });
@@ -952,7 +952,7 @@ exports.checkCode = checkCode;
952
952
  // [5031] "gulpfile.js" found in repo with @iobroker/adapter-dev. Check if gulp is still needed.
953
953
  // [5032] "lib/tools.js" found in repo but not used anywhere. Consider removing this outdated file.
954
954
  // [5033] method "${method}()" is deprecated and will be removed with future js-controller version. Please use "set/deleteObject()" instead.
955
- // [5034] Files with conflicting extensions found in directory "${dir}": ${filePaths} - Only one JavaScript file extension (.js, .cjs, or .mjs) should be used per file name.
955
+ // [5034] Files with conflicting extensions found in directory "${dir}": ${filePaths} - Only one JavaScript/TypeScript file extension (.ts, .js, .cjs, or .mjs) should be used per file name.
956
956
  // [5035] Cannot parse YAML file "${fileName}": ${e.message}
957
957
  // [5038] Conflicting JSON files in directory "${dir}": Both ${baseName}.json and ${baseName}.json5 versions of same file exist. Please remove one.
958
958
 
@@ -29,6 +29,7 @@ axios.defaults.headers.common = {
29
29
  };
30
30
 
31
31
  const common = require('./common.js');
32
+ const M8900__Dependabot = require('./M8900__Dependabot.js');
32
33
 
33
34
  async function getAllIssues(context) {
34
35
  //console.log('\ngetAllIssues');
@@ -120,6 +121,8 @@ async function checkGithubRepo(context) {
120
121
  }
121
122
 
122
123
  // max E803 - limited to 849
124
+ // E8900 - E8999: reserved for M8900__Dependabot
125
+ await M8900__Dependabot.checkDependabot(context);
123
126
 
124
127
  return context;
125
128
  }
@@ -133,3 +136,5 @@ exports.checkGithubRepo = checkGithubRepo;
133
136
  // [E8001] No repository about text found. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add the description.
134
137
  // [E8002] No topics found in the repository. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add some topics.
135
138
  // [E8003] Archived repositories are not allowed.
139
+ //
140
+ // [E8900 - E8999] Dependabot checks - see M8900__Dependabot.js
@@ -0,0 +1,302 @@
1
+ 'use strict';
2
+ /*
3
+ This module is a support module for iobroker.repochecker
4
+
5
+ Area checked: Dependabot configuration
6
+ Numbering : 8900 - 8999
7
+
8
+ */
9
+
10
+ const yaml = require('js-yaml');
11
+ const common = require('./common.js');
12
+
13
+ const DEPENDABOT_FILE = '/.github/dependabot.yml';
14
+ const AUTOMERGE_FILE = '/.github/workflows/automerge-dependabot.yml';
15
+ const OLD_AUTOMERGE_FILE = '/.github/workflows/dependabot-auto-merge.yml';
16
+ const OLD_AUTOMERGE_FILE_OLD = '/.github/workflows/dependabot-auto-merge.yml.OLD';
17
+ const AUTO_MERGE_CONFIG = '/.github/auto-merge.yml';
18
+
19
+ /**
20
+ * Returns true if the given file path exists in the context's filesList,
21
+ * handling both the leading-slash (remote) and no-leading-slash (local) formats.
22
+ *
23
+ * @param {object} context - The checker context
24
+ * @param {string} filePath - File path with leading slash (e.g. '/.github/dependabot.yml')
25
+ * @returns {boolean} true if file is found in filesList
26
+ */
27
+ function fileExistsInList(context, filePath) {
28
+ if (!context.filesList) {
29
+ return false;
30
+ }
31
+ return context.filesList.includes(filePath) || context.filesList.includes(filePath.replace(/^\//, ''));
32
+ }
33
+
34
+ /**
35
+ * Checks the automerge workflow configuration.
36
+ *
37
+ * @param {object} context - The checker context
38
+ */
39
+ async function checkAutomerge(context) {
40
+ const hasNewAutomerge = fileExistsInList(context, AUTOMERGE_FILE);
41
+ const hasOldAutomerge = fileExistsInList(context, OLD_AUTOMERGE_FILE);
42
+ const automergeConfigured = hasNewAutomerge || hasOldAutomerge;
43
+
44
+ if (!automergeConfigured) {
45
+ // S8913: Suggest to set up automerging
46
+ context.warnings.push(
47
+ `[S8913] No automerge workflow found. Consider setting up automerging by adding ".github/workflows/automerge-dependabot.yml".`,
48
+ );
49
+ return;
50
+ }
51
+
52
+ context.checks.push('Automerge workflow found.');
53
+
54
+ // Validate automerge files as YAML and check for deprecated action
55
+ const filesToCheck = [];
56
+ if (hasNewAutomerge) {
57
+ filesToCheck.push(AUTOMERGE_FILE);
58
+ }
59
+ if (hasOldAutomerge) {
60
+ filesToCheck.push(OLD_AUTOMERGE_FILE);
61
+ }
62
+
63
+ for (const filePath of filesToCheck) {
64
+ let fileContent;
65
+ try {
66
+ fileContent = await common.getFile(context, filePath);
67
+ } catch (e) {
68
+ context.errors.push(
69
+ `[E8912] Cannot read automerge workflow file "${filePath}": ${e.message.split('\n')[0]}`,
70
+ );
71
+ continue;
72
+ }
73
+
74
+ if (!fileContent) {
75
+ context.errors.push(`[E8912] Automerge workflow file "${filePath}" is empty.`);
76
+ continue;
77
+ }
78
+
79
+ try {
80
+ yaml.load(fileContent);
81
+ } catch (e) {
82
+ context.errors.push(
83
+ `[E8912] Automerge workflow file "${filePath}" is not valid YAML: ${e.message.split('\n')[0]}`,
84
+ );
85
+ continue;
86
+ }
87
+
88
+ context.checks.push(`Automerge workflow file "${filePath}" is valid YAML.`);
89
+
90
+ // E8912: Check for deprecated action
91
+ if (fileContent.includes('ahmadnassri/action-dependabot-auto-merge')) {
92
+ context.errors.push(
93
+ `[E8912] Automerge workflow file "${filePath}" uses deprecated action "ahmadnassri/action-dependabot-auto-merge" which no longer works. ` +
94
+ `Please migrate to "iobroker-bot-orga/action-automerge-dependabot@v1".`,
95
+ );
96
+ }
97
+ }
98
+
99
+ // S8914: If automerging is active and .github/auto-merge.yml does not exist, suggest to add it
100
+ if (!fileExistsInList(context, AUTO_MERGE_CONFIG)) {
101
+ context.warnings.push(
102
+ `[S8914] Automerge is configured but ".github/auto-merge.yml" was not found. Consider adding it to allow specific automerge configurations.`,
103
+ );
104
+ } else {
105
+ context.checks.push('".github/auto-merge.yml" found.');
106
+ }
107
+ }
108
+
109
+ async function checkDependabot(context) {
110
+ console.log('\n[E8900 - E8999] checking dependabot');
111
+
112
+ // S8901: Check if dependabot.yml exists
113
+ if (!fileExistsInList(context, DEPENDABOT_FILE)) {
114
+ context.warnings.push(
115
+ `[S8901] Dependabot configuration file ".github/dependabot.yml" not found. Consider adding dependabot to keep dependencies up to date.`,
116
+ );
117
+ // Still check automerge configuration even if dependabot.yml is missing
118
+ await checkAutomerge(context);
119
+ return context;
120
+ }
121
+
122
+ context.checks.push('Dependabot configuration file ".github/dependabot.yml" found.');
123
+
124
+ // Load and validate dependabot.yml
125
+ let content;
126
+ try {
127
+ content = await common.getFile(context, DEPENDABOT_FILE);
128
+ } catch (e) {
129
+ context.errors.push(
130
+ `[E8902] Cannot read dependabot configuration file "${DEPENDABOT_FILE}": ${e.message.split('\n')[0]}`,
131
+ );
132
+ await checkAutomerge(context);
133
+ return context;
134
+ }
135
+
136
+ if (!content) {
137
+ context.errors.push(`[E8902] Dependabot configuration file "${DEPENDABOT_FILE}" is empty.`);
138
+ await checkAutomerge(context);
139
+ return context;
140
+ }
141
+
142
+ // E8902: Validate YAML
143
+ let dependabotConfig;
144
+ try {
145
+ dependabotConfig = yaml.load(content);
146
+ } catch (e) {
147
+ context.errors.push(
148
+ `[E8902] Dependabot configuration file "${DEPENDABOT_FILE}" is not valid YAML: ${e.message.split('\n')[0]}`,
149
+ );
150
+ await checkAutomerge(context);
151
+ return context;
152
+ }
153
+
154
+ if (!dependabotConfig || typeof dependabotConfig !== 'object') {
155
+ context.errors.push(
156
+ `[E8902] Dependabot configuration file "${DEPENDABOT_FILE}" does not contain a valid dependabot configuration.`,
157
+ );
158
+ await checkAutomerge(context);
159
+ return context;
160
+ }
161
+
162
+ context.checks.push('Dependabot configuration file is valid YAML.');
163
+
164
+ const updates = dependabotConfig.updates;
165
+ if (!Array.isArray(updates) || updates.length === 0) {
166
+ context.errors.push(
167
+ `[E8903] Dependabot configuration "${DEPENDABOT_FILE}" has no "updates" entries. At least "github-actions" and "npm" ecosystems should be configured.`,
168
+ );
169
+ await checkAutomerge(context);
170
+ return context;
171
+ }
172
+
173
+ // E8903: Check for github-actions ecosystem
174
+ const hasGithubActions = updates.some(u => u['package-ecosystem'] === 'github-actions');
175
+ if (!hasGithubActions) {
176
+ context.errors.push(
177
+ `[E8903] Dependabot configuration "${DEPENDABOT_FILE}" has no entry with "package-ecosystem: github-actions". Please add one.`,
178
+ );
179
+ } else {
180
+ context.checks.push('Dependabot is configured for "github-actions" ecosystem.');
181
+ }
182
+
183
+ // E8904: Check for npm ecosystem
184
+ const hasNpm = updates.some(u => u['package-ecosystem'] === 'npm');
185
+ if (!hasNpm) {
186
+ context.errors.push(
187
+ `[E8904] Dependabot configuration "${DEPENDABOT_FILE}" has no entry with "package-ecosystem: npm". Please add one.`,
188
+ );
189
+ } else {
190
+ context.checks.push('Dependabot is configured for "npm" ecosystem.');
191
+ }
192
+
193
+ // W8905: If multiple package.json files exist in non-root directories, check npm entry uses directories wildcard
194
+ if (hasNpm) {
195
+ const filesList = context.filesList || [];
196
+ const nonRootPackageJsonFiles = filesList.filter(f => {
197
+ const normalized = f.startsWith('/') ? f : `/${f}`;
198
+ // Match any package.json that is NOT at the root
199
+ return /\/[^/]+\/.*package\.json$/.test(normalized);
200
+ });
201
+
202
+ if (nonRootPackageJsonFiles.length > 0) {
203
+ const npmEntries = updates.filter(u => u['package-ecosystem'] === 'npm');
204
+ const hasDirectoriesWildcard = npmEntries.some(u => {
205
+ const configuredDirectories = u['directories'];
206
+ return (
207
+ Array.isArray(configuredDirectories) &&
208
+ configuredDirectories.some(dir => dir === '**/*' || dir === '**')
209
+ );
210
+ });
211
+
212
+ if (!hasDirectoriesWildcard) {
213
+ context.warnings.push(
214
+ `[W8905] Repository contains package.json files in non-root directories (e.g. ${nonRootPackageJsonFiles.slice(0, 3).join(', ')}). ` +
215
+ `Dependabot may miss updates unless the "npm" ecosystem entry uses "directories: ['**/*']" instead of "directory: '/'"`,
216
+ );
217
+ } else {
218
+ context.checks.push(
219
+ 'Dependabot npm entry uses "directories" wildcard covering non-root package.json files.',
220
+ );
221
+ }
222
+ }
223
+ }
224
+
225
+ // Check each update entry for schedule and open-pull-requests-limit issues
226
+ for (const update of updates) {
227
+ const ecosystem = update['package-ecosystem'] || '(unknown)';
228
+ const schedule = update['schedule'] || {};
229
+ const interval = schedule['interval'];
230
+
231
+ // S8906: Suggest cron instead of monthly
232
+ if (interval === 'monthly') {
233
+ context.warnings.push(
234
+ `[S8906] Dependabot entry for "${ecosystem}" uses "schedule: interval: monthly". ` +
235
+ `Consider migrating to a random cron schedule ("schedule: interval: cron") for more balanced load distribution.`,
236
+ );
237
+
238
+ // W8909: 'day' is not supported by monthly schedule
239
+ if (Object.prototype.hasOwnProperty.call(schedule, 'day')) {
240
+ context.warnings.push(
241
+ `[W8909] Dependabot entry for "${ecosystem}" uses "schedule: interval: monthly" with a "day" setting. ` +
242
+ `The "day" setting is not supported for monthly schedules and should be removed.`,
243
+ );
244
+ }
245
+ }
246
+
247
+ // W8907 / S8908: open-pull-requests-limit checks
248
+ if (Object.prototype.hasOwnProperty.call(update, 'open-pull-requests-limit')) {
249
+ const limit = update['open-pull-requests-limit'];
250
+ if (typeof limit === 'number') {
251
+ if (limit < 5) {
252
+ context.warnings.push(
253
+ `[W8907] Dependabot entry for "${ecosystem}" has "open-pull-requests-limit: ${limit}" which is very low and could cause incomplete dependency updates.`,
254
+ );
255
+ } else if (limit < 10) {
256
+ context.warnings.push(
257
+ `[S8908] Dependabot entry for "${ecosystem}" has "open-pull-requests-limit: ${limit}". A limit of at least 15 is recommended.`,
258
+ );
259
+ }
260
+ }
261
+ }
262
+ }
263
+
264
+ // S8910: Check if OLD automerge file (.OLD suffix) exists
265
+ if (fileExistsInList(context, OLD_AUTOMERGE_FILE_OLD)) {
266
+ context.warnings.push(
267
+ `[S8910] File "${OLD_AUTOMERGE_FILE_OLD}" was found. If it is no longer needed, consider deleting it.`,
268
+ );
269
+ }
270
+
271
+ // S8911: Check if old dependabot-auto-merge.yml exists, suggest migration to automerge-dependabot.yml
272
+ if (fileExistsInList(context, OLD_AUTOMERGE_FILE)) {
273
+ context.warnings.push(
274
+ `[S8911] File "${OLD_AUTOMERGE_FILE}" was found. Consider migrating to the new standard workflow "automerge-dependabot.yml".`,
275
+ );
276
+ }
277
+
278
+ // Check automerge configuration
279
+ await checkAutomerge(context);
280
+
281
+ return context;
282
+ }
283
+
284
+ exports.checkDependabot = checkDependabot;
285
+
286
+ // List of error and warnings used at this module
287
+ // ----------------------------------------------
288
+
289
+ // [S8901] Dependabot configuration file ".github/dependabot.yml" not found.
290
+ // [E8902] Dependabot configuration file is not valid YAML or cannot be read.
291
+ // [E8903] No entry with "package-ecosystem: github-actions" found.
292
+ // [E8904] No entry with "package-ecosystem: npm" found.
293
+ // [W8905] Repository has non-root package.json but npm entry does not use directories wildcard.
294
+ // [S8906] Suggest cron instead of monthly schedule.
295
+ // [W8907] open-pull-requests-limit < 5 (very low).
296
+ // [S8908] open-pull-requests-limit < 10 (recommend at least 15).
297
+ // [W8909] 'day' setting not supported with monthly schedule.
298
+ // [S8910] Suggest to delete dependabot-auto-merge.yml.OLD.
299
+ // [S8911] Suggest to migrate dependabot-auto-merge.yml to automerge-dependabot.yml.
300
+ // [E8912] Automerge workflow file uses deprecated action or is invalid YAML.
301
+ // [S8913] Suggest to set up automerging.
302
+ // [S8914] Automerging is active but .github/auto-merge.yml not found.
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
- "version": "5.2.2",
2
+ "version": "5.3.0",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
- "ajv": "^8.17.1",
6
- "axios": "^1.13.4",
5
+ "ajv": "^8.18.0",
6
+ "axios": "^1.13.6",
7
7
  "compare-versions": "^6.1.1",
8
8
  "image-size": "^1.2.0",
9
9
  "js-yaml": "^4.1.1",
10
10
  "json5": "^2.2.3",
11
- "semver": "^7.7.3"
11
+ "semver": "^7.7.4"
12
12
  },
13
13
  "devDependencies": {
14
- "@alcalzone/release-script": "^5.0.0",
14
+ "@alcalzone/release-script": "^5.1.1",
15
15
  "@iobroker/eslint-config": "^2.2.0",
16
- "@tsconfig/node20": "^20.1.8",
17
- "@types/node": "^24.10.1",
16
+ "@tsconfig/node20": "^20.1.9",
17
+ "@types/node": "^24.11.0",
18
18
  "@types/semver": "^7.7.1"
19
19
  },
20
20
  "repository": {