-
Notifications
You must be signed in to change notification settings - Fork 1
danger-js: Add DiffForFile method with comprehensive diff parsing, use interfaces to allow mocking #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
abcb1a9 to
d9989a8
Compare
There was a problem hiding this 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
DiffForFileandDiffForFileWithRefsmethods to the Git interface for executing git diff commands - Introduce
FileDiffandDiffLinetypes 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
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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>
Summary
DiffForFilemethod to Git struct that executes git diff for a specific fileFileDiffandDiffLinetypes to represent parsed diff content