-
Notifications
You must be signed in to change notification settings - Fork 14
task: filter violations to add to the report #538
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import fs from 'node:fs/promises'; | ||
| import { execSync } from 'child_process'; | ||
| import path from 'path'; | ||
|
|
||
| async function filterIpaViolations() { | ||
| try { | ||
| // Check if rule ID is provided | ||
| const ruleId = process.argv[2]; | ||
| if (!ruleId) { | ||
| console.error('Usage: node filter-ipa-violations.js <rule-id>'); | ||
| console.error('Example: node filter-ipa-violations.js xgen-IPA-102-collection-identifier-camelCase'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const outputFile = path.join(process.cwd(), `${ruleId}-violations.md`); | ||
|
|
||
| console.log(`Filtering violations for rule ID: ${ruleId}`); | ||
| console.log('Running IPA validation...'); | ||
|
|
||
| let validationOutput; | ||
| try { | ||
| // Run IPA validation and get output as JSON | ||
| execSync( | ||
| 'spectral lint --format=json -o results.json ./openapi/.raw/v2.yaml --ruleset=./tools/spectral/ipa/ipa-spectral.yaml', | ||
| { | ||
| encoding: 'utf-8', | ||
| timeout: 4000, | ||
| maxBuffer: 10 * 1024 * 1024, | ||
| } | ||
| ); | ||
| } catch (error) { | ||
| console.error('Error (expected):', error.message); | ||
| } | ||
|
|
||
| // Read the JSON output | ||
| validationOutput = await fs.readFile('results.json', 'utf-8'); | ||
| console.log('Filtering results...'); | ||
|
|
||
| // Parse the JSON output | ||
| const validationResults = JSON.parse(validationOutput); | ||
|
|
||
| // Filter results for the exact specified rule ID | ||
| const filteredResults = validationResults.filter((violation) => violation.code === ruleId); | ||
|
|
||
| // Group by source file | ||
| const groupedBySource = filteredResults.reduce((acc, violation) => { | ||
| const source = violation.source; | ||
| if (!acc[source]) { | ||
| acc[source] = []; | ||
| } | ||
| acc[source].push({ | ||
| path: violation.path, | ||
| message: violation.message, | ||
| source: violation.source, | ||
| }); | ||
| return acc; | ||
| }, {}); | ||
|
|
||
| // Generate markdown content | ||
| let markdownContent = `# ${ruleId} Violations Checklist\n\n`; | ||
| markdownContent += `Generated on: ${new Date().toLocaleString()}\n\n`; | ||
|
|
||
| Object.keys(groupedBySource).forEach((source) => { | ||
| const violations = groupedBySource[source]; | ||
|
|
||
| violations.forEach((violation) => { | ||
| markdownContent += `## ${violation.source}\n\n`; | ||
| markdownContent += `Path: \`${violation.path.join('/')}\`\n\n`; | ||
| markdownContent += `- [ ] Fixed\n\n`; | ||
| }); | ||
| }); | ||
|
|
||
| // Write the markdown file | ||
| await fs.writeFile(outputFile, markdownContent, 'utf-8'); | ||
|
|
||
| const violationCount = filteredResults.length; | ||
| console.log(`Results saved to ${outputFile}`); | ||
| console.log(`Found ${violationCount} violations to fix`); | ||
| } catch (error) { | ||
| console.error('Error:', error.message); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| filterIpaViolations(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.