Commit c96c8c8
danger-js: Add DiffForFile method with comprehensive diff parsing, use interfaces to allow mocking (#32)
* danger-js: Add DiffForFile method with comprehensive diff parsing
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
* danger-js: Convert structs to clean interfaces without suffixes
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>
* danger-js: Convert structs to clean interfaces and improve diff parsing
- 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>
* danger-js: Fix test expectations for correct line number parsing
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>
* danger-js: Update dangerfile to use new Git interface methods
* Delete .claude/settings.local.json
* danger-js: Address PR review comments - optimize performance and security
* danger-js: Address PR review comments - improve security and add gitignore
- 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
* danger: Extract chars to vars
* mr: Address comments
* Update danger-js/types_danger_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>1 parent 24f9751 commit c96c8c8
File tree
10 files changed
+743
-31
lines changed- build/ci
- cmd/danger-go/runner
- danger-js
10 files changed
+743
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
0 commit comments