@iobroker/repochecker 5.20.13 → 5.21.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 +46 -0
- package/index.js +87 -3
- package/lib/M0000_PackageJson.js +42 -22
- package/lib/M1000_IOPackageJson.js +82 -3
- package/lib/M2000_Npm.js +4 -13
- package/lib/M3000_Testing.js +29 -6
- package/lib/M4000_Repository.js +7 -14
- package/lib/M5000_Code.js +73 -111
- package/lib/M8000_Github.js +9 -14
- package/lib/M9000_GitNpmIgnore.js +22 -10
- package/lib/common.js +129 -44
- package/lib/config.js +55 -0
- package/lib/postprocessing.js +1 -0
- package/package.json +7 -6
package/lib/M5000_Code.js
CHANGED
|
@@ -845,88 +845,9 @@ async function checkCode(context) {
|
|
|
845
845
|
}
|
|
846
846
|
}
|
|
847
847
|
|
|
848
|
-
|
|
848
|
+
// react detection has been moved to config.updateConfig(), result is stored at context.usesReact
|
|
849
849
|
if (
|
|
850
|
-
context.
|
|
851
|
-
(context.packageJson.devDependencies['@iobroker/adapter-react-v5'] ||
|
|
852
|
-
context.packageJson.devDependencies['@iobroker/gui-components'] ||
|
|
853
|
-
context.packageJson.devDependencies['react'])
|
|
854
|
-
) {
|
|
855
|
-
common.info('REACT detected at package devDependencies');
|
|
856
|
-
usesReact = true;
|
|
857
|
-
}
|
|
858
|
-
if (
|
|
859
|
-
context.packageJson.dependencies &&
|
|
860
|
-
(context.packageJson.dependencies['@iobroker/adapter-react-v5'] ||
|
|
861
|
-
context.packageJson.dependencies['@iobroker/gui-components'] ||
|
|
862
|
-
context.packageJson.dependencies['react'])
|
|
863
|
-
) {
|
|
864
|
-
common.info('REACT detected at package dependencies');
|
|
865
|
-
usesReact = true;
|
|
866
|
-
}
|
|
867
|
-
if (context['/src-admin/package.json']) {
|
|
868
|
-
const packageJson = JSON.parse(context['/src-admin/package.json']);
|
|
869
|
-
if (
|
|
870
|
-
packageJson.devDependencies &&
|
|
871
|
-
(packageJson.devDependencies['@iobroker/adapter-react-v5'] ||
|
|
872
|
-
packageJson.devDependencies['@iobroker/gui-components'])
|
|
873
|
-
) {
|
|
874
|
-
common.info('REACT detected at src-admin/package devDependencies');
|
|
875
|
-
usesReact = true;
|
|
876
|
-
}
|
|
877
|
-
if (
|
|
878
|
-
packageJson.dependencies &&
|
|
879
|
-
(packageJson.dependencies['@iobroker/adapter-react-v5'] ||
|
|
880
|
-
packageJson.dependencies['@iobroker/gui-components'])
|
|
881
|
-
) {
|
|
882
|
-
common.info('REACT detected at src-admin/package dependencies');
|
|
883
|
-
usesReact = true;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
if (context['/src-widgets/package.json']) {
|
|
887
|
-
const packageJson = JSON.parse(context['/src-widgets/package.json']);
|
|
888
|
-
if (
|
|
889
|
-
packageJson.devDependencies &&
|
|
890
|
-
(packageJson.devDependencies['@iobroker/adapter-react-v5'] ||
|
|
891
|
-
packageJson.devDependencies['@iobroker/gui-components'] ||
|
|
892
|
-
packageJson.devDependencies['react'])
|
|
893
|
-
) {
|
|
894
|
-
common.info('REACT detected at src-widgets/package devDependencies');
|
|
895
|
-
usesReact = true;
|
|
896
|
-
}
|
|
897
|
-
if (
|
|
898
|
-
packageJson.dependencies &&
|
|
899
|
-
(packageJson.dependencies['@iobroker/adapter-react-v5'] ||
|
|
900
|
-
packageJson.dependencies['@iobroker/gui-components'] ||
|
|
901
|
-
packageJson.dependencies['react'])
|
|
902
|
-
) {
|
|
903
|
-
common.info('REACT detected at src-widgets/package dependencies');
|
|
904
|
-
usesReact = true;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
if (context['/src/package.json']) {
|
|
908
|
-
//console.log('"src/package.json" exists');
|
|
909
|
-
const packageJson = JSON.parse(context['/src/package.json']);
|
|
910
|
-
if (
|
|
911
|
-
packageJson.devDependencies &&
|
|
912
|
-
(packageJson.devDependencies['@iobroker/adapter-react-v5'] ||
|
|
913
|
-
packageJson.devDependencies['@iobroker/gui-components'])
|
|
914
|
-
) {
|
|
915
|
-
// console.log('REACT detected');
|
|
916
|
-
usesReact = true;
|
|
917
|
-
}
|
|
918
|
-
if (
|
|
919
|
-
packageJson.dependencies &&
|
|
920
|
-
(packageJson.dependencies['@iobroker/adapter-react-v5'] ||
|
|
921
|
-
packageJson.dependencies['@iobroker/gui-components'])
|
|
922
|
-
) {
|
|
923
|
-
// console.log('REACT detected');
|
|
924
|
-
usesReact = true;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
if (
|
|
929
|
-
!usesReact &&
|
|
850
|
+
!context.usesReact &&
|
|
930
851
|
!context.ioPackageJson.common.noConfig &&
|
|
931
852
|
(!context.ioPackageJson.common.adminUI ||
|
|
932
853
|
(context.ioPackageJson.common.adminUI.config !== 'json' &&
|
|
@@ -1368,7 +1289,7 @@ async function checkCode(context) {
|
|
|
1368
1289
|
context.warnings.push(
|
|
1369
1290
|
'[W5020] "gulpfile.js" found in repo but "gulp" not found at devDependencies at package.json. Check whether it can be removed.',
|
|
1370
1291
|
);
|
|
1371
|
-
} else if (!usesReact) {
|
|
1292
|
+
} else if (!context.usesReact) {
|
|
1372
1293
|
// Check if @iobroker/adapter-dev is present in devDependencies
|
|
1373
1294
|
if (context.packageJson.devDependencies && context.packageJson.devDependencies['@iobroker/adapter-dev']) {
|
|
1374
1295
|
context.warnings.push(
|
|
@@ -1504,33 +1425,37 @@ async function checkCode(context) {
|
|
|
1504
1425
|
}
|
|
1505
1426
|
}
|
|
1506
1427
|
|
|
1507
|
-
// Check for outdated lib/tools.js
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
if (
|
|
1518
|
-
content
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1428
|
+
// Check for outdated lib/tools.js (also .mjs and .cjs variants)
|
|
1429
|
+
const toolsFileExtensions = ['.js', '.mjs', '.cjs'];
|
|
1430
|
+
for (const toolsExt of toolsFileExtensions) {
|
|
1431
|
+
const toolsFile = `lib/tools${toolsExt}`;
|
|
1432
|
+
if (context.filesList.includes(`/${toolsFile}`)) {
|
|
1433
|
+
// Check if lib/tools file is used anywhere in the repository
|
|
1434
|
+
let isUsed = false;
|
|
1435
|
+
|
|
1436
|
+
// Search through all loaded files for references to tools
|
|
1437
|
+
for (const fileName of Object.keys(context)) {
|
|
1438
|
+
if (fileName.startsWith('/') && typeof context[fileName] === 'string') {
|
|
1439
|
+
const content = context[fileName];
|
|
1440
|
+
// Look for various patterns that might reference lib/tools
|
|
1441
|
+
if (
|
|
1442
|
+
content.includes('lib/tools') ||
|
|
1443
|
+
content.includes('./lib/tools') ||
|
|
1444
|
+
content.includes('../lib/tools') ||
|
|
1445
|
+
content.includes('./tools') ||
|
|
1446
|
+
content.includes('../tools')
|
|
1447
|
+
) {
|
|
1448
|
+
isUsed = true;
|
|
1449
|
+
break;
|
|
1450
|
+
}
|
|
1526
1451
|
}
|
|
1527
1452
|
}
|
|
1528
|
-
}
|
|
1529
1453
|
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1454
|
+
if (!isUsed) {
|
|
1455
|
+
context.warnings.push(
|
|
1456
|
+
`[S5032] "${toolsFile}" found in repo but not used anywhere. Consider removing file.`,
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1534
1459
|
}
|
|
1535
1460
|
}
|
|
1536
1461
|
|
|
@@ -1788,6 +1713,12 @@ async function checkCode(context) {
|
|
|
1788
1713
|
// Packages known to be provided by the js-controller/system and therefore not required as dependencies
|
|
1789
1714
|
const systemProvidedPackages = new Set(['@iobroker/plugin-sentry']);
|
|
1790
1715
|
|
|
1716
|
+
// Packages provided transitively by "@iobroker/testing" (>= 5.1.1). This list is prepared by
|
|
1717
|
+
// M0000_PackageJson (stored into context.redundantTestingPackages) and only present when a
|
|
1718
|
+
// matching "@iobroker/testing" version is installed. When present these packages (e.g. sinon,
|
|
1719
|
+
// chai, mocha) do not need to be listed as (dev)dependencies, so W5042 must not be raised for them.
|
|
1720
|
+
const testingProvidedPackages = new Set(context.redundantTestingPackages || []);
|
|
1721
|
+
|
|
1791
1722
|
// Extract path alias prefixes from tsconfig.json compilerOptions.paths.
|
|
1792
1723
|
// These are local path aliases (pseudo-organisations) that should be treated like local files
|
|
1793
1724
|
// and ignored during dependency checks (e.g. "@backend" from "@backend/*": ["src/*"]).
|
|
@@ -1866,10 +1797,36 @@ async function checkCode(context) {
|
|
|
1866
1797
|
}
|
|
1867
1798
|
}
|
|
1868
1799
|
// Exact file base names to exclude from scanning
|
|
1869
|
-
const excludedSourceFiles = new Set(['tasks.js', 'tasks.ts', 'Gruntfile.js', 'gulpfile.js']);
|
|
1870
|
-
|
|
1871
|
-
// Exact relative file paths (without leading slash) to exclude from dependency scanning
|
|
1872
|
-
|
|
1800
|
+
const excludedSourceFiles = new Set(['tasks.js', 'tasks.mjs', 'tasks.cjs', 'tasks.ts', 'Gruntfile.js', 'gulpfile.js']);
|
|
1801
|
+
|
|
1802
|
+
// Exact relative file paths (without leading slash) to exclude from dependency scanning.
|
|
1803
|
+
// lib/tools.* is normally excluded, but if another source file imports (requires) it,
|
|
1804
|
+
// it must be scanned like any other source file.
|
|
1805
|
+
const excludedSourceRelPaths = new Set();
|
|
1806
|
+
const toolsRelPaths = ['lib/tools.js', 'lib/tools.mjs', 'lib/tools.cjs'];
|
|
1807
|
+
for (const toolsRelPath of toolsRelPaths) {
|
|
1808
|
+
let isImported = false;
|
|
1809
|
+
// Search all other loaded source files for a reference to lib/tools
|
|
1810
|
+
for (const fileName of Object.keys(context)) {
|
|
1811
|
+
if (fileName === `/${toolsRelPath}` || !fileName.startsWith('/') || typeof context[fileName] !== 'string') {
|
|
1812
|
+
continue;
|
|
1813
|
+
}
|
|
1814
|
+
const content = context[fileName];
|
|
1815
|
+
if (
|
|
1816
|
+
content.includes('lib/tools') ||
|
|
1817
|
+
content.includes('./lib/tools') ||
|
|
1818
|
+
content.includes('../lib/tools') ||
|
|
1819
|
+
content.includes('./tools') ||
|
|
1820
|
+
content.includes('../tools')
|
|
1821
|
+
) {
|
|
1822
|
+
isImported = true;
|
|
1823
|
+
break;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
if (!isImported) {
|
|
1827
|
+
excludedSourceRelPaths.add(toolsRelPath);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1873
1830
|
|
|
1874
1831
|
const packageDependencies = context.packageJson.dependencies || {};
|
|
1875
1832
|
const packageDevDependencies = context.packageJson.devDependencies || {};
|
|
@@ -2050,6 +2007,11 @@ async function checkCode(context) {
|
|
|
2050
2007
|
continue;
|
|
2051
2008
|
}
|
|
2052
2009
|
|
|
2010
|
+
// Skip packages provided transitively by "@iobroker/testing" (>= 5.1.1)
|
|
2011
|
+
if (testingProvidedPackages.has(packageName)) {
|
|
2012
|
+
continue;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2053
2015
|
// For @types/* packages, devDependencies is also acceptable
|
|
2054
2016
|
if (packageName.startsWith('@types/') && packageDevDependencies[packageName]) {
|
|
2055
2017
|
continue;
|
|
@@ -2239,7 +2201,7 @@ exports.getFilesList = getFilesList;
|
|
|
2239
2201
|
// [5036] Plugin "${plugin}" is listed at .releaseconfig.json but "${packageName}" is not installed as devDependency. Please add.
|
|
2240
2202
|
// [5037] Plugin "${pluginName}" is installed but not listed at .releaseconfig.json. Please add or remove the devDependency.
|
|
2241
2203
|
// [5031] "gulpfile.js" found in repo with @iobroker/adapter-dev. Check if gulp is still needed.
|
|
2242
|
-
// [5032] "lib/tools.js" found in repo but not used anywhere. Consider removing this outdated file.
|
|
2204
|
+
// [5032] "lib/tools.js" (also .mjs/.cjs) found in repo but not used anywhere. Consider removing this outdated file.
|
|
2243
2205
|
// [5033] method "${method}()" is deprecated and will be removed with future js-controller version. Please use "set/deleteObject()" instead.
|
|
2244
2206
|
// [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.
|
|
2245
2207
|
// [5035] Cannot parse YAML file "${fileName}": ${e.message}
|
package/lib/M8000_Github.js
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
Numbering : 8000 - 8999
|
|
7
7
|
|
|
8
8
|
*/
|
|
9
|
-
const axios = require('axios');
|
|
10
|
-
|
|
11
9
|
const issuesToWatchAsError = [
|
|
12
10
|
'IMPORTANT: Update of dependency @iobroker/adapter-core is required as soon as possible',
|
|
13
11
|
'Compatibility check and testing for node.js 24',
|
|
@@ -23,20 +21,13 @@ const issuesToWatchAsWarning = [
|
|
|
23
21
|
'Compatibility check and testing for node.js 26',
|
|
24
22
|
];
|
|
25
23
|
|
|
26
|
-
// disable axios caching
|
|
27
|
-
// axios.defaults.headers.common = {
|
|
28
|
-
// 'Cache-Control': 'no-cache',
|
|
29
|
-
// Pragma: 'no-cache',
|
|
30
|
-
// Expires: '0',
|
|
31
|
-
// };
|
|
32
|
-
|
|
33
24
|
const common = require('./common.js');
|
|
34
25
|
const M8900__Dependabot = require('./M8900__Dependabot.js');
|
|
35
26
|
|
|
36
27
|
async function getAllIssues(context) {
|
|
37
28
|
// console.log('\ngetAllIssues');
|
|
38
29
|
// console.log(`${context.githubUrlApi}/issues`);
|
|
39
|
-
const response = await axios(`${context.githubUrlApi}/issues`, {});
|
|
30
|
+
const response = await context.axios(`${context.githubUrlApi}/issues`, {});
|
|
40
31
|
return response.data;
|
|
41
32
|
}
|
|
42
33
|
|
|
@@ -49,9 +40,10 @@ async function getCommitInfos(context) {
|
|
|
49
40
|
const url = `${context.githubUrlApi}/commits/${context.branch}`;
|
|
50
41
|
try {
|
|
51
42
|
common.debug(`reading github commits from ${url}`);
|
|
52
|
-
response = await axios(url);
|
|
43
|
+
response = await context.axios(url);
|
|
53
44
|
} catch (e) {
|
|
54
|
-
common.
|
|
45
|
+
const message = common.getResponseMessage(e);
|
|
46
|
+
common.error(`error downloading commit info from ${url} - ${e}${message ? ` - ${message}` : ''}`);
|
|
55
47
|
throw e;
|
|
56
48
|
}
|
|
57
49
|
|
|
@@ -96,10 +88,13 @@ async function checkGithubRepo(context) {
|
|
|
96
88
|
|
|
97
89
|
let releases = [];
|
|
98
90
|
try {
|
|
99
|
-
const releasesResponse = await axios(`${context.githubUrlApi}/releases?per_page=20`);
|
|
91
|
+
const releasesResponse = await context.axios(`${context.githubUrlApi}/releases?per_page=20`);
|
|
100
92
|
releases = Array.isArray(releasesResponse.data) ? releasesResponse.data : [];
|
|
101
93
|
} catch (e) {
|
|
102
|
-
|
|
94
|
+
const message = common.getResponseMessage(e);
|
|
95
|
+
common.error(
|
|
96
|
+
`error downloading release info from ${context.githubUrlApi}/releases - ${e}${message ? ` - ${message}` : ''}`,
|
|
97
|
+
);
|
|
103
98
|
}
|
|
104
99
|
|
|
105
100
|
if (!releases.length) {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
- conversion of github to regex is wrong with multiple stars
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const common = require('./common.js');
|
|
18
18
|
const { minimatch } = require('minimatch');
|
|
19
19
|
|
|
20
20
|
// Source directories (or directory paths) whose i18n subdirectories are excluded from npm packaging
|
|
@@ -25,6 +25,7 @@ const { minimatch } = require('minimatch');
|
|
|
25
25
|
const SRC_DIRS_TO_IGNORE = [
|
|
26
26
|
'src',
|
|
27
27
|
'src-admin',
|
|
28
|
+
'src-devices', // lgtv
|
|
28
29
|
'src-editor', // java-script adapter
|
|
29
30
|
'src-rules',
|
|
30
31
|
'src-tab',
|
|
@@ -360,17 +361,28 @@ async function checkGitIgnore(context) {
|
|
|
360
361
|
);
|
|
361
362
|
}
|
|
362
363
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
// E9007/W9008 flag files that are BOTH tracked by git AND excluded by
|
|
365
|
+
// .gitignore. This can only be decided from the repository's committed
|
|
366
|
+
// file list. In remote mode `context.filesList` is exactly that (fetched
|
|
367
|
+
// from jsdelivr / the GitHub tree). In `--local` mode, however, it is a
|
|
368
|
+
// plain filesystem walk (`getAllFiles` in M5000_Code.js) that also
|
|
369
|
+
// contains build outputs and other gitignored-but-untracked files that
|
|
370
|
+
// merely exist on disk — so a match there is NOT proof of git-tracking
|
|
371
|
+
// and produces false positives (e.g. admin/custom, src-admin/build). Run
|
|
372
|
+
// this check only in remote mode, where the file list is authoritative.
|
|
373
|
+
if (!common.isLocal()) {
|
|
374
|
+
for (const entry of findIgnoredTrackedEntries(trackedEntries, rules)) {
|
|
375
|
+
if (entry.path === '/build' && entry.isDirectory) {
|
|
376
|
+
context.errors.push(
|
|
377
|
+
'[E9007] build directory is tracked but excluded by .gitignore. Either remove the tracked /build directory from git (if generated) or remove the ignore rule (if intentionally tracked).',
|
|
378
|
+
);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
context.warnings.push(
|
|
383
|
+
`[W9008] ${entry.isDirectory ? 'directory' : 'file'} ${entry.path.replace(/^\//, '')} is tracked but covered by .gitignore. Remove from git if generated, or remove the ignore rule if intentionally tracked.`,
|
|
367
384
|
);
|
|
368
|
-
continue;
|
|
369
385
|
}
|
|
370
|
-
|
|
371
|
-
context.warnings.push(
|
|
372
|
-
`[W9008] ${entry.isDirectory ? 'directory' : 'file'} ${entry.path.replace(/^\//, '')} is tracked but covered by .gitignore. Remove from git if generated, or remove the ignore rule if intentionally tracked.`,
|
|
373
|
-
);
|
|
374
386
|
}
|
|
375
387
|
}
|
|
376
388
|
|
package/lib/common.js
CHANGED
|
@@ -11,6 +11,14 @@ const semverValid = require('semver/functions/valid');
|
|
|
11
11
|
const githubToken = process.env.OWN_GITHUB_TOKEN;
|
|
12
12
|
const redactedValue = '***REDACTED***';
|
|
13
13
|
|
|
14
|
+
// Private axios instance used within this module. Created by initAxios().
|
|
15
|
+
// We deliberately avoid a global axios instance so that request specific
|
|
16
|
+
// configuration (e.g. an individual github token) does not leak between requests.
|
|
17
|
+
let axiosInstance = null;
|
|
18
|
+
|
|
19
|
+
// The github token actually used for authorization. Kept for redaction of log output.
|
|
20
|
+
let effectiveGithubToken = githubToken;
|
|
21
|
+
|
|
14
22
|
let gDebug = false;
|
|
15
23
|
let gInfo = true;
|
|
16
24
|
let gSuccess = false;
|
|
@@ -36,47 +44,85 @@ const githubHostnames = new Set([
|
|
|
36
44
|
const filesListCache = new Map();
|
|
37
45
|
const fileCache = new Map();
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
'
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
/*
|
|
48
|
+
Masks a token for logging: keeps the first 4 and last 4 characters and
|
|
49
|
+
replaces everything in between with '*'. Short tokens are masked completely.
|
|
50
|
+
*/
|
|
51
|
+
function maskToken(token) {
|
|
52
|
+
if (typeof token !== 'string' || !token) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
if (token.length <= 10) {
|
|
56
|
+
return '*'.repeat(token.length);
|
|
57
|
+
}
|
|
58
|
+
return `${token.slice(0, 4)}${'*'.repeat(token.length - 8)}${token.slice(-4)}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
Creates the private axios instance used within this module and stores it at
|
|
63
|
+
context.axios so that all other modules can use the same configured instance.
|
|
64
|
+
|
|
65
|
+
The github token used for authorization is taken from context.githubToken if
|
|
66
|
+
present and non blank, otherwise the OWN_GITHUB_TOKEN environment variable is
|
|
67
|
+
used (as before).
|
|
68
|
+
*/
|
|
69
|
+
function initAxios(context) {
|
|
70
|
+
const instance = axios.create();
|
|
71
|
+
|
|
72
|
+
// disable axios caching
|
|
73
|
+
instance.defaults.headers.common = {
|
|
74
|
+
'Cache-Control': 'no-cache',
|
|
75
|
+
Pragma: 'no-cache',
|
|
76
|
+
Expires: '0',
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// determine which github token to use
|
|
80
|
+
const contextToken = context && typeof context.githubToken === 'string' ? context.githubToken.trim() : '';
|
|
81
|
+
const token = contextToken || githubToken;
|
|
82
|
+
effectiveGithubToken = token;
|
|
83
|
+
|
|
84
|
+
if (token) {
|
|
85
|
+
info(
|
|
86
|
+
contextToken
|
|
87
|
+
? `using authorization defined by context.githubToken for github URLs (${maskToken(token)})`
|
|
88
|
+
: `using authorization defined by OWN_GITHUB_TOKEN for github URLs (${maskToken(token)})`,
|
|
89
|
+
);
|
|
90
|
+
const githubAuthorization = `Bearer ${token}`;
|
|
91
|
+
instance.interceptors.request.use(
|
|
92
|
+
request => {
|
|
93
|
+
let parsedUrl;
|
|
94
|
+
try {
|
|
95
|
+
if (request?.url) {
|
|
96
|
+
parsedUrl = new URL(request.url, request.baseURL || undefined);
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
parsedUrl = undefined;
|
|
56
100
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
101
|
+
const hostname = parsedUrl?.hostname?.toLowerCase();
|
|
102
|
+
const isGitHubUrl = !!hostname && githubHostnames.has(hostname);
|
|
103
|
+
// console.log('axios access:');
|
|
104
|
+
// console.log(` request-url: ${request.url}`);
|
|
105
|
+
// console.log(` parsed-url : ${parsedUrl}`);
|
|
106
|
+
// console.log(` isGitHubUrl: ${isGitHubUrl}`);
|
|
107
|
+
if (isGitHubUrl) {
|
|
108
|
+
request.headers = request.headers || {};
|
|
109
|
+
request.headers.Authorization = githubAuthorization;
|
|
110
|
+
}
|
|
111
|
+
return request;
|
|
112
|
+
},
|
|
113
|
+
error => Promise.reject(error),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
instance.interceptors.response.use(
|
|
118
|
+
response => response,
|
|
119
|
+
error => Promise.reject(redactAxiosError(error)),
|
|
73
120
|
);
|
|
74
|
-
}
|
|
75
121
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
122
|
+
axiosInstance = instance;
|
|
123
|
+
context.axios = instance;
|
|
124
|
+
return context;
|
|
125
|
+
}
|
|
80
126
|
|
|
81
127
|
// function log(msg) {
|
|
82
128
|
// console.log(`${msg}`);
|
|
@@ -119,6 +165,9 @@ function redactString(value) {
|
|
|
119
165
|
if (githubToken && result.includes(githubToken)) {
|
|
120
166
|
result = result.replaceAll(githubToken, redactedValue);
|
|
121
167
|
}
|
|
168
|
+
if (effectiveGithubToken && effectiveGithubToken !== githubToken && result.includes(effectiveGithubToken)) {
|
|
169
|
+
result = result.replaceAll(effectiveGithubToken, redactedValue);
|
|
170
|
+
}
|
|
122
171
|
return result;
|
|
123
172
|
}
|
|
124
173
|
|
|
@@ -172,6 +221,37 @@ function stringifyError(error) {
|
|
|
172
221
|
}
|
|
173
222
|
}
|
|
174
223
|
|
|
224
|
+
// Extract the textual message a server may return in the response body of a failed
|
|
225
|
+
// request (e.g. jsdelivr returns { status: 403, message: 'Package size exceeded ...' }).
|
|
226
|
+
// Returns an empty string if no such message could be determined.
|
|
227
|
+
function getResponseMessage(error) {
|
|
228
|
+
let data = error?.response?.data;
|
|
229
|
+
if (!data) {
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
// binary responses (responseType 'arraybuffer') arrive as a Buffer - decode to text
|
|
233
|
+
if (Buffer.isBuffer(data)) {
|
|
234
|
+
data = data.toString('utf8');
|
|
235
|
+
}
|
|
236
|
+
// some servers send the body as a JSON string - try to parse it
|
|
237
|
+
if (typeof data === 'string') {
|
|
238
|
+
const text = data.trim();
|
|
239
|
+
try {
|
|
240
|
+
data = JSON.parse(text);
|
|
241
|
+
} catch {
|
|
242
|
+
// not JSON - return the raw text (limit length to keep logs readable)
|
|
243
|
+
return redactString(text).slice(0, 500);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (data && typeof data === 'object') {
|
|
247
|
+
const message = data.message || data.error;
|
|
248
|
+
if (typeof message === 'string') {
|
|
249
|
+
return redactString(message);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return '';
|
|
253
|
+
}
|
|
254
|
+
|
|
175
255
|
function isDebug() {
|
|
176
256
|
return gDebug;
|
|
177
257
|
}
|
|
@@ -228,11 +308,12 @@ async function downloadURL(url, binary) {
|
|
|
228
308
|
try {
|
|
229
309
|
//const response = await axios(githubUrl + (path || ''), options);
|
|
230
310
|
// @ts-expect-error options work this way
|
|
231
|
-
const response = await
|
|
311
|
+
const response = await axiosInstance(url, options);
|
|
232
312
|
debug(`Download succeded`);
|
|
233
313
|
return response.data;
|
|
234
314
|
} catch (e) {
|
|
235
|
-
|
|
315
|
+
const message = getResponseMessage(e);
|
|
316
|
+
error(`Cannot download ${url} ${e}${message ? ` - ${message}` : ''}`);
|
|
236
317
|
return '';
|
|
237
318
|
}
|
|
238
319
|
}
|
|
@@ -281,25 +362,27 @@ async function getFilesList(context) {
|
|
|
281
362
|
debug(`Download ${url}`);
|
|
282
363
|
const filesList = [];
|
|
283
364
|
try {
|
|
284
|
-
const response = await
|
|
365
|
+
const response = await axiosInstance(url);
|
|
285
366
|
debug(`download succeded`);
|
|
286
367
|
if (response.data?.files) {
|
|
287
368
|
response.data.files.forEach(fileInfo => filesList.push(fileInfo.name));
|
|
288
369
|
}
|
|
289
370
|
} catch (e) {
|
|
290
|
-
|
|
371
|
+
const message = getResponseMessage(e);
|
|
372
|
+
error(`Cannot download ${url} ${e}${message ? ` - ${message}` : ''}`);
|
|
291
373
|
info(`will retry using github api`);
|
|
292
374
|
|
|
293
375
|
const url2 = `https://api.github.com/repos/${context.repository}/git/trees/${context.lastCommitSha}?recursive=1`;
|
|
294
376
|
debug(`Download ${url} [RETRY]`);
|
|
295
377
|
try {
|
|
296
|
-
const response = await
|
|
378
|
+
const response = await axiosInstance(url2);
|
|
297
379
|
debug(`download succeded [RETRY]`);
|
|
298
380
|
if (response.data?.tree) {
|
|
299
381
|
response.data.tree.forEach(fileInfo => filesList.push(`/${fileInfo.path}`));
|
|
300
382
|
}
|
|
301
383
|
} catch (e) {
|
|
302
|
-
|
|
384
|
+
const message = getResponseMessage(e);
|
|
385
|
+
error(`Cannot download ${url2} ${e}${message ? ` - ${message}` : ''}`);
|
|
303
386
|
throw 'Cannot download files listing.'; // ABORT
|
|
304
387
|
}
|
|
305
388
|
}
|
|
@@ -426,12 +509,14 @@ function getMinimumNodeJsVersion(versionRange) {
|
|
|
426
509
|
return minimumVersion ? minimumVersion.version : null;
|
|
427
510
|
}
|
|
428
511
|
|
|
512
|
+
exports.initAxios = initAxios;
|
|
429
513
|
exports.debug = debug;
|
|
430
514
|
exports.info = info;
|
|
431
515
|
exports.error = error;
|
|
432
516
|
exports.warn = warn;
|
|
433
517
|
exports.redactAxiosError = redactAxiosError;
|
|
434
518
|
exports.stringifyError = stringifyError;
|
|
519
|
+
exports.getResponseMessage = getResponseMessage;
|
|
435
520
|
|
|
436
521
|
exports.isDebug = isDebug;
|
|
437
522
|
exports.isInfo = isInfo;
|