Skip to content

feat(tools): import exclude patterns as ignore rules OD-1268 - #73

Open
manufacturist wants to merge 2 commits into
mainfrom
feat/od-1268-import-exclude-as-ignore-rules
Open

manufacturist wants to merge 2 commits into
mainfrom
feat/od-1268-import-exclude-as-ignore-rules

Conversation

@manufacturist

Copy link
Copy Markdown
Contributor

tools --import dropped the config's exclude patterns, so cloud analysis kept reporting files the local run skips. OD-1268

  • The global exclude becomes rules for every tool, and each tool's exclude becomes rules for that tool. A pattern on several tools becomes one rule.
  • Literal paths with a / go as file rules, everything else as glob.
  • The preview checks the rules with the API's dryRun and lists every pattern that won't be imported, with the reason. Patterns of unknown tools and with a leading / are skipped by the CLI.
  • New --dry-run (with --import only) prints the whole preview and writes nothing.
  • A repository with a Codacy configuration file gets one line, and the tools are still imported.

API client pinned to codacy-api 58.11.0, the first published bundle with the ignore rules operations and dryRun.

  • Test on dev: --dry-run, -y, a second run, a repository with .codacy.yaml, and a repository token

@codacy-production

codacy-production Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 78 complexity · 12 duplication

Metric Results
Complexity 78
Duplication 12

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

⚠️ Resolve issues before merging

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-run performs only API dry-run checks, skips prompting, and makes no writes.
  • Reject --dry-run when --import is 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

Comment on lines +199 to +200
} else if (refusal.error === "AlreadyExists") {
outcome.alreadyExists.push(rule);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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.

Comment on lines +215 to +220
outcome.errors.push({
tool: `${batch.length} ignore ${pluralize("rule", batch.length)}`,
error: errorReason(err),
status: err instanceof ApiError ? err.status : undefined,
details: [],
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread src/commands/tools.ts
console.log();
}

const failures = [...result.failed, ...rulesErrors];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants