git_diff_parser 2.1.2 → 2.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2dbd2e853cc2f2a086d9d7ca049d8d08a2c4ea20
4
- data.tar.gz: 49457d76b8459a35bb7e4cd2a1ebf75c7a26648d
3
+ metadata.gz: 5b9c1edf73e6e914929331d565114ba7f3514aba
4
+ data.tar.gz: 07cf0a06016067f4139ddc4e1b62abb2af88e250
5
5
  SHA512:
6
- metadata.gz: 9e2321ec9eaa16a52fd5f6c554177ed8cd1b3a49033a058c47c48cf4d3744d29cd30b130dc35cea2be204a43ab5e810e2b938f573d614940dcb711c738055d41
7
- data.tar.gz: 3c4d956af424439d973aaed32f0884374a51bc05378d0d7015fa52c1db9dcd9d674cb7f4220b6116401288f230e41b1aa519320d4bc8c8e92353759f58e0c9fe
6
+ metadata.gz: b18677c9b988875a4eba90a303b72c41943579367e300b7c39d6423dc092f58912cf22df02ffce849c320cd9392cd8177afb7be35c8de67a4d6aae8b483f2b82
7
+ data.tar.gz: fc63c6812d623d479e6b2e73eebc35f47941f29b5c4d9c8f9bece40d7bcf90a6aa65fd0a5a230420596c1f63de57822a5ba29dea7e4fd328b9f991b59389caa7
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+ var execSync = require('child_process').execSync;
3
+ var URI = require('urijs');
4
+
5
+ var gemspec = JSON.parse(execSync('bundle exec parse-gemspec-cli git_diff_parser.gemspec'));
6
+ var homepageUrl = gemspec.homepage;
7
+ var url = new URI(homepageUrl);
8
+ var host = url.protocol() + '://' + url.authority();
9
+ var owner = url.pathname().split('/')[1];
10
+ var repository = url.pathname().split('/')[2];
11
+
12
+ module.exports = {
13
+ version: gemspec.version,
14
+ host: host,
15
+ owner: owner,
16
+ repository: repository
17
+ };
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /node_modules/
data/.rubocop.yml CHANGED
@@ -12,6 +12,3 @@ Metrics/LineLength:
12
12
  Style/FileName:
13
13
  Exclude:
14
14
  - exe/*
15
-
16
- Style/RegexpLiteral:
17
- MaxSlashes: 0
data/.travis.yml CHANGED
@@ -1,15 +1,17 @@
1
- language: ruby
1
+ language: "ruby"
2
2
  sudo: false
3
3
  rvm:
4
- - 1.9
5
- - 2.0
6
- - 2.1
7
- - 2.2
4
+ - "1.9"
5
+ - "2.0"
6
+ - "2.1"
7
+ - "2.2"
8
+ - "ruby-head"
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: "ruby-head"
8
12
  before_install:
9
- - gem update bundler
13
+ - "gem update bundler"
14
+ - "bin/setup"
10
15
  notifications:
11
16
  email:
12
17
  - ogataken@gmail.com
13
- branches:
14
- only:
15
- - master
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
  gem 'byebug' if RUBY_VERSION >= '2.0.0'
6
6
  gem 'pry'
7
+ gem 'rubocop'
8
+ gem 'yard'
9
+ gem 'parse_gemspec-cli'
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # GitDiffParser
2
2
 
3
- [![Gem Version](http://img.shields.io/gem/v/git_diff_parser.svg?style=flat)](http://badge.fury.io/rb/git_diff_parser)
4
- [![Build Status](http://img.shields.io/travis/packsaddle/ruby-git_diff_parser/master.svg?style=flat)](https://travis-ci.org/packsaddle/ruby-git_diff_parser)
3
+ [![Gem version][gem-image]][gem-url] [![Travis-CI Status][travis-image]][travis-url] [![yard docs][docs-image]][docs-url]
4
+
5
+ > Parse `git diff` into patches and lines.
5
6
 
6
- Parser for `git diff`.
7
7
 
8
8
  ## Examples
9
9
 
@@ -95,6 +95,17 @@ patch.changed_lines
95
95
  # @content="+ body = concat_body(data)\n", @patch_position=13>]
96
96
  ```
97
97
 
98
+
99
+ ## API
100
+
101
+ And more *[details][docs-url]*.
102
+
103
+
104
+ ## Changelog
105
+
106
+ [changelog.md](./changelog.md).
107
+
108
+
98
109
  ## Installation
99
110
 
100
111
  Add this line to your application's Gemfile:
@@ -111,12 +122,14 @@ Or install it yourself as:
111
122
 
112
123
  $ gem install git_diff_parser
113
124
 
125
+
114
126
  ## Development
115
127
 
116
128
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
117
129
 
118
130
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
119
131
 
132
+
120
133
  ## Contributing
121
134
 
122
135
  1. Fork it ( https://github.com/packsaddle/ruby-git_diff_parser/fork )
@@ -125,10 +138,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
125
138
  4. Push to the branch (`git push origin my-new-feature`)
126
139
  5. Create a new Pull Request
127
140
 
141
+
128
142
  ## License
143
+
129
144
  ### git_diff_parser
130
145
  Copyright (c) 2015 sanemat. [Licensed under the MIT license](./LICENSE)
131
146
 
147
+
132
148
  ### original [thoughtbot/hound](https://github.com/thoughtbot/hound)
133
149
 
134
150
  Copyright (c) 2014 thoughtbot, inc. [Licensed under the MIT license](./thoughtbot-hound/LICENSE)
@@ -136,3 +152,11 @@ Copyright (c) 2014 thoughtbot, inc. [Licensed under the MIT license](./thoughtbo
136
152
  * lib/git_diff_parser/line.rb <- app/models/line.rb
137
153
  * lib/git_diff_parser/patch.rb <- app/models/patch.rb
138
154
  * spec/git_diff_parser/patch_spec.rb <- spec/models/patch_spec.rb
155
+
156
+
157
+ [travis-url]: https://travis-ci.org/packsaddle/ruby-git_diff_parser
158
+ [travis-image]: https://img.shields.io/travis/packsaddle/ruby-git_diff_parser/master.svg?style=flat-square&label=build%20%28linux%29
159
+ [gem-url]: https://rubygems.org/gems/git_diff_parser
160
+ [gem-image]: http://img.shields.io/gem/v/git_diff_parser.svg?style=flat-square
161
+ [docs-url]: http://www.rubydoc.info/gems/git_diff_parser
162
+ [docs-image]: https://img.shields.io/badge/yard-docs-blue.svg?style=flat-square
data/Rakefile CHANGED
@@ -7,3 +7,12 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
7
7
  end
8
8
 
9
9
  task default: :spec
10
+
11
+ require 'yard'
12
+ require 'yard/rake/yardoc_task'
13
+ DOC_FILES = ['lib/**/*.rb']
14
+ DOC_OPTIONS = ['--debug', '--verbose']
15
+ YARD::Rake::YardocTask.new(:doc) do |t|
16
+ t.files = DOC_FILES
17
+ t.options = DOC_OPTIONS if Rake.application.options.trace
18
+ end
data/bin/setup CHANGED
@@ -1,7 +1,15 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
1
+ #!/usr/bin/env ruby
4
2
 
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
3
+ require 'open3'
4
+ unless ENV['CI']
5
+ out, err, status = Open3.capture3(*%w(bundle install))
6
+ $stdout.puts out
7
+ $stderr.puts err
8
+ exit status.exitstatus if !status.exitstatus.nil? && status.exitstatus != 0
9
+ end
10
+ unless ENV['CI']
11
+ out, err, status = Open3.capture3(*%w(npm install))
12
+ $stdout.puts out
13
+ $stderr.puts err
14
+ exit status.exitstatus if !status.exitstatus.nil? && status.exitstatus != 0
15
+ end
data/changelog.md ADDED
@@ -0,0 +1,4 @@
1
+ <a name="2.1.3"></a>
2
+ ## [2.1.3](https://github.com/packsaddle/ruby-git_diff_parser/compare/v2.1.2...v2.1.3) (2015-10-01)
3
+
4
+ * Improve document
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['sanemat']
10
10
  spec.email = ['o.gata.ken@gmail.com']
11
11
 
12
- spec.summary = 'Parser for `git diff`.'
13
- spec.description = 'Parse `git diff` result.'
12
+ spec.summary = 'Parse `git diff` into patches and lines.'
13
+ spec.description = 'Parse `git diff` into patches and lines.'
14
14
  spec.homepage = 'https://github.com/packsaddle/ruby-git_diff_parser'
15
15
  spec.license = 'MIT'
16
16
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  .grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 1.8'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'bundler', '>= 0'
27
+ spec.add_development_dependency 'rake', '>= 0'
28
+ spec.add_development_dependency 'rspec', '>= 0'
29
29
  end
@@ -4,7 +4,12 @@ require 'git_diff_parser/patch'
4
4
  require 'git_diff_parser/patches'
5
5
  require 'git_diff_parser/diff_parser'
6
6
 
7
+ # Parse `git diff` into patches and lines
7
8
  module GitDiffParser
9
+
10
+ # @param contents [String] `git diff` result.
11
+ #
12
+ # @return [Patches<Patch>] parsed patches and lines
8
13
  def self.parse(contents)
9
14
  DiffParser.parse(contents)
10
15
  end
@@ -1,5 +1,11 @@
1
1
  module GitDiffParser
2
+ # Parse entire `git diff` into Patches and Patch
2
3
  class DiffParser
4
+ # Parse entire `git diff` into Patches and Patch
5
+ #
6
+ # @param contents [String] `git diff` result
7
+ #
8
+ # @return [Patches<Patch>] parsed object
3
9
  def self.parse(contents)
4
10
  body = false
5
11
  file_name = ''
@@ -1,7 +1,16 @@
1
1
  module GitDiffParser
2
+ # Parsed line
2
3
  class Line
3
4
  attr_reader :number, :patch_position
5
+ # @!attribute [r] number
6
+ # @return [Integer] line number
7
+ # @!attribute [r] patch_position
8
+ # @return [Integer] line patch position
4
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)
5
14
  def initialize(options = {})
6
15
  fail(ArgumentError('number is required')) unless options[:number]
7
16
  fail(ArgumentError('content is required')) unless options[:content]
@@ -11,6 +20,7 @@ module GitDiffParser
11
20
  @patch_position = options[:patch_position]
12
21
  end
13
22
 
23
+ # @return [Boolean] true if line changed
14
24
  def changed?
15
25
  true
16
26
  end
@@ -1,17 +1,58 @@
1
1
  module GitDiffParser
2
+ # Parsed patch
2
3
  class Patch
3
4
  RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/
4
5
  MODIFIED_LINE = /^\+(?!\+|\+)/
5
6
  NOT_REMOVED_LINE = /^[^-]/
6
7
 
7
8
  attr_accessor :file, :body, :secure_hash
9
+ # @!attribute [rw] file
10
+ # @return [String, nil] file path or nil
11
+ # @!attribute [rw] body
12
+ # @return [String, nil] patch section in `git diff` or nil
13
+ # @see #initialize
14
+ # @!attribute [rw] secure_hash
15
+ # @return [String, nil] target sha1 hash or nil
8
16
 
17
+ # @param body [String] patch section in `git diff`.
18
+ # GitHub's pull request file's patch.
19
+ # GitHub's commit file's patch.
20
+ #
21
+ # <<-BODY
22
+ # @@ -11,7 +11,7 @@ def valid?
23
+ #
24
+ # def run
25
+ # api.create_pending_status(*api_params, 'Hound is working...')
26
+ # - @style_guide.check(pull_request_additions)
27
+ # + @style_guide.check(api.pull_request_files(@pull_request))
28
+ # build = repo.builds.create!(violations: @style_guide.violations)
29
+ # update_api_status(build)
30
+ # end
31
+ # @@ -19,6 +19,7 @@ def run
32
+ # private
33
+ #
34
+ # def update_api_status(build = nil)
35
+ # + # might not need this after using Rubocop and fetching individual files.
36
+ # sleep 1
37
+ # if @style_guide.violations.any?
38
+ # api.create_failure_status(*api_params, 'Hound does not approve', build_url(build))
39
+ # BODY
40
+ #
41
+ # @param options [Hash] options
42
+ # @option options [String] :file file path
43
+ # @option options [String] 'file' file path
44
+ # @option options [String] :secure_hash target sha1 hash
45
+ # @option options [String] 'secure_hash' target sha1 hash
46
+ #
47
+ # @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
48
+ # @see https://developer.github.com/v3/pulls/#list-pull-requests-files
9
49
  def initialize(body, options = {})
10
50
  @body = body || ''
11
51
  @file = options[:file] || options['file'] if options[:file] || options['file']
12
52
  @secure_hash = options[:secure_hash] || options['secure_hash'] if options[:secure_hash] || options['secure_hash']
13
53
  end
14
54
 
55
+ # @return [Array<Line>] changed lines
15
56
  def changed_lines
16
57
  line_number = 0
17
58
 
@@ -35,10 +76,14 @@ module GitDiffParser
35
76
  end
36
77
  end
37
78
 
79
+ # @return [Array<Integer>] changed line numbers
38
80
  def changed_line_numbers
39
81
  changed_lines.map(&:number)
40
82
  end
41
83
 
84
+ # @param line_number [Integer] line number
85
+ #
86
+ # @return [Integer, nil] patch position
42
87
  def find_patch_position_by_line_number(line_number)
43
88
  target = changed_lines.find { |line| line.number == line_number }
44
89
  return nil unless target
@@ -1,26 +1,37 @@
1
1
  require 'delegate'
2
2
  module GitDiffParser
3
+ # The array of patch
3
4
  class Patches < DelegateClass(Array)
5
+ # @return [Patches<Patch>]
4
6
  def self.[](*ary)
5
7
  new(ary)
6
8
  end
7
9
 
10
+ # @return [Patches<Patch>]
8
11
  def initialize(*args)
9
12
  super Array.new(*args)
10
13
  end
11
14
 
15
+ # @return [Array<String>] file path
12
16
  def files
13
17
  map(&:file)
14
18
  end
15
19
 
20
+ # @return [Array<String>] target sha1 hash
16
21
  def secure_hashes
17
22
  map(&:secure_hash)
18
23
  end
19
24
 
25
+ # @param file [String] file path
26
+ #
27
+ # @return [Patch, nil]
20
28
  def find_patch_by_file(file)
21
29
  find { |patch| patch.file == file }
22
30
  end
23
31
 
32
+ # @param secure_hash [String] target sha1 hash
33
+ #
34
+ # @return [Patch, nil]
24
35
  def find_patch_by_secure_hash(secure_hash)
25
36
  find { |patch| patch.secure_hash == secure_hash }
26
37
  end
@@ -1,3 +1,3 @@
1
1
  module GitDiffParser
2
- VERSION = '2.1.2'
2
+ VERSION = '2.1.3'
3
3
  end
data/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "devDependencies": {
3
+ "conventional-changelog": "0.4.3",
4
+ "npm-check-updates": "^2.2.3",
5
+ "urijs": "^1.16.1"
6
+ },
7
+ "scripts": {
8
+ "changelog": "conventional-changelog -i changelog.md --overwrite --preset angular --context .conventional-changelog.context.js",
9
+ "ncu": "ncu -u"
10
+ }
11
+ }
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_diff_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,13 +52,14 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Parse `git diff` result.
55
+ description: Parse `git diff` into patches and lines.
56
56
  email:
57
57
  - o.gata.ken@gmail.com
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".conventional-changelog.context.js"
62
63
  - ".gitignore"
63
64
  - ".rspec"
64
65
  - ".rubocop.yml"
@@ -71,6 +72,7 @@ files:
71
72
  - Rakefile
72
73
  - bin/console
73
74
  - bin/setup
75
+ - changelog.md
74
76
  - git_diff_parser.gemspec
75
77
  - lib/git_diff_parser.rb
76
78
  - lib/git_diff_parser/diff_parser.rb
@@ -78,6 +80,7 @@ files:
78
80
  - lib/git_diff_parser/patch.rb
79
81
  - lib/git_diff_parser/patches.rb
80
82
  - lib/git_diff_parser/version.rb
83
+ - package.json
81
84
  - thoughtbot-hound/LICENSE
82
85
  homepage: https://github.com/packsaddle/ruby-git_diff_parser
83
86
  licenses:
@@ -102,5 +105,6 @@ rubyforge_project:
102
105
  rubygems_version: 2.4.5
103
106
  signing_key:
104
107
  specification_version: 4
105
- summary: Parser for `git diff`.
108
+ summary: Parse `git diff` into patches and lines.
106
109
  test_files: []
110
+ has_rdoc: