git_diff_parser 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b9c1edf73e6e914929331d565114ba7f3514aba
4
- data.tar.gz: 07cf0a06016067f4139ddc4e1b62abb2af88e250
3
+ metadata.gz: 5a39ab2710d525d8674cad580b457c9b91f26d42
4
+ data.tar.gz: 06e5e4229ec3638bb07484ef6ca38f68e01353ab
5
5
  SHA512:
6
- metadata.gz: b18677c9b988875a4eba90a303b72c41943579367e300b7c39d6423dc092f58912cf22df02ffce849c320cd9392cd8177afb7be35c8de67a4d6aae8b483f2b82
7
- data.tar.gz: fc63c6812d623d479e6b2e73eebc35f47941f29b5c4d9c8f9bece40d7bcf90a6aa65fd0a5a230420596c1f63de57822a5ba29dea7e4fd328b9f991b59389caa7
6
+ metadata.gz: b1455c92a35925da353a218db73d6f6f88be0799c037bad628b346f6f67df2232e1ec6de01a86c0935b46d1441705de15864e2cb680577674b242418a85f4469
7
+ data.tar.gz: a270ee8fe1e9fde3241d7143b5c5e85bcdfe03a2cd0ffd0b12ba3ae568e844a34e4596e2db2c98a0a17afbf90234a7eb840b7a58615ffe8286911414a9b4458a
data/README.md CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  ## Examples
9
9
 
10
+ ### Parse entire `git diff`
11
+
10
12
  ```ruby
11
13
  diff = <<'EOL'
12
14
  diff --git a/lib/saddler/reporter/github.rb b/lib/saddler/reporter/github.rb
@@ -25,12 +27,8 @@ EOL
25
27
 
26
28
  patches = GitDiffParser.parse(diff)
27
29
  #=> [#<GitDiffParser::Patch:0x007fb313189430
28
- # @body="@@ -2,6 +2,7 @@\n require 'octokit'\n require
29
- # 'git'\n require 'saddler/reporter/github/version'\n+r
30
- # equire 'saddler/reporter/github/support'\n require 'sad
31
- # dler/reporter/github/helper'\n require 'saddler/reporte
32
- # r/github/client'\n require 'saddler/reporter/github/com
33
- # ment'\n", @file="lib/saddler/reporter/github.rb">]
30
+ # @body="@@ -2,6 +2,7 @@\n require 'octokit'\n require 'git'\n require 'saddler/reporter/github/version'\n+r (snip)",
31
+ # @file="lib/saddler/reporter/github.rb">]
34
32
 
35
33
  patches[0].file
36
34
  #=> "lib/saddler/reporter/github.rb"
@@ -42,6 +40,14 @@ patches[0].changed_lines
42
40
  # @patch_position=4>]
43
41
  ```
44
42
 
