Skip to content

feat: log warnings for conflicting custom formats#427

Closed
BlackDark wants to merge 3 commits intomainfrom
log-cf-conflicts
Closed

feat: log warnings for conflicting custom formats#427
BlackDark wants to merge 3 commits intomainfrom
log-cf-conflicts

Conversation

@BlackDark
Copy link
Copy Markdown
Member

@BlackDark BlackDark commented Apr 12, 2026

Add support for loading and checking conflicts.json from TRaSH Guides to warn users when they select mutually exclusive custom formats.

  • Add conflict types (TrashConflictEntry, TrashConflicts, TrashConflictsMapping)
  • Update TrashCache to include conflicts for both RADARR and SONARR
  • Add loadConflictsFromTrash function to load conflicts.json from TRaSH Guides
  • Add checkCustomFormatConflicts function to detect conflicts among selected CFs
  • Call conflict checking in pipeline after calculating CFs to manage

Resolves GitHub issue for TRaSH Guides conflicts.json integration

Summary by Sourcery

Integrate TRaSH Guides custom format conflict data into the cache and pipeline to warn when users select mutually exclusive custom formats.

New Features:

  • Load TRaSH Guides conflicts.json for Radarr and Sonarr and cache conflict groups alongside existing TRaSH data.
  • Detect and log warnings for conflicting custom formats selected in the pipeline based on TRaSH-defined conflicts.

Enhancements:

  • Extend TRaSH cache and type definitions to model custom format conflict groups for both Radarr and Sonarr.

Add support for loading and checking conflicts.json from TRaSH Guides to
warn users when they select mutually exclusive custom formats.

- Add conflict types (TrashConflictEntry, TrashConflicts,
  TrashConflictsMapping)
- Update TrashCache to include conflicts for both RADARR and SONARR
- Add loadConflictsFromTrash function to load conflicts.json from TRaSH
  Guides
- Add checkCustomFormatConflicts function to detect conflicts among
  selected CFs
- Call conflict checking in pipeline after calculating CFs to manage

Resolves GitHub issue for TRaSH Guides conflicts.json integration
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 12, 2026

Reviewer's Guide

Adds TRaSH Guides conflicts.json support to cache and pipeline to detect and log warnings for mutually exclusive custom formats in Radarr/Sonarr configurations.

Sequence diagram for checking custom format conflicts in the pipeline

sequenceDiagram
  actor User
  participant CLI as CLI
  participant pipeline as pipeline
  participant calculateCFsToManage as calculateCFsToManage
  participant checkCustomFormatConflicts as checkCustomFormatConflicts
  participant TrashCache as TrashCache
  participant logger as logger

  User ->> CLI: run command
  CLI ->> pipeline: pipeline(globalConfig, instanceConfig)

  pipeline ->> calculateCFsToManage: calculateCFsToManage(config)
  calculateCFsToManage -->> pipeline: idsToManage(Set<string>)

  pipeline ->> checkCustomFormatConflicts: checkCustomFormatConflicts(arrType, idsToManage)

  alt cache not ready
    checkCustomFormatConflicts ->> logger: debug ((arrType) Cache not ready. Cannot check conflicts.)
    checkCustomFormatConflicts -->> pipeline: return
  else cache ready
    checkCustomFormatConflicts ->> TrashCache: read cache[arrType].conflicts
    alt no conflicts configured
      checkCustomFormatConflicts ->> logger: debug ((arrType) No conflicts defined.)
      checkCustomFormatConflicts -->> pipeline: return
    else conflicts configured
      alt fewer than 2 CFs selected
        checkCustomFormatConflicts -->> pipeline: return
      else potential conflicts
        loop for each conflictGroup in conflicts
          checkCustomFormatConflicts ->> TrashCache: iterate conflictGroup entries
          alt more than one matching CF in group
            checkCustomFormatConflicts ->> logger: warn ((arrType) Conflicting custom formats found: names)
          end
        end
        alt no conflicts found
          checkCustomFormatConflicts ->> logger: debug ((arrType) No conflicts detected among selected custom formats.)
        end
      end
    end
  end

  pipeline -->> CLI: continue with loadCustomFormatDefinitions
Loading

Updated class diagram for TRaSH conflicts types and cache

classDiagram

  class TrashConflictEntry {
    string name
    string desc
  }

  class TrashConflicts {
    Record~string, TrashConflictEntry~[] custom_formats
  }

  class TrashConflictsMapping {
    Map~number, Record~string, TrashConflictEntry~~ mapping
  }

  class TrashQualityDefinition {
  }

  class TrashSonarrNaming {
  }

  class TrashRadarrNaming {
  }

  class TrashQP {
  }

  class TrashCF {
  }

  class TrashCFGroupMapping {
  }

  class TrashCacheSonarr {
    Map~string, TrashQP~ qualityProfiles
    Map~string, TrashCF~ customFormats
    TrashCFGroupMapping customFormatGroups
    Map~string, TrashQualityDefinition~ qualityDefinitions
    TrashSonarrNaming naming
    TrashConflictsMapping conflicts
  }

  class TrashCacheRadarr {
    Map~string, TrashQP~ qualityProfiles
    Map~string, TrashCF~ customFormats
    TrashCFGroupMapping customFormatGroups
    Map~string, TrashQualityDefinition~ qualityDefinitions
    TrashRadarrNaming naming
    TrashConflictsMapping conflicts
  }

  class TrashCache {
    TrashCacheSonarr SONARR
    TrashCacheRadarr RADARR
  }

  class TrashGuideService {
    +loadConflictsFromTrash(arrType TrashArrSupported) TrashConflictsMapping
    +checkCustomFormatConflicts(arrType TrashArrSupported, cfTrashIds Set~string~) void
  }

  TrashConflicts "1" o-- "*" TrashConflictEntry : contains
  TrashConflictsMapping "1" o-- "*" TrashConflictEntry : grouped

  TrashCache "1" o-- "1" TrashCacheSonarr : SONARR
  TrashCache "1" o-- "1" TrashCacheRadarr : RADARR

  TrashCacheSonarr "1" o-- "1" TrashConflictsMapping : conflicts
  TrashCacheRadarr "1" o-- "1" TrashConflictsMapping : conflicts

  TrashGuideService ..> TrashConflictsMapping : uses
  TrashGuideService ..> TrashCache : reads
Loading

File-Level Changes

Change Details Files
Extend Trash cache and type system to store TRaSH custom format conflict data for Radarr and Sonarr.
  • Augment TrashCache type to include a conflicts field for both SONARR and RADARR entries
  • Introduce TrashConflictEntry, TrashConflicts, and TrashConflictsMapping types to model conflicts.json structure and in-memory mapping
src/trash-guide.ts
src/types/trashguide.types.ts
Implement loading of conflicts.json from TRaSH Guides into an in-memory mapping with logging and cache integration.
  • Add trashRepoPaths entries for radarrConflicts and sonarrConflicts pointing to conflicts.json in the TRaSH repo
  • Create loadConflictsFromTrash to read conflicts.json for the requested arrType, map conflict groups into a Map, handle unsupported types, cache-not-ready cases, and log success/failure details
  • Populate SONARR.conflicts and RADARR.conflicts in createCache using loadConflictsFromTrash
src/trash-guide.ts
src/util.ts
Add runtime conflict detection for selected custom formats and integrate it into the main pipeline.
  • Implement checkCustomFormatConflicts to compare selected CF trash IDs against loaded conflict groups, logging warnings when more than one mutually exclusive format in a group is selected
  • Short-circuit conflict checking when cache is not ready, conflicts are absent, or fewer than two CFs are selected
  • Invoke checkCustomFormatConflicts in the main pipeline after calculating idsToManage and before loading custom format definitions
src/trash-guide.ts
src/index.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The TrashConflictsMapping type and the use of Map<number, ...> keyed by array index add indirection without clear benefit; consider using the custom_formats array directly (or a map keyed by a meaningful ID) to simplify loadConflictsFromTrash and iteration in checkCustomFormatConflicts.
  • In checkCustomFormatConflicts, you can return early when cfTrashIds.size < 2 before checking cacheReady and accessing cache[arrType].conflicts to avoid unnecessary cache/logging work on the common trivial case.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `TrashConflictsMapping` type and the use of `Map<number, ...>` keyed by array index add indirection without clear benefit; consider using the `custom_formats` array directly (or a map keyed by a meaningful ID) to simplify `loadConflictsFromTrash` and iteration in `checkCustomFormatConflicts`.
- In `checkCustomFormatConflicts`, you can return early when `cfTrashIds.size < 2` before checking `cacheReady` and accessing `cache[arrType].conflicts` to avoid unnecessary cache/logging work on the common trivial case.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Add unit tests for loadConflictsFromTrash and checkCustomFormatConflicts
functions to ensure conflict detection works correctly.

- Test unsupported arr types return empty map
- Test loading conflicts from conflicts.json
- Test error handling when conflicts.json does not exist
- Test handling of empty conflicts array
- Test early return for unsupported arrType
Update loadConflictsFromTrash and checkCustomFormatConflicts to
accept ArrType parameter to avoid type errors when called with
non-RADARR/SONARR types. The functions already handle this case by
returning early.

This fixes TypeScript compilation errors when using any supported
*arr type.
@BlackDark
Copy link
Copy Markdown
Member Author

Supersedes by #428

@BlackDark BlackDark closed this Apr 12, 2026
@BlackDark BlackDark deleted the log-cf-conflicts branch April 12, 2026 12:05
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.

1 participant