Skip to content

Centralize file path validation for issue providers#1268

Merged
pascalberger merged 4 commits intodevelopfrom
copilot/fix-975
Oct 22, 2025
Merged

Centralize file path validation for issue providers#1268
pascalberger merged 4 commits intodevelopfrom
copilot/fix-975

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 23, 2025

This PR centralizes the file path validation logic that was previously duplicated across multiple issue providers (MsBuild, TAP, and SARIF) into a single, reusable method on the BaseIssueProvider class.

Problem

The ValidateFilePath method existed in three different implementations with similar but slightly different logic:

  • MsBuild: BaseMsBuildLogFileFormat.ValidateFilePath - validated absolute paths only
  • TAP: BaseTapLogFileFormat.ValidateFilePath - handled both relative and absolute paths with auto-detection
  • SARIF: SarifIssuesProvider.ValidateFilePath - took an explicit isAbsolutePath parameter

This duplication made the codebase harder to maintain and could lead to inconsistent behavior across providers.

Solution

Added a centralized BaseIssueProvider.ValidateFilePath static method that:

  • Automatically detects if a path is relative or absolute (no need for manual detection)
  • Validates that absolute paths are within the repository using existing extension methods
  • Converts absolute paths to relative paths using the repository root
  • Preserves relative paths unchanged
  • Returns a consistent tuple format: (bool Valid, string FilePath)

All existing provider implementations now delegate to this centralized method:

protected (bool Valid, string FilePath) ValidateFilePath(string filePath, IRepositorySettings repositorySettings) =>
    BaseIssueProvider.ValidateFilePath(filePath, repositorySettings);

Benefits

  • Eliminates code duplication: Removed ~60 lines of duplicated validation logic
  • Ensures consistency: All issue providers now use identical validation behavior
  • Improves maintainability: Changes to validation logic only need to be made in one place
  • Comprehensive coverage: Added thorough tests for all validation scenarios

Testing

  • All existing tests continue to pass (no regressions)
  • Added comprehensive test coverage for the new centralized method
  • Verified functionality across MsBuild, TAP, and SARIF providers

Fixes #975.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Centralize file path validation for issue providers Centralize file path validation for issue providers Sep 24, 2025
Copilot AI requested a review from pascalberger September 24, 2025 00:23
@pascalberger pascalberger marked this pull request as ready for review October 21, 2025 20:34
@pascalberger pascalberger requested a review from a team as a code owner October 21, 2025 20:34
Copilot AI review requested due to automatic review settings October 21, 2025 20:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR consolidates duplicate file path validation logic from three issue providers (MsBuild, TAP, and SARIF) into a single static method on BaseIssueProvider, improving maintainability and ensuring consistent validation behavior across all providers.

Key Changes:

  • Added centralized BaseIssueProvider.ValidateFilePath static method with automatic path type detection and validation
  • Updated all three providers to delegate to the centralized method instead of maintaining separate implementations
  • Added comprehensive test coverage for the new validation method

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Cake.Issues/BaseIssueProvider.cs Adds new static ValidateFilePath method with automatic path detection and validation logic
src/Cake.Issues.Tests/BaseIssueProviderTests.cs Adds comprehensive test suite covering all validation scenarios including null checks, absolute/relative paths, and edge cases
src/Cake.Issues.Tap/BaseTapLogFileFormat.cs Replaces local implementation with delegation to centralized method
src/Cake.Issues.Sarif/SarifIssuesProvider.cs Removes manual path type detection logic and delegates to centralized method
src/Cake.Issues.MsBuild/BaseMsBuildLogFileFormat.cs Replaces local implementation with delegation to centralized method

Copilot AI and others added 3 commits October 22, 2025 22:48
Co-authored-by: pascalberger <2190718+pascalberger@users.noreply.github.com>
Co-authored-by: pascalberger <2190718+pascalberger@users.noreply.github.com>
@pascalberger pascalberger merged commit 6e798d7 into develop Oct 22, 2025
149 checks passed
@pascalberger pascalberger deleted the copilot/fix-975 branch October 22, 2025 22:48
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.

Centralize file path validation for issue providers

3 participants