Skip to content

Commit f52313c

Browse files
fix: config in a separate file
1 parent dc56c6a commit f52313c

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121

2222
*.out
2323
**/*ipa-collector-results-combined.log
24+
**/*metric-collection-results.json
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import path from 'path';
2+
import { fileURLToPath } from 'url';
3+
4+
const dirname = path.dirname(fileURLToPath(import.meta.url));
5+
const rootDir = path.resolve(dirname, '../../../../');
6+
7+
const config = {
8+
defaultOasFilePath: path.join(rootDir, 'openapi', 'v2.json'),
9+
defaultCollectorResultsFilePath: path.join(dirname, '..', 'ipa-collector-results-combined.log'),
10+
defaultRulesetFilePath: path.join(dirname, '..', 'ipa-spectral.yaml'),
11+
defaultMetricCollectionResultsFilePath: path.join(dirname, 'metric-collection-results.json'),
12+
};
13+
14+
export default config;

tools/spectral/ipa/metrics/metricCollection.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,20 @@ import {
1010
getSeverityPerRule,
1111
merge,
1212
} from './utils.js';
13+
import config from './config.js';
1314
const { Spectral } = spectral;
1415

15-
//TBD
16-
const oasFile = '../../../../openapi/v2.json';
17-
const dirname = path.dirname(fileURLToPath(import.meta.url));
18-
const collectorResultsFile = path.join(dirname, '../ipa-collector-results-combined.log');
19-
20-
async function runMetricCollectionJob() {
16+
async function runMetricCollectionJob(oasFilePath = config.defaultOasFilePath) {
2117
try {
22-
console.log('Loading OpenAPI file...');
23-
const oasContent = loadOpenAPIFile(oasFile);
18+
console.log(`Loading OpenAPI file: ${oasFilePath}`);
19+
const oasContent = loadOpenAPIFile(oasFilePath);
2420

2521
console.log('Extracting team ownership data...');
2622
const ownershipData = extractTeamOwnership(oasContent);
2723

2824
console.log('Initializing Spectral...');
2925
const spectral = new Spectral();
30-
const rulesetPath = path.join(dirname, '../ipa-spectral.yaml');
31-
const ruleset = await loadRuleset(rulesetPath, spectral);
26+
const ruleset = await loadRuleset(config.defaultRulesetFilePath, spectral);
3227

3328
console.log('Getting rule severities...');
3429
const ruleSeverityMap = getSeverityPerRule(ruleset);
@@ -37,7 +32,7 @@ async function runMetricCollectionJob() {
3732
const spectralResults = await spectral.run(oasContent);
3833

3934
console.log('Loading collector results...');
40-
const collectorResults = loadCollectorResults(collectorResultsFile);
35+
const collectorResults = loadCollectorResults(config.defaultCollectorResultsFilePath);
4136

4237
console.log('Merging results...');
4338
const mergedResults = merge(spectralResults, ownershipData, collectorResults, ruleSeverityMap);
@@ -50,6 +45,9 @@ async function runMetricCollectionJob() {
5045
}
5146
}
5247

53-
runMetricCollectionJob()
54-
.then((results) => fs.writeFileSync('results.log', JSON.stringify(results)))
48+
const args = process.argv.slice(2);
49+
const customOasFile = args[0];
50+
51+
runMetricCollectionJob(customOasFile)
52+
.then((results) => fs.writeFileSync(config.defaultMetricCollectionResultsFilePath, JSON.stringify(results)))
5553
.catch((error) => console.error(error.message));

0 commit comments

Comments
 (0)