diff_parser 1.0.0 → 1.1.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 +8 -8
- data/lib/diff_parser.rb +15 -0
- data/lib/diff_parser/commit.rb +4 -11
- data/lib/diff_parser/diff.rb +7 -5
- data/lib/diff_parser/diff_files_collection.rb +6 -7
- data/lib/diff_parser/file.rb +39 -6
- data/lib/diff_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDM3MjZhYmUyMmZkZTQxNDc0N2U4NWNkNGIzM2NjNWQwYTg4MTVlMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzVlNDFlNzEzNDM5MDE5Yjk0OTcyMDliNTYwZWVhM2M1ZTEyYzVhNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTdmZDQ5ODRmYmMzYzBiOWYwMmVjNzEwMjQzZGY4MjBkNWVlYzk2Y2RlYzU0
|
10
|
+
MDNlYzAwZmIzNjVhYTc5YTQ0NmFlNjBiOGUzMmZlNGVhODIwYjg1YTdiMjAw
|
11
|
+
NDI1YjM4Yzg2YzkwYzAyNjE1YWQzYmM2YWQ0MDY2NzlhOGYwMjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTRhOGVjYjYxMjkxZTkwNWJmOTVkYzU5MTNlZGVmMDEyNzdkNGU4NDNkYmY3
|
14
|
+
MDdjMzVhN2UxZDdmY2IyOGI1YzYyMjhhNTlmMWI4YmZlZWU1YzUxY2IzOGY3
|
15
|
+
NGFiNjI5YzdkMzAwMjFjMDgzOGNjNDc1OGZiNzkxMDk4NGJiMGU=
|
data/lib/diff_parser.rb
CHANGED
@@ -5,3 +5,18 @@ require 'diff_parser/diff_files_collection'
|
|
5
5
|
require 'diff_parser/raw_line'
|
6
6
|
require 'diff_parser/diff_line'
|
7
7
|
require 'diff_parser/inline_diff'
|
8
|
+
|
9
|
+
module DiffParser
|
10
|
+
mattr_accessor :max_changes_to_render
|
11
|
+
@@max_changes_to_render = 500
|
12
|
+
|
13
|
+
mattr_accessor :reduced_max_changes_to_render
|
14
|
+
@@reduced_max_changes_to_render = 10
|
15
|
+
|
16
|
+
mattr_accessor :changes_reduction_threshold
|
17
|
+
@@changes_reduction_threshold = 20
|
18
|
+
|
19
|
+
def self.setup
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
end
|
data/lib/diff_parser/commit.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# http://developer.github.com/v3/repos/commits/#get-a-single-commit
|
2
|
+
# http://developer.github.com/v3/media/#commits-commit-comparison-and-pull-requests
|
3
|
+
|
1
4
|
module DiffParser
|
2
5
|
class Commit
|
3
6
|
attr_reader :github, :repo, :sha
|
@@ -9,17 +12,7 @@ module DiffParser
|
|
9
12
|
end
|
10
13
|
|
11
14
|
def diff
|
12
|
-
DiffParser::Diff.new(
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def info
|
18
|
-
@info ||= github.commit(repo, sha)
|
19
|
-
end
|
20
|
-
|
21
|
-
def raw
|
22
|
-
@raw ||= github.commit(repo, sha, accept: 'application/vnd.github.VERSION.diff')
|
15
|
+
DiffParser::Diff.new(self)
|
23
16
|
end
|
24
17
|
end
|
25
18
|
end
|
data/lib/diff_parser/diff.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
module DiffParser
|
2
2
|
class Diff
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :raw, :info, :commit
|
4
|
+
delegate :github, :repo, :sha, to: :commit
|
4
5
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
@
|
6
|
+
def initialize(commit)
|
7
|
+
@commit = commit
|
8
|
+
@info = github.commit(commit.repo, sha)
|
9
|
+
@raw = github.commit(repo, sha, accept: 'application/vnd.github.VERSION.diff')
|
8
10
|
end
|
9
11
|
|
10
12
|
def files
|
11
|
-
DiffParser::DiffFilesCollection.new(
|
13
|
+
DiffParser::DiffFilesCollection.new(self)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -2,15 +2,14 @@ module DiffParser
|
|
2
2
|
class DiffFilesCollection
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :diff
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@diff_info = diff_info
|
7
|
+
def initialize(diff)
|
8
|
+
@diff = diff
|
10
9
|
end
|
11
10
|
|
12
11
|
def raw_lines
|
13
|
-
preprocessed_lines = DiffParser::InlineDiff.processing(
|
12
|
+
preprocessed_lines = DiffParser::InlineDiff.processing(diff.raw.lines)
|
14
13
|
preprocessed_lines.map { |line| RawLine.new(line) }
|
15
14
|
end
|
16
15
|
|
@@ -22,8 +21,8 @@ module DiffParser
|
|
22
21
|
|
23
22
|
if raw_line.info?
|
24
23
|
yield current_file if current_file
|
25
|
-
current_file = DiffParser::File.new(raw_line.full_line,
|
26
|
-
|
24
|
+
current_file = DiffParser::File.new(raw_line.full_line, diff)
|
25
|
+
elsif !current_file.folded?
|
27
26
|
current_file.push_line(raw_line, idx)
|
28
27
|
end
|
29
28
|
end
|
data/lib/diff_parser/file.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module DiffParser
|
2
2
|
class File
|
3
3
|
attr_accessor :line_old, :line_new
|
4
|
-
attr_reader :lines, :
|
4
|
+
attr_reader :lines, :path, :file_info, :diff
|
5
5
|
delegate :additions, :deletions, to: :file_info
|
6
6
|
|
7
|
-
def initialize(path,
|
7
|
+
def initialize(path, diff)
|
8
8
|
@path = preprocess_path(path)
|
9
|
+
@diff = diff
|
9
10
|
@lines = []
|
10
11
|
@line_old = 1
|
11
12
|
@line_new = 1
|
12
|
-
@
|
13
|
-
@file_info = retrieve_file_info(diff_info)
|
13
|
+
@file_info = retrieve_file_info(diff)
|
14
14
|
end
|
15
15
|
|
16
16
|
def push_line(raw_line, idx)
|
@@ -41,14 +41,47 @@ module DiffParser
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def sha
|
45
|
+
diff.sha
|
46
|
+
end
|
47
|
+
|
48
|
+
def folded?
|
49
|
+
@folded ||= if file_max_changes_exceeded?
|
50
|
+
lines << DiffLine.new('Changes not shown', 'info', nil, nil, 0, nil)
|
51
|
+
true
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
private
|
45
58
|
|
59
|
+
def max_changes_to_render
|
60
|
+
if diff.info.files.count > DiffParser.changes_reduction_threshold
|
61
|
+
DiffParser.reduced_max_changes_to_render
|
62
|
+
else
|
63
|
+
DiffParser.max_changes_to_render
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def file_max_changes_exceeded?
|
68
|
+
(file_info.additions > max_changes_to_render && added?) || (file_info.deletions > max_changes_to_render && removed?)
|
69
|
+
end
|
70
|
+
|
71
|
+
def added?
|
72
|
+
file_info.status == 'added'
|
73
|
+
end
|
74
|
+
|
75
|
+
def removed?
|
76
|
+
file_info.status == 'removed'
|
77
|
+
end
|
78
|
+
|
46
79
|
def preprocess_path(path)
|
47
80
|
path.split(' ').last[2..-1]
|
48
81
|
end
|
49
82
|
|
50
|
-
def retrieve_file_info(
|
51
|
-
|
83
|
+
def retrieve_file_info(diff)
|
84
|
+
diff.info.files.find { |f| f.filename == path }
|
52
85
|
end
|
53
86
|
end
|
54
87
|
end
|
data/lib/diff_parser/version.rb
CHANGED