github_diff_parser 0.1.0 → 1.0.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/Gemfile.lock +24 -17
- data/lib/github_diff_parser/diff.rb +14 -1
- data/lib/github_diff_parser/parser.rb +12 -0
- data/lib/github_diff_parser/regexes.rb +17 -0
- data/lib/github_diff_parser/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e34f38b28e0e403ba84d95e805bd2a0f97da47d1567893f527f99835b1ce4b87
|
4
|
+
data.tar.gz: 6eba918c1307b5dd51e48e942041cfa96a0a18f1c438bfde385b88b55b6fc4b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34e0ac9ef75f79799cd3eec754e520fe828ba9408c706d6de8bf6c42a728ce79998e1c2305aec4a89f08bf760cee1e8964695e45325643d92c2f6460b42ac684
|
7
|
+
data.tar.gz: 8ec23e1cde869fe9ad809717d0b7e19290fed6edcb7fc47c4d00fc05eb20bfc2139f0f7e3dec6937810927f2e2e0bf506947b9270cf4251ea4dee8976b06fc61
|
data/Gemfile.lock
CHANGED
@@ -1,39 +1,46 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
github_diff_parser (
|
4
|
+
github_diff_parser (1.0.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
|
-
|
12
|
-
|
13
|
-
|
11
|
+
json (2.6.3)
|
12
|
+
language_server-protocol (3.17.0.3)
|
13
|
+
minitest (5.18.1)
|
14
|
+
parallel (1.23.0)
|
15
|
+
parser (3.2.2.3)
|
14
16
|
ast (~> 2.4.1)
|
17
|
+
racc
|
18
|
+
racc (1.7.1)
|
15
19
|
rainbow (3.1.1)
|
16
20
|
rake (13.0.6)
|
17
|
-
regexp_parser (2.
|
21
|
+
regexp_parser (2.8.1)
|
18
22
|
rexml (3.2.5)
|
19
|
-
rubocop (1.
|
23
|
+
rubocop (1.53.1)
|
24
|
+
json (~> 2.3)
|
25
|
+
language_server-protocol (>= 3.17.0)
|
20
26
|
parallel (~> 1.10)
|
21
|
-
parser (>= 3.
|
27
|
+
parser (>= 3.2.2.3)
|
22
28
|
rainbow (>= 2.2.2, < 4.0)
|
23
29
|
regexp_parser (>= 1.8, < 3.0)
|
24
|
-
rexml
|
25
|
-
rubocop-ast (>= 1.
|
30
|
+
rexml (>= 3.2.5, < 4.0)
|
31
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
26
32
|
ruby-progressbar (~> 1.7)
|
27
|
-
unicode-display_width (>=
|
28
|
-
rubocop-ast (1.
|
29
|
-
parser (>= 3.
|
30
|
-
rubocop-shopify (2.
|
31
|
-
rubocop (~> 1.
|
32
|
-
ruby-progressbar (1.
|
33
|
-
unicode-display_width (2.
|
33
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
34
|
+
rubocop-ast (1.29.0)
|
35
|
+
parser (>= 3.2.1.0)
|
36
|
+
rubocop-shopify (2.14.0)
|
37
|
+
rubocop (~> 1.51)
|
38
|
+
ruby-progressbar (1.13.0)
|
39
|
+
unicode-display_width (2.4.2)
|
34
40
|
|
35
41
|
PLATFORMS
|
36
42
|
x86_64-darwin-20
|
43
|
+
x86_64-darwin-22
|
37
44
|
x86_64-linux
|
38
45
|
|
39
46
|
DEPENDENCIES
|
@@ -44,4 +51,4 @@ DEPENDENCIES
|
|
44
51
|
rubocop-shopify
|
45
52
|
|
46
53
|
BUNDLED WITH
|
47
|
-
2.
|
54
|
+
2.4.14
|
@@ -11,8 +11,16 @@ module GithubDiffParser
|
|
11
11
|
# @return [Array<GithubDiffParser::Hunk>] the hunks belonging to this diff
|
12
12
|
attr_reader :hunks
|
13
13
|
|
14
|
+
# @return [String] the hash of the previous file. This is indicate in the diff
|
15
|
+
# by the line `index abc..def`. The +abc+ part is the previous_index.
|
16
|
+
attr_reader :previous_index
|
17
|
+
|
18
|
+
# @return [String] the hash of the new file. This is indicate in the diff
|
19
|
+
# by the line `index abc..def`. The +def+ part is the previous_index.
|
20
|
+
attr_reader :new_index
|
21
|
+
|
14
22
|
# @private
|
15
|
-
attr_writer :file_mode
|
23
|
+
attr_writer :file_mode, :previous_index, :new_index
|
16
24
|
|
17
25
|
# @param previous_filename [String] the original filename. Represented by "diff --git /a filename"
|
18
26
|
# @param new_filename [String] the new filename. Represented by "diff --git /b filename"
|
@@ -22,6 +30,11 @@ module GithubDiffParser
|
|
22
30
|
@hunks = []
|
23
31
|
end
|
24
32
|
|
33
|
+
# Get all the lines in this diff. Shortcut for `diff.hunks.each { |h| h.lines }`
|
34
|
+
def lines
|
35
|
+
hunks.flat_map(&:lines)
|
36
|
+
end
|
37
|
+
|
25
38
|
# Add a Git Hunk to the diff.
|
26
39
|
#
|
27
40
|
# @param previous_lino_start [String] the starting line number of the hunk for the original file
|
@@ -18,6 +18,8 @@ module GithubDiffParser
|
|
18
18
|
case line
|
19
19
|
when Regexes::DIFF_HEADER
|
20
20
|
process_new_diff(Regexp.last_match)
|
21
|
+
when Regexes::INDEX_HEADER
|
22
|
+
process_index(Regexp.last_match)
|
21
23
|
when Regexes::MODE_HEADER
|
22
24
|
process_diff_file_mode(Regexp.last_match)
|
23
25
|
when Regexes::ORIGINAL_FILE_HEADER, Regexes::NEW_FILE_HEADER
|
@@ -47,6 +49,16 @@ module GithubDiffParser
|
|
47
49
|
@current_diff = Diff.new(match_data[:previous_filename], match_data[:new_filename])
|
48
50
|
end
|
49
51
|
|
52
|
+
# Called when encountering a `index abc..def` in the Git Diff output.
|
53
|
+
#
|
54
|
+
# @param match_data [MatchData]
|
55
|
+
def process_index(match_data)
|
56
|
+
validate_diff
|
57
|
+
|
58
|
+
@current_diff.previous_index = match_data[:previous_index]
|
59
|
+
@current_diff.new_index = match_data[:new_index]
|
60
|
+
end
|
61
|
+
|
50
62
|
# Called when encountering a `new file mode 100644` or `delete file mode 100644` in the Git Diff output.
|
51
63
|
#
|
52
64
|
# @param match_data [MatchData]
|
@@ -19,6 +19,23 @@ module GithubDiffParser
|
|
19
19
|
\Z # End of line
|
20
20
|
}x
|
21
21
|
|
22
|
+
# This Regexp is used to match the sha of the previous and the file
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# diff --git a/app/my_file.rb b/app/my_file.rb
|
27
|
+
# index d3dfbe4..ac0e8b3 100644 <-- Match this line -->
|
28
|
+
# --- a/app/my_file.rb
|
29
|
+
# +++ b/app/my_file.rb
|
30
|
+
# @@ -5,6 +5,6 @@ def test1
|
31
|
+
INDEX_HEADER = %r{
|
32
|
+
\A # Start of line
|
33
|
+
index\s # Match 'index '
|
34
|
+
(?<previous_index>[a-z0-9]+) # Match and capture alphanumerical chars
|
35
|
+
.. # Match '..' literally
|
36
|
+
(?<new_index>[a-z0-9]+) # Match and captuer alphanumerical chars
|
37
|
+
}x
|
38
|
+
|
22
39
|
# This Regexp is used to match the header containing the original filename.
|
23
40
|
#
|
24
41
|
# @example Possible header on a diff.
|
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:
|
4
|
+
version: 1.0.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: 2023-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -61,13 +61,13 @@ files:
|
|
61
61
|
- lib/github_diff_parser/parser.rb
|
62
62
|
- lib/github_diff_parser/regexes.rb
|
63
63
|
- lib/github_diff_parser/version.rb
|
64
|
-
homepage: https://github.com/
|
64
|
+
homepage: https://github.com/CatanaCorp/github_diff_parser
|
65
65
|
licenses:
|
66
66
|
- MIT
|
67
67
|
metadata:
|
68
68
|
allowed_push_host: https://rubygems.org
|
69
|
-
homepage_uri: https://github.com/
|
70
|
-
source_code_uri: https://github.com/
|
69
|
+
homepage_uri: https://github.com/CatanaCorp/github_diff_parser
|
70
|
+
source_code_uri: https://github.com/CatanaCorp/github_diff_parser
|
71
71
|
rubygems_mfa_required: 'true'
|
72
72
|
post_install_message:
|
73
73
|
rdoc_options: []
|
@@ -77,14 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
77
|
requirements:
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: 3.0.0
|
81
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.4.10
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: A Ruby Gem to parse unified git diff output.
|