Repository navigation
feat(tools): import exclude patterns as ignore rules OD-1268 - #73
manufacturist wants to merge 2 commits into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 78 |
| Duplication | 12 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
An existing ignore rule can be incorrectly classified as fully imported when its tool scope is narrower than the configuration requires. This can leave exclusions unapplied while reporting success, so the scope comparison should be corrected before merging.
Codacy also found:
- A function-length threshold issue in
src/utils/import-ignore-rules.ts. - High cyclomatic complexity in the import action handler in
src/commands/tools.ts.
Test suggestions
- Convert literal paths and glob-like patterns to the correct rule type.
- Plan global rules, tool-specific rules, grouping, ordering, and global precedence.
- Skip unknown tools and leading-slash patterns with reasons.
- Batch requests at 100 rules and preserve order and reason metadata.
- Classify successful, already-existing, and API-refused rules.
- Continue with later batches after a non-409 request failure.
- Stop processing after a 409 configuration-file conflict while still importing tools.
- Run the complete import preview followed by the real import.
-
--dry-runperforms only API dry-run checks, skips prompting, and makes no writes. - Reject
--dry-runwhen--importis absent. - Use repository-token authentication for ignore-rule imports.
- Validate global and per-tool exclusions as arrays of strings.
- Avoid ignore-rule API calls when the configuration has no exclusions.
- Sanitize patterns and API refusal messages before human-readable output.
TIP How was this review? Give us feedback
| } else if (refusal.error === "AlreadyExists") { | ||
| outcome.alreadyExists.push(rule); |
There was a problem hiding this comment.
🔴 HIGH RISK
If an existing rule covers fewer tools than the config requires, those exclusions remain missing while the import reports success. Consider listing the affected pattern and scope as not imported so the user can correct the rule.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| outcome.errors.push({ | ||
| tool: `${batch.length} ignore ${pluralize("rule", batch.length)}`, | ||
| error: errorReason(err), | ||
| status: err instanceof ApiError ? err.status : undefined, | ||
| details: [], | ||
| }); |
There was a problem hiding this comment.
🟡 MEDIUM RISK
When a batch fails, users see only the number of affected rules and cannot identify the patterns that were not imported. Consider recording each pattern in the failed batch with the failure reason.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| } | ||
| outcome.errors.push({ | ||
| tool: `${batch.length} ignore ${pluralize("rule", batch.length)}`, | ||
| error: errorReason(err), |
There was a problem hiding this comment.
🟡 MEDIUM RISK
A failed request can print terminal control sequences supplied in the API error body. Consider sanitizing the error reason before passing it to terminal output.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
…ection, re-verify token whitelist
| console.log(); | ||
| } | ||
|
|
||
| const failures = [...result.failed, ...rulesErrors]; |
There was a problem hiding this comment.
Rules that the API refuses go to outcome.refused, and only outcome.errors reaches failures. When the real request refuses rules, the CLI prints the "weren't imported" table and then "✓ Configuration imported successfully.". Two examples are an InvalidPattern such as ./src/**, and a LimitReached in a later batch that the dry run can't catch. With -y, which is how the autoconfig flow in #74 runs the import, the last line tells the caller that all rules went in. Can the refused rules count in failures, or can the success line change when refused isn't empty?
tools --importdropped the config'sexcludepatterns, so cloud analysis kept reporting files the local run skips. OD-1268excludebecomes rules for every tool, and each tool'sexcludebecomes rules for that tool. A pattern on several tools becomes one rule./go asfilerules, everything else asglob.dryRunand lists every pattern that won't be imported, with the reason. Patterns of unknown tools and with a leading/are skipped by the CLI.--dry-run(with--importonly) prints the whole preview and writes nothing.API client pinned to codacy-api 58.11.0, the first published bundle with the ignore rules operations and
dryRun.--dry-run,-y, a second run, a repository with.codacy.yaml, and a repository token