Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension that the script also uses the local data for checking #323

Merged
merged 8 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions DEBUGGING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Debugging

## Local Debugging

To test the repochecker and debug into the script under vscode:

1. Clone the repository to your local machine.\
Best is that the directory is on the same level than your adapter repository.

2. run npm install in the repochecker directory.

3. switch to your adapter repository and create a new launch configuration:

```json5
{
"name": "Launch Program",
"program": "../iobroker.repochecker/index.js", // path to the repochecker repo
// args as entered on the commandline, arguments as a array
"args": ["https://github.com/klein0r/ioBroker.luftdaten","--local"],
"request": "launch",
"stopOnEntry": true,
"runtimeExecutable": "<path to node/node.exe>", //optional if needed
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
```

## Local Testing without debugging

To test the repochecker under vscode:

1. Clone the repository to your local machine.\
Best is that the directory is on the same level than your adapter repository.

2. run npm install in the repochecker directory.

3. switch to your adapter repository and enter the following commandline in a new terminal

```bash
node ..\ioBroker.repochecker\index.js https://github.com/klein0r/ioBroker.luftdaten --local
```

## Testing without installing

The following command should be entered in the root of your repository:

```bash
npx github:oweitman/iobroker.repochecker https://github.com/oweitman/ioBroker.luftdaten --local
```
282 changes: 171 additions & 111 deletions README.md

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ function makeResponse(code, data) {
}