43
+
44
+ ### Parse single patch
45
+
46
+ * patch section in `git diff`.
47
+ * GitHub's [pull request file's patch](https://developer.github.com/v3/pulls/#list-pull-requests-files).
48
+ * GitHub's [commit file's patch](https://developer.github.com/v3/repos/commits/#get-a-single-commit).
49
+
50
+
45
51
  ```ruby
46
52
  diff = <<-'EOS'
47
53
  @@ -2,6 +2,7 @@ module Saddler
@@ -1,3 +1,15 @@
1
+ <a name="2.2.0"></a>
2
+ # [2.2.0](https://github.com/packsaddle/ruby-git_diff_parser/compare/v2.1.3...v2.2.0) (2015-10-01)
3
+
4
+
5
+ ### Features
6
+
7
+ * **line:** remove default, and use meaningful variable name ([3b14ae7](https://github.com/packsaddle/ruby-git_diff_parser/commit/3b14ae7))
8
+ * **parser:** add deprecated tag ([0e88b7c](https://github.com/packsaddle/ruby-git_diff_parser/commit/0e88b7c))
9
+ * **patches:** use Patches.parse instead of DiffParser.parse ([6597e6d](https://github.com/packsaddle/ruby-git_diff_parser/commit/6597e6d))
10
+
11
+
12
+
1
13
  <a name="2.1.3"></a>
2
14
  ## [2.1.3](https://github.com/packsaddle/ruby-git_diff_parser/compare/v2.1.2...v2.1.3) (2015-10-01)
3
15
 
@@ -6,11 +6,10 @@ require 'git_diff_parser/diff_parser'
6
6
 
7
7
  # Parse `git diff` into patches and lines
8
8
  module GitDiffParser
9
-
10
9
  # @param contents [String] `git diff` result.
11
10
  #
12
11
  # @return [Patches<Patch>] parsed patches and lines
13
12
  def self.parse(contents)
14
- DiffParser.parse(contents)
13
+ Patches.parse(contents)
15
14
  end
16
15
  end
@@ -1,41 +1,18 @@
1
1
  module GitDiffParser
2
2
  # Parse entire `git diff` into Patches and Patch
3
+ #
4
+ # @deprecated
3
5
  class DiffParser
4
6
  # Parse entire `git diff` into Patches and Patch
5
7
  #
8
+ # @deprecated Use {Patches.parse} instead.
9
+ #
6
10
  # @param contents [String] `git diff` result
7
11
  #
8
12
  # @return [Patches<Patch>] parsed object
9
13
  def self.parse(contents)
10
- body = false
11
- file_name = ''
12
- patch = []
13
- lines = contents.lines
14
- line_count = lines.count
15
- parsed = Patches.new
16
- lines.each_with_index do |line, count|
17
- case line.chomp
18
- when /^diff/
19
- unless patch.empty?
20
- parsed << Patch.new(patch.join("\n") + "\n", file: file_name)
21
- patch.clear
22
- file_name = ''
23
- end
24
- body = false
25
- when /^\-\-\-/
26
- when %r{^\+\+\+ b/(?<file_name>.*)}
27
- file_name = Regexp.last_match[:file_name]
28
- body = true
29
- when /^(?<body>[\ @\+\-\\].*)/
30
- patch << Regexp.last_match[:body] if body
31
- if !patch.empty? && body && line_count == count + 1
32
- parsed << Patch.new(patch.join("\n") + "\n", file: file_name)
33
- patch.clear
34
- file_name = ''
35
- end
36
- end
37
- end
38
- parsed
14
+ warn '[DEPRECATION] `DiffParser.parse` is deprecated. Please use `Patches.parse` instead.'
15
+ Patches.parse(contents)
39
16
  end
40
17
  end
41
18
  end
@@ -7,17 +7,17 @@ module GitDiffParser
7
7
  # @!attribute [r] patch_position
8
8
  # @return [Integer] line patch position
9
9
 
10
- # @param options [Hash] this is not options
11
- # @option options [Integer] :number line number (required)
12
- # @option options [String] :content content (required)
13
- # @option options [Integer] :patch_position patch position (required)
14
- def initialize(options = {})
15
- fail(ArgumentError('number is required')) unless options[:number]
16
- fail(ArgumentError('content is required')) unless options[:content]
17
- fail(ArgumentError('patch_position is required')) unless options[:patch_position]
18
- @number = options[:number]
19
- @content = options[:content]
20
- @patch_position = options[:patch_position]
10
+ # @param params [Hash] required params
11
+ # @option params [Integer] :number line number (required)
12
+ # @option params [String] :content content (required)
13
+ # @option params [Integer] :patch_position patch position (required)
14
+ def initialize(params)
15
+ fail(ArgumentError('number is required')) unless params[:number]
16
+ fail(ArgumentError('content is required')) unless params[:content]
17
+ fail(ArgumentError('patch_position is required')) unless params[:patch_position]
18
+ @number = params[:number]
19
+ @content = params[:content]
20
+ @patch_position = params[:patch_position]
21
21
  end
22
22
 
23
23
  # @return [Boolean] true if line changed
@@ -7,6 +7,41 @@ module GitDiffParser
7
7
  new(ary)
8
8
  end
9
9
 
10
+ # @param contents [String] `git diff` result
11
+ #
12
+ # @return [Patches<Patch>] parsed object
13
+ def self.parse(contents)
14
+ body = false
15
+ file_name = ''
16
+ patch = []
17
+ lines = contents.lines
18
+ line_count = lines.count
19
+ parsed = new
20
+ lines.each_with_index do |line, count|
21
+ case line.chomp
22
+ when /^diff/
23
+ unless patch.empty?
24
+ parsed << Patch.new(patch.join("\n") + "\n", file: file_name)
25
+ patch.clear
26
+ file_name = ''
27
+ end
28
+ body = false
29
+ when /^\-\-\-/
30
+ when %r{^\+\+\+ b/(?<file_name>.*)}
31
+ file_name = Regexp.last_match[:file_name]
32
+ body = true
33
+ when /^(?<body>[\ @\+\-\\].*)/
34
+ patch << Regexp.last_match[:body] if body
35
+ if !patch.empty? && body && line_count == count + 1
36
+ parsed << Patch.new(patch.join("\n") + "\n", file: file_name)
37
+ patch.clear
38
+ file_name = ''
39
+ end
40
+ end
41
+ end
42
+ parsed
43
+ end
44
+
10
45
  # @return [Patches<Patch>]
11
46
  def initialize(*args)
12
47
  super Array.new(*args)
@@ -1,3 +1,3 @@
1
1
  module GitDiffParser
2
- VERSION = '2.1.3'
2
+ VERSION = '2.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_diff_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat