feat: add --matches-stack filter to the patterns command - #45
Merged
Conversation
Exposes the API's new `matchesStack` query param on `codacy patterns`, so a tool's code patterns can be narrowed to those that do (or don't) match the repository's detected stack. Tri-state, matching the existing `issues --false-positives`: the bare flag or `true` sends `matchesStack=true`, `false` sends `matchesStack=false`, omitting it sends nothing. Applies in bulk mode too, so `--enable-all`/`--disable-all` can be scoped to the stack. The post-update `toolPatternsOverview` call deliberately stays unfiltered — its counts describe the whole tool, not the updated subset. Required bumping the pinned API spec 57.3.9 -> 57.4.17 (`matchesStack` first ships in 57.4.14). The spec delta is purely additive, but the param is inserted mid-signature on `listRepositoryToolPatterns` (arg 12, before `sort`), so the full-positional-arg assertions in patterns.test.ts each gained a trailing `undefined`. `pattern.ts`/`issues.ts` stop at `search` (arg 9) and were unaffected. Also re-verified the repository-token whitelist as AGENTS.md requires after `update-api`: 57.4.x now declares the `ProjectTokenAuth` scheme in the spec (absent in 57.3.9), making the list machine-checkable, and it is 14 operations rather than 13 — the addition, `searchAiInventoryCategories`, is unused here. `patterns` stays fully whitelisted, so no new token guard. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 15 |
| Duplication | 2 |
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
The generated API client/spec changes for the new matchesStack parameter are not present in the supplied diff, so compatibility with the new request signature cannot be verified. This should be resolved before merging.
The required issues-command regression scenario is missing. Codacy reports the PR as up to standards, with no new issues, but coverage data is unavailable.
About this PR
- Add a regression test confirming that the
issuescommand continues using the sharedparseBooleanOptionimplementation. - Please include or otherwise verify the generated API client/spec changes required for the new
matchesStackparameter before merging.
Test suggestions
- List mode sends
matchesStack=truefor the bare flag. - List mode sends
matchesStack=truefor explicittrue. - List mode sends
matchesStack=falsefor explicitfalse. - List mode omits the parameter when the option is absent.
- The
-kalias supports the tri-state filter. - Bulk enable/disable passes the stack filter to
updateRepositoryToolPatterns. - Bulk update calls
toolPatternsOverviewwithout stack filtering. -
parseBooleanOptionhandles case-insensitive false/true and other values. - The
issuescommand continues using the extracted shared boolean parser.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. The `issues` command continues using the extracted shared boolean parser.
TIP How was this review? Give us feedback
4 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
-k, --matches-stack [value]tocodacy patterns, exposing the API's newmatchesStackquery param — narrows a tool's code patterns to those that do (or don't) match the repository's detected stack.issues --false-positives: the bare flag ortruesendsmatchesStack=true,falsesendsmatchesStack=false, omitting it sends nothing. Read explicitly rather than by truthiness, so an explicitfalsestays distinct from "not requested".--enable-all/--disable-allcan be scoped to the stack. The post-updatetoolPatternsOverviewcall deliberately stays unfiltered — its counts describe the whole tool, not the updated subset (there's a test pinning that).parseBooleanOptionmoved out ofissues.tsinto a sharedsrc/utils/options.tsand is now imported by both commands.The API bump is the risky part
matchesStackdoesn't exist in the pinned spec — it first ships in 57.4.14, and 57.4.17 is the latest published build. Sincesrc/api/client/is generated (andprepublishOnlyregenerates it), the pin inpackage.jsonhad to move.I diffed the two specs before bumping; the delta is purely additive:
deleteRepositoryApiTokens,reanalyzeCommitCoverage)matchesStackParamonlistRepositoryToolPatterns/updateRepositoryToolPatterns/toolPatternsOverviewstackTagsFilterParamonlistOrganizationRepositories...WithAnalysisOne sharp edge:
matchesStackis inserted mid-signature onlistRepositoryToolPatterns(arg 12, beforesort), not appended — so every full-positional-arg assertion inpatterns.test.tsgained a trailingundefined.pattern.tsandissues.tsstop atsearch(arg 9) and were unaffected.Repository-token whitelist re-verified
AGENTS.mdrequires this after everyupdate-api. Two findings, both recorded inSPECS/repository-tokens.md:57.4.xnow declares theProjectTokenAuthscheme in the spec (57.3.9 declared it nowhere), so the whitelist is machine-checkable — I added a verification command to the spec and confirmed it runs verbatim.searchAiInventoryCategories, which this CLI doesn't use.patternsstays fully whitelisted, so no new token guard was needed.Test plan
npm run check-types— cleannpm test— 625 passing (was 614; +7patterns, +4utils/options)npm run build— cleannpx ts-node src/index.ts patterns --helpshows-k, --matches-stack [value]codacy/codacy-cloud-cli, tooleslint9,--categories Security):--matches-stackand--matches-stack truereturn identical pattern setstrueandfalsesets are fully disjoint (0 overlap;false→ 21 patterns,true→ 100, the page cap)🤖 Generated with Claude Code