function check(request, ctx, callback) {
// console.log('PROCESS: ' + JSON.stringify(request));
// console.log('PROCESS: ' + JSON.stringify(request));
if (!request.queryStringParameters.url) {
return callback(null, makeResponse(500, {error: 'No github URL provided'}));
return callback(null, makeResponse(500, { error: 'No github URL provided' }));
} else {
const context = {checks: [], errors: [], warnings: []};
const context = { checks: [], errors: [], warnings: [] };
let githubUrl = request.queryStringParameters.url;
const githubBranch = request.queryStringParameters.branch;

Expand Down Expand Up @@ -191,14 +191,22 @@ function getText(text, lang) {
return text;
}

common.setDebug(true); /* DEBUG*/

if (typeof module !== 'undefined' && module.parent) {
exports.handler = check;
} else {
let repoUrl = 'https://github.com/klein0r/ioBroker.luftdaten';
let repoBranch = null;

// check for local check
if (process.argv.includes('--local')) {
process.argv.splice(process.argv.indexOf('--local'), 1);
common.setLocal(true);
}

if (process.argv.includes('--debug')) {
process.argv.splice(process.argv.indexOf('--debug'), 1);
common.setDebug(true);
}
// Get url from parameters if possible
if (process.argv.length > 2) {
repoUrl = process.argv[2];
Expand Down
46 changes: 23 additions & 23 deletions lib/M000_PackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async function checkPackageJson(context) {
if (context.packageJson.dependencies) {
for (const blacklist in blacklistedDependenciesPackageJson) {
if (context.packageJson.dependencies[blacklist]) {
if (blacklistedDependenciesPackageJson[blacklist].err){
if (blacklistedDependenciesPackageJson[blacklist].err) {
context.errors.push(`[E050] ${blacklistedDependenciesPackageJson[blacklist].msg}`);
} else {
context.warnings.push(`[W051] ${blacklistedDependenciesPackageJson[blacklist].msg}`);
Expand All @@ -283,7 +283,7 @@ async function checkPackageJson(context) {
if (context.packageJson.devDependencies) {
for (const blacklist in blacklistedDevDependenciesPackageJson) {
if (context.packageJson.devDependencies[blacklist]) {
if (blacklistedDevDependenciesPackageJson[blacklist].err){
if (blacklistedDevDependenciesPackageJson[blacklist].err) {
context.errors.push(`[E052] ${blacklistedDevDependenciesPackageJson[blacklist].msg}`);
} else {
context.warnings.push(`[W053] ${blacklistedDevDependenciesPackageJson[blacklist].msg}`);
Expand Down Expand Up @@ -328,16 +328,16 @@ async function checkPackageJson(context) {
// 'engines': { 'node': '>= 18.1.2 < 19' }
const nodeVal = context.packageJson.engines.node;
const match = nodeVal.match(/^(?<cmp>[<>=~]+)?\s*(?<vers>\d+(\.\d+(\.\d+)?)?(-\w+\.\d+)?)/m);
if ( ! match ) {
if (!match) {
context.warnings.push(`[W027] Engines clause at at package.json ({'engines' : { 'node' : '${nodeVal}' } }") is not parseable.`);
} else {
common.debug( `node check: ${JSON.stringify(match.groups)}`);
if ( match.groups.cmp !== '>' && match.groups.cmp !== '>=' ) {
common.debug(`node check: ${JSON.stringify(match.groups)}`);
if (match.groups.cmp !== '>' && match.groups.cmp !== '>=') {
context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
} else {
if ( ! compareVersions.compare( match.groups.vers, requiredNodeVersion, '>=')) {
if (!compareVersions.compare(match.groups.vers, requiredNodeVersion, '>=')) {
context.errors.push(`[E029] Node.js ${requiredNodeVersion} is required as minimum, node.js ${recommendedNodeVersion} is recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
} else if ( ! compareVersions.compare( match.groups.vers, recommendedNodeVersion, '>=')) {
} else if (!compareVersions.compare(match.groups.vers, recommendedNodeVersion, '>=')) {
context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
} else {
context.checks.push(`Correct node.js version ${match.groups.vers} requested by "engines" attribute at package.json.`);
Expand All @@ -355,12 +355,12 @@ async function checkPackageJson(context) {
const requiredVersion = dependenciesPackageJson[dependency].required;
const recommendedVersion = dependenciesPackageJson[dependency].recommended;
let dependencyVersion = context.packageJson.dependencies[`${dependency}`] || '';
dependencyVersion = dependencyVersion.replace(/[\^~]/,'' );
dependencyVersion = dependencyVersion.replace(/[\^~]/, '');
if (!dependencyVersion) {
context.errors.push(`[E032] No dependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to dependencies at package.json`);
} else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
} else if (!compareVersions.compare(dependencyVersion, requiredVersion, '>=')) {
context.errors.push(`[E033] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update dependencies at package.json`);
} else if (! compareVersions.compare( dependencyVersion, recommendedVersion, '>=' )) {
} else if (!compareVersions.compare(dependencyVersion, recommendedVersion, '>=')) {
context.warnings.push(`[W034] ${dependency} ${dependencyVersion} specified. ${recommendedVersion} is recommended. Please consider updating dependencies at package.json`);
} else {
context.checks.push('dependency ${dependency} ${dependencyVersion} is ok');
Expand All @@ -376,12 +376,12 @@ async function checkPackageJson(context) {
const requiredVersion = devDependenciesPackageJson[dependency].required;
const recommendedVersion = devDependenciesPackageJson[dependency].recommended;
let dependencyVersion = context.packageJson.devDependencies[`${dependency}`] || '';
dependencyVersion = dependencyVersion.replace(/[\^~]/,'' );
dependencyVersion = dependencyVersion.replace(/[\^~]/, '');
if (!dependencyVersion) {
context.errors.push(`[E035] No devDependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to devDependencies at package.json`);
} else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
} else if (!compareVersions.compare(dependencyVersion, requiredVersion, '>=')) {
context.errors.push(`[E036] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update devDependencies at package.json`);
} else if (! compareVersions.compare( dependencyVersion, recommendedVersion, '>=' )) {
} else if (!compareVersions.compare(dependencyVersion, recommendedVersion, '>=')) {
context.warnings.push(`[W037] ${dependency} ${dependencyVersion} specified. ${recommendedVersion} is recommended. Please consider updating devDependencies at package.json`);
} else {
context.checks.push('devDependency ${dependency} ${dependencyVersion} is ok');
Expand All @@ -400,8 +400,8 @@ async function checkPackageJson(context) {
];
for (const dependency in context.packageJson.dependencies) {
if (!context.packageJson.dependencies[dependency].startsWith('^') &&
!context.packageJson.dependencies[dependency].startsWith('~') &&
!context.packageJson.dependencies[dependency].startsWith('>')
!context.packageJson.dependencies[dependency].startsWith('~') &&
!context.packageJson.dependencies[dependency].startsWith('>')
) {
if (context.packageJson.dependencies[dependency].toLowerCase().includes('github.com')) {
context.warnings.push(`[W043] dependency should not require a github version. Please change "${dependency}:${context.packageJson.dependencies[dependency]}"`);
Expand All @@ -415,8 +415,8 @@ async function checkPackageJson(context) {

for (const dependency in context.packageJson.devDependencies) {
if (!context.packageJson.devDependencies[dependency].startsWith('^') &&
!context.packageJson.devDependencies[dependency].startsWith('~') &&
!context.packageJson.devDependencies[dependency].startsWith('>')
!context.packageJson.devDependencies[dependency].startsWith('~') &&
!context.packageJson.devDependencies[dependency].startsWith('>')
) {
if (context.packageJson.devDependencies[dependency].toLowerCase().includes('github.com')) {
context.warnings.push(`[W045] devDependency should not require github versions. Please change "${dependency}:${context.packageJson.devDependencies[dependency]}"`);
Expand All @@ -437,7 +437,7 @@ async function checkPackageJson(context) {
//console.log(` check ${log}`);
tmp = tmp[element];
if (!tmp) {
//console.log(` ${log} does not exist`);
//console.log(` ${log} does not exist`);
break;
}
}
Expand All @@ -448,9 +448,9 @@ async function checkPackageJson(context) {
context.warnings.push(`[W038] ${blacklistPackageJson[blacklist].msg}`);
}
}
// else {
// console.log(`blacklist ${blacklist} no match`);
// }
// else {
// console.log(`blacklist ${blacklist} no match`);
// }
}
context.checks.push('"blacklist (package)" checked.');

Expand All @@ -462,10 +462,10 @@ async function checkPackageJson(context) {
const recommendedKeywords = ['ioBroker'];
common.debug(`package.keywords: "${context.packageJson.keywords.join(', ')}"`);
common.debug(`filtered: "${context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase()))}"`);
if (context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase())).length === 0 ) {
if (context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase())).length === 0) {
context.errors.push(`[E049] "keywords" within package.json must contain some keywords besides "${context.packageJson.keywords.join(', ')}" related to adapter`);
}
if (! recommendedKeywords.filter(keyword => context.packageJson.keywords.includes(keyword)).length > 0) {
if (!recommendedKeywords.filter(keyword => context.packageJson.keywords.includes(keyword)).length > 0) {

Check warning

Code scanning / CodeQL

Implicit operand conversion Warning

This expression will be implicitly converted from boolean to number or string.
context.warnings.push(`[W040] "keywords" within package.json should contain "${recommendedKeywords.join(', ')}"`);
}
if (forbiddenKeywords.filter(keyword => context.packageJson.keywords.map(k => k.toLowerCase()).includes(keyword)).length > 0) {
Expand Down
Loading