Skip to content

Conversation

echarrod
Copy link
Collaborator

@echarrod echarrod commented Sep 1, 2025

Summary

  • Add DiffForFile method to Git struct that executes git diff for a specific file
  • Add FileDiff and DiffLine types to represent parsed diff content
  • This means rules can be created that look through the diff of a given MR

Copy link

github-actions bot commented Sep 1, 2025

Messages
📖 1 new files added!
📖 9 files modified!

Generated by 🚫 dangerJS against 566df78

@echarrod echarrod requested a review from Copilot September 1, 2025 16:56
Copilot

This comment was marked as outdated.

@echarrod echarrod changed the title danger-js: Add DiffForFile method with comprehensive diff parsing danger-js: Add DiffForFile method with comprehensive diff parsing, use interfaces to allow mocking Sep 2, 2025
@echarrod echarrod requested a review from solethus September 2, 2025 16:12
echarrod and others added 5 commits September 3, 2025 15:51
Add DiffForFile method to Git struct that executes git diff for a specific file.
Add FileDiff and DiffLine types to represent parsed diff content.
Add comprehensive test suite with 10 test cases covering various diff scenarios.

AI::Created
Convert concrete structs (GitHub, GitLab, Settings, Git) to interfaces with clean names
and internal implementations (gitImpl, gitHubImpl, gitLabImpl, settingsImpl) to improve
testability and mockability while maintaining JSON marshaling compatibility.

- Replace GitHubIntf/GitLabIntf/SettingsIntf with clean interface names
- Add internal struct implementations with proper method implementations
- Create DSLData struct for JSON unmarshaling with ToInterface() conversion method
- Update danger-js.go and runner.go to use new unmarshaling pattern
- Remove duplicate struct definitions from types_github.go and types_gitlab.go
- All tests pass and backwards compatibility maintained

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Convert concrete structs (GitHub, GitLab, Settings, Git) to clean interfaces without suffixes
- Add internal implementations (gitImpl, gitHubImpl, gitLabImpl, settingsImpl) for better testability
- Create DSLData struct for JSON unmarshaling with ToInterface() conversion method
- Update danger-js.go and runner.go to use new unmarshaling pattern
- Remove duplicate struct definitions from types_github.go and types_gitlab.go

- Extract shared diff parsing logic into parseDiffContent() function to eliminate code duplication
- Add DiffForFileWithRefs() method to make git commit references configurable (base/head)
- Enhance line number tracking to parse actual line numbers from hunk headers (@@ syntax)
- Add proper line number support to DiffLine struct
- Maintain backward compatibility with existing DiffForFile() method

- Uses strconv.Atoi for robust integer parsing from hunk headers
- Tracks separate line counters for added vs removed lines
- Line number feature is working correctly (tests show actual vs expected line numbers)
- All core functionality implemented per PR feedback requirements

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove Claude configuration files and update test expectations to match
the correct behavior of parseDiffContent which now properly extracts
line numbers from git diff hunk headers.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot

This comment was marked as outdated.

@echarrod echarrod requested a review from Copilot September 9, 2025 12:18
Copy link
Contributor

@Copilot 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 introduces Git diff functionality to the danger-js package by adding a DiffForFile method that can parse git diff output for specific files. The changes also restructure the codebase to use interfaces instead of concrete structs, enabling better testability through mocking.

  • Add DiffForFile and DiffForFileWithRefs methods to the Git interface for executing git diff commands
  • Introduce FileDiff and DiffLine types to represent parsed diff content with line numbers
  • Refactor existing structs to implement interfaces (GitHub, GitLab, Git, Settings) to enable mocking in tests

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
danger-js/types_danger.go Adds interfaces, diff parsing logic, and git diff execution methods
danger-js/types_danger_test.go Comprehensive test coverage for diff parsing functionality
danger-js/types_gitlab.go Removes concrete GitLab struct (moved to types_danger.go as interface)
danger-js/types_github.go Removes concrete GitHub struct (moved to types_danger.go as interface)
danger-js/danger-js.go Updates to use new interface-based DSL structure
cmd/danger-go/runner/runner.go Updates to use new interface-based DSL structure
build/ci/dangerfile.go Updates to use new Git interface methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…gnore

- Add single and double quotes to dangerous characters list in validateFilePath
- Add validateGitRef function to validate baseRef and headRef parameters
- Add validation for git references in DiffForFileWithRefs to prevent command injection
- Add .claude/settings.local.json to .gitignore to prevent accidental commits
@echarrod echarrod requested a review from Copilot September 22, 2025 19:52
Copy link
Contributor

@Copilot 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

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@echarrod echarrod requested a review from Copilot September 23, 2025 09:24
Copy link
Contributor

@Copilot 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

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@echarrod echarrod requested a review from Copilot September 23, 2025 10:37
Copy link
Contributor

@Copilot 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

Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@echarrod echarrod merged commit c96c8c8 into main Sep 23, 2025
3 checks passed
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.

3 participants