github_diff_parser 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/Gemfile.lock +1 -1
- data/lib/github_diff_parser/diff.rb +10 -13
- data/lib/github_diff_parser/hunk.rb +24 -1
- data/lib/github_diff_parser/parser.rb +1 -1
- data/lib/github_diff_parser/regexes.rb +1 -1
- data/lib/github_diff_parser/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59fc3a134cc5315f7d28ff394d4aa87d367ad31265f294c8a34e604802eca1de
|
4
|
+
data.tar.gz: 8f547b86fb5495a0f8a5b4749cfa7aa034077d4056d2d5862228ebe6e75559f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3927c8a434063bf2f3f159d3e745e7553f8a3add0755b5e13f2607b3a4d4a1c2bc6dd0ebc83dac9db7137e0b197b3a26771790e3e02377e30633b9a0935d39ec
|
7
|
+
data.tar.gz: 38f190c40a078858227c3995028562245c7d2db128482de36b0a376e8fbcc6ecb057564d3bd2752c6f7e498e8c72d4ccfba239e11ccb539600ea26b081cbceaf
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## Unreleased
|
8
8
|
|
9
|
+
## [1.2.0] - 2024-9-2
|
10
|
+
### Added
|
11
|
+
- Added `GithubDiffParser::Hunk#context` which returns the context of the hunk.
|
12
|
+
In this example, it would return "def blabla"
|
13
|
+
```diff
|
14
|
+
@@ +1,6 -1,18 def blabla
|
15
|
+
```
|
16
|
+
|
17
|
+
- Added `GithubDiffParser::Hunk#previous_line_count` which returns the prevous line count in a hunk.
|
18
|
+
In this example, it would return 6.
|
19
|
+
```diff
|
20
|
+
@@ +1,6 -1,18 def blabla
|
21
|
+
```
|
22
|
+
|
23
|
+
- Added `GithubDiffParser::Hunk#new_line_count` which returns the prevous line count in a hunk.
|
24
|
+
In this example, it would return 18.
|
25
|
+
```diff
|
26
|
+
@@ +1,6 -1,18 def blabla
|
27
|
+
```
|
28
|
+
|
29
|
+
### Fixed
|
30
|
+
- `GithubDiffParser::Diff#previous_line_number_is_now` could return a wrong value
|
31
|
+
for the line number 1 in a file.
|
32
|
+
|
33
|
+
## [1.1.1] - 2024-2-21
|
34
|
+
### Fixed
|
35
|
+
- `GithubDiffParser::Diff#new_mode?` and ``GithubDiffParser::Diff#deleted_mode?` would raise
|
36
|
+
an error with this kind of diff:
|
37
|
+
|
38
|
+
```diff
|
39
|
+
diff --git a/blabla.rb b/app/my_file.rb
|
40
|
+
similarity index 100%
|
41
|
+
rename from blabla.rb
|
42
|
+
rename to app/my_file.rb
|
43
|
+
```
|
44
|
+
|
9
45
|
## [1.1.0] - 2024-2-21
|
10
46
|
### Added
|
11
47
|
- Github Diff Parser parses the permissions bits and you now have have access to various method
|
data/Gemfile.lock
CHANGED
@@ -47,8 +47,8 @@ module GithubDiffParser
|
|
47
47
|
#
|
48
48
|
# @example Representation of the previous_lino_start and new_lino_start in a Git Diff
|
49
49
|
# @@ -6,5 +6,6 @@ def test1 # => The first 6 is the previous_lino_start, the second is the new_lino_start
|
50
|
-
def add_hunk(previous_lino_start, new_lino_start)
|
51
|
-
hunks << Hunk.new(previous_lino_start, new_lino_start)
|
50
|
+
def add_hunk(previous_lino_start, new_lino_start, context)
|
51
|
+
hunks << Hunk.new(previous_lino_start, new_lino_start, context)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Add a line belonging to the previously processed Git Hunk.
|
@@ -78,7 +78,7 @@ module GithubDiffParser
|
|
78
78
|
#
|
79
79
|
# @return [Boolean]
|
80
80
|
def deleted_mode?
|
81
|
-
@mode
|
81
|
+
@mode&.operation == "deleted"
|
82
82
|
end
|
83
83
|
|
84
84
|
# Check if this Diff is set to new mode.
|
@@ -94,7 +94,7 @@ module GithubDiffParser
|
|
94
94
|
#
|
95
95
|
# @return [Boolean]
|
96
96
|
def new_mode?
|
97
|
-
@mode
|
97
|
+
@mode&.operation == "new"
|
98
98
|
end
|
99
99
|
|
100
100
|
# Check if this Diff is set to rename mode.
|
@@ -112,17 +112,17 @@ module GithubDiffParser
|
|
112
112
|
|
113
113
|
# @return [Boolean] True if this diff applies to a regular file.
|
114
114
|
def normal_file?
|
115
|
-
@mode
|
115
|
+
@mode&.bits == "100644"
|
116
116
|
end
|
117
117
|
|
118
118
|
# @return [Boolean] True if this diff applies to an executable.
|
119
119
|
def executable?
|
120
|
-
@mode
|
120
|
+
@mode&.bits == "100755"
|
121
121
|
end
|
122
122
|
|
123
123
|
# @return [Boolean] True if this diff applies to a symlink.
|
124
124
|
def symlink?
|
125
|
-
@mode
|
125
|
+
@mode&.bits == "120000"
|
126
126
|
end
|
127
127
|
|
128
128
|
# @return [String] The source of the symlink
|
@@ -140,7 +140,7 @@ module GithubDiffParser
|
|
140
140
|
#
|
141
141
|
# @return [Integer]
|
142
142
|
def previous_line_number_is_now(line_number)
|
143
|
-
return line_number
|
143
|
+
return line_number if line_unchanged?(line_number)
|
144
144
|
|
145
145
|
applicable_hunk = last_applicable_hunk_for_line(line_number)
|
146
146
|
line = applicable_hunk.find_previous_line(line_number)
|
@@ -196,16 +196,13 @@ module GithubDiffParser
|
|
196
196
|
|
197
197
|
private
|
198
198
|
|
199
|
-
# Check if a line was shifted. A line is considered shifted if its number is superior to the first hunk's start
|
200
|
-
# range.
|
201
|
-
#
|
202
199
|
# @param line_number [Integer]
|
203
200
|
#
|
204
201
|
# @return [Boolean]
|
205
|
-
def
|
202
|
+
def line_unchanged?(line_number)
|
206
203
|
first_hunk = hunks.first
|
207
204
|
|
208
|
-
line_number
|
205
|
+
line_number < first_hunk.new_file_start_line
|
209
206
|
end
|
210
207
|
|
211
208
|
# Find the last hunk that shifts the line. We need the last because we know it's the one that will shift the line
|
@@ -11,14 +11,19 @@ module GithubDiffParser
|
|
11
11
|
# @return [Integer] (see #initialize)
|
12
12
|
attr_reader :new_file_start_line
|
13
13
|
|
14
|
+
# @return [String] (see #initialize)
|
15
|
+
attr_reader :context
|
16
|
+
|
14
17
|
# @param previous_file_start_line [String] the starting line number of the hunk for the original file
|
15
18
|
# @param new_file_start_line [String] the starting line number of the hunk for the new file
|
19
|
+
# @param context [String]
|
16
20
|
#
|
17
21
|
# @example Representation of the previous_file_start_line and new_file_start_line in a Git Diff
|
18
22
|
# @@ -6,5 +6,6 @@ def test1 # => The first 6 is the previous_file_start_line the second is the new_file_start_line
|
19
|
-
def initialize(previous_file_start_line, new_file_start_line)
|
23
|
+
def initialize(previous_file_start_line, new_file_start_line, context)
|
20
24
|
@previous_file_start_line = Integer(previous_file_start_line)
|
21
25
|
@new_file_start_line = Integer(new_file_start_line)
|
26
|
+
@context = context
|
22
27
|
@lines = []
|
23
28
|
end
|
24
29
|
|
@@ -82,5 +87,23 @@ module GithubDiffParser
|
|
82
87
|
def find_current_line(line_number)
|
83
88
|
lines.find { |line| line.current_number == line_number }
|
84
89
|
end
|
90
|
+
|
91
|
+
# The number of lines in the previous version.
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# "@@ +3,4 -3,8 @@" This would return "4"
|
95
|
+
# "@@ +3 -3 @@" This would return "1"
|
96
|
+
def previous_line_count
|
97
|
+
contextual_lines.count + deletion_lines.count
|
98
|
+
end
|
99
|
+
|
100
|
+
# The number of lines in the new version.
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# "@@ +3,4 -3,8 @@" This would return "8"
|
104
|
+
# "@@ +3 -3 @@" This would return "1"
|
105
|
+
def new_line_count
|
106
|
+
contextual_lines.count + addition_lines.count
|
107
|
+
end
|
85
108
|
end
|
86
109
|
end
|
@@ -81,7 +81,7 @@ module GithubDiffParser
|
|
81
81
|
def add_hunk_to_diff(match_data)
|
82
82
|
validate_diff
|
83
83
|
|
84
|
-
@current_diff.add_hunk(match_data[:previous_lino_start], match_data[:new_lino_start])
|
84
|
+
@current_diff.add_hunk(match_data[:previous_lino_start], match_data[:new_lino_start], match_data[:context])
|
85
85
|
end
|
86
86
|
|
87
87
|
# Called when encountering a `-text` or `+text` or ` text` in the Git Diff output.
|
@@ -115,7 +115,7 @@ module GithubDiffParser
|
|
115
115
|
@@\s # Match '@@ '
|
116
116
|
-(?<previous_lino_start>\d+)(,\d+)?\s # Match '-1,11 ' or match '-1 ' and capture the '1' part
|
117
117
|
\+(?<new_lino_start>\d+)(,\d+)?\s # Match '+1,34 ' or match '+1 ' and capture the '1' part
|
118
|
-
|
118
|
+
@@\s?(?<context>.*) # Match '@@ Any text' and capture the 'Any text' part
|
119
119
|
\Z # End of line
|
120
120
|
}x
|
121
121
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_diff_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard CHIN
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02
|
11
|
+
date: 2024-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
rubygems_version: 3.5.
|
88
|
+
rubygems_version: 3.5.11
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: A Ruby Gem to parse unified git diff output.
|