github_diff_parser 1.1.1 → 1.3.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 +29 -0
- data/Gemfile.lock +16 -18
- data/lib/github_diff_parser/diff.rb +5 -8
- 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 +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f18e9f0c51f8db6051b7abb37f64f3e5c7a99c3fb207884530255d885a883d70
|
4
|
+
data.tar.gz: 38642e3746220a8dfc3eb7664495088dee7d69164aa884436d46a39a0f75e79f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 166abca2249d6fc2c1f3b841863d1f08c5d37651ee8a9dbd84796e8401ac56d0ee5973fa5feaf9e53fce557d3efa270e418d5b046cdfa57e8f9b2d568288f87a
|
7
|
+
data.tar.gz: 7b126d8024109a587db870c35d27ac3fce0ef2563d52c8068f7e2223c13bb872397f0361693ef7a415c510548784f40546e89b3a1f2956921d12973aa370b097
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## Unreleased
|
8
8
|
|
9
|
+
## [1.3.0] - 2025-1-8
|
10
|
+
### Removed
|
11
|
+
|
12
|
+
- Remove support for Ruby 3.0. The minimum version to use this gem is Ruby 3.1.
|
13
|
+
|
14
|
+
## [1.2.0] - 2024-9-2
|
15
|
+
### Added
|
16
|
+
- Added `GithubDiffParser::Hunk#context` which returns the context of the hunk.
|
17
|
+
In this example, it would return "def blabla"
|
18
|
+
```diff
|
19
|
+
@@ +1,6 -1,18 def blabla
|
20
|
+
```
|
21
|
+
|
22
|
+
- Added `GithubDiffParser::Hunk#previous_line_count` which returns the prevous line count in a hunk.
|
23
|
+
In this example, it would return 6.
|
24
|
+
```diff
|
25
|
+
@@ +1,6 -1,18 def blabla
|
26
|
+
```
|
27
|
+
|
28
|
+
- Added `GithubDiffParser::Hunk#new_line_count` which returns the prevous line count in a hunk.
|
29
|
+
In this example, it would return 18.
|
30
|
+
```diff
|
31
|
+
@@ +1,6 -1,18 def blabla
|
32
|
+
```
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
- `GithubDiffParser::Diff#previous_line_number_is_now` could return a wrong value
|
36
|
+
for the line number 1 in a file.
|
37
|
+
|
9
38
|
## [1.1.1] - 2024-2-21
|
10
39
|
### Fixed
|
11
40
|
- `GithubDiffParser::Diff#new_mode?` and ``GithubDiffParser::Diff#deleted_mode?` would raise
|
data/Gemfile.lock
CHANGED
@@ -1,42 +1,40 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
github_diff_parser (1.
|
4
|
+
github_diff_parser (1.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
10
|
byebug (11.1.3)
|
11
|
-
json (2.
|
11
|
+
json (2.7.2)
|
12
12
|
language_server-protocol (3.17.0.3)
|
13
|
-
minitest (5.
|
14
|
-
parallel (1.
|
15
|
-
parser (3.
|
13
|
+
minitest (5.25.1)
|
14
|
+
parallel (1.26.3)
|
15
|
+
parser (3.3.4.2)
|
16
16
|
ast (~> 2.4.1)
|
17
17
|
racc
|
18
|
-
racc (1.
|
18
|
+
racc (1.8.1)
|
19
19
|
rainbow (3.1.1)
|
20
|
-
rake (13.
|
21
|
-
regexp_parser (2.
|
22
|
-
|
23
|
-
rubocop (1.53.1)
|
20
|
+
rake (13.2.1)
|
21
|
+
regexp_parser (2.9.2)
|
22
|
+
rubocop (1.66.0)
|
24
23
|
json (~> 2.3)
|
25
24
|
language_server-protocol (>= 3.17.0)
|
26
25
|
parallel (~> 1.10)
|
27
|
-
parser (>= 3.
|
26
|
+
parser (>= 3.3.0.2)
|
28
27
|
rainbow (>= 2.2.2, < 4.0)
|
29
|
-
regexp_parser (>=
|
30
|
-
|
31
|
-
rubocop-ast (>= 1.28.0, < 2.0)
|
28
|
+
regexp_parser (>= 2.4, < 3.0)
|
29
|
+
rubocop-ast (>= 1.32.1, < 2.0)
|
32
30
|
ruby-progressbar (~> 1.7)
|
33
31
|
unicode-display_width (>= 2.4.0, < 3.0)
|
34
|
-
rubocop-ast (1.
|
35
|
-
parser (>= 3.
|
36
|
-
rubocop-shopify (2.
|
32
|
+
rubocop-ast (1.32.1)
|
33
|
+
parser (>= 3.3.1.0)
|
34
|
+
rubocop-shopify (2.15.1)
|
37
35
|
rubocop (~> 1.51)
|
38
36
|
ruby-progressbar (1.13.0)
|
39
|
-
unicode-display_width (2.
|
37
|
+
unicode-display_width (2.5.0)
|
40
38
|
|
41
39
|
PLATFORMS
|
42
40
|
x86_64-darwin-20
|
@@ -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.
|
@@ -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.3.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:
|
11
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -78,14 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 3.
|
81
|
+
version: 3.1.0
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
rubygems_version: 3.5.
|
88
|
+
rubygems_version: 3.5.22
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: A Ruby Gem to parse unified git diff output.
|