checkstyle_filter-git 0.1.1 → 1.0.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: ca6d69dfc71484d7250c9784f38db85977aee9c8
4
- data.tar.gz: 0be05f771642be3c26b954bd9980da454120932d
3
+ metadata.gz: eefefc30a709cd108ff7af5fc8665bdb3e233697
4
+ data.tar.gz: 86fd8708b347ac2331d691ec9974fcbbaf589984
5
5
  SHA512:
6
- metadata.gz: 325f170d3e5f6e3eb7452dcf4acb19f5dbcb8e0666e4fd2d3254b33a8d0084da230956fb88a40391ecd1fea835db03d17d39cd89d2163622ba36f6cfaa528a64
7
- data.tar.gz: 547481f001ce67eab29bba5c81c63e5bd588708c239e76a352178b3b3ff062af9abefc8dad2936b3c3a3b84f75a4428225bde83a1833b17f4c57efe03bafea81
6
+ metadata.gz: 3b44da9604d392b41a91dd785e934ff6cc930a463309ec6ce86d4a30cd0bc51ce4709ddfd355f523ad46b7d9373d51c0f5da03656b1d4ea79df3485776cbf4f0
7
+ data.tar.gz: a73d4e34ff10f4e955cce90609c9dc1af28853ae135c5e262483c0d41eebc2688d4c90e9279542e316e15b13144155dc821dea36d656ba0f2c25cdb9e2fd4be7
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'byebug' if RUBY_VERSION >= '2.0.0'
7
+ gem 'pry'
data/README.md CHANGED
@@ -98,7 +98,7 @@ git diff -z --name-only origin/master.. \
98
98
  --require rubocop/formatter/checkstyle_formatter \
99
99
  --format RuboCop::Formatter::CheckstyleFormatter \
100
100
  | checkstyle_filter-git diff origin/master.. \
101
- | saddler run \
101
+ | saddler report \
102
102
  --require github/pull-request-comment-formatter \
103
103
  --format Github::PullRequestCommentFormatter
104
104
  ```
@@ -119,6 +119,26 @@ Or install it yourself as:
119
119
 
120
120
  $ gem install checkstyle_filter-git
121
121
 
122
+ ## Help
123
+
124
+ ```
125
+ $ checkstyle_filter-git
126
+ Commands:
127
+ checkstyle_filter-git diff # Filter using `git diff`
128
+ checkstyle_filter-git help [COMMAND] # Describe available commands or one specific command
129
+ checkstyle_filter-git version # Show the CheckstyleFilter/Git version
130
+
131
+ $ checkstyle_filter-git help diff
132
+ Usage:
133
+ checkstyle_filter-git diff
134
+
135
+ Options:
136
+ [--data=DATA]
137
+ [--file=FILE]
138
+
139
+ Filter using `git diff`
140
+ ```
141
+
122
142
  ## Development
123
143
 
124
144
  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. Run `bundle exec checkstyle_filter-git` to use the code located in this directory, ignoring other installed copies of this gem.
@@ -127,7 +147,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
127
147
 
128
148
  ## Contributing
129
149
 
130
- 1. Fork it ( https://github.com/[my-github-username]/checkstyle_filter-git/fork )
150
+ 1. Fork it ( https://github.com/packsaddle/ruby-checkstyle_filter-git/fork )
131
151
  2. Create your feature branch (`git checkout -b my-new-feature`)
132
152
  3. Commit your changes (`git commit -am 'Add some feature'`)
133
153
  4. Push to the branch (`git push origin my-new-feature`)
@@ -27,5 +27,6 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.8'
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
- spec.add_development_dependency 'minitest'
30
+ spec.add_development_dependency 'test-unit'
31
+ spec.add_development_dependency 'nori'
31
32
  end
@@ -1,9 +1,8 @@
1
- require 'checkstyle_filter/git/version'
2
1
  require 'git/diff/parser'
3
- require 'checkstyle_filter/git/diff_parser'
2
+ require 'checkstyle_filter/git/version'
3
+ require 'checkstyle_filter/git/filter'
4
4
 
5
5
  module CheckstyleFilter
6
6
  module Git
7
- # Your code goes here...
8
7
  end
9
8
  end
@@ -26,23 +26,7 @@ module CheckstyleFilter
26
26
 
27
27
  command = ['git', 'diff', '--no-color', commit_ish].compact
28
28
  git_diff, _, _ = Open3.capture3(*command)
29
- parsed = ::CheckstyleFilter::Git::DiffParser.parse(git_diff)
30
-
31
- # TODO: split to class
32
- require 'rexml/document'
33
- document = REXML::Document.new data
34
- document.elements.each('/checkstyle/file') do |file_element|
35
- file_name = file_element.attribute('name').value
36
- next unless file_element_file_in_git_diff?(file_name, parsed)
37
- file_element.elements.each('error') do |error_element|
38
- line = error_element.attribute('line') && error_element.attribute('line').value.to_i
39
- if file_element_error_line_no_in_modified?(file_name, parsed, line)
40
- error_element.remove
41
- end
42
- end
43
- end
44
-
45
- puts document.to_s
29
+ puts ::CheckstyleFilter::Git::Filter.filter(data, git_diff)
46
30
  end
47
31
 
48
32
  desc 'version', 'Show the CheckstyleFilter/Git version'
@@ -51,32 +35,6 @@ module CheckstyleFilter
51
35
  def version
52
36
  puts "CheckstyleFilter/Git version #{::CheckstyleFilter::Git::VERSION}"
53
37
  end
54
-
55
- no_commands do
56
- def file_element_file_in_git_diff?(file_name, parsed_git_diff)
57
- require 'pathname'
58
- diff_files = parsed_git_diff.map { |one| one[:file_name] }
59
- diff_files
60
- .map { |file| Pathname.new(file).expand_path }
61
- .include?(Pathname.new(file_name).expand_path)
62
- end
63
-
64
- def file_element_error_line_no_in_modified?(file_name, parsed_git_diff, line_no)
65
- require 'pathname'
66
- diff_pairs = parsed_git_diff
67
- .select do |diff|
68
- Pathname.new(diff[:file_name]).expand_path == Pathname.new(file_name).expand_path
69
- end
70
- return false if diff_pairs.empty?
71
- modified_lines = Set.new
72
- diff_pairs.map do |diff_pair|
73
- diff_pair[:patch].changed_lines.map do |line|
74
- modified_lines << line.number
75
- end
76
- end
77
- modified_lines.include?(line_no)
78
- end
79
- end
80
38
  end
81
39
  end
82
40
  end
@@ -0,0 +1,57 @@
1
+ require 'rexml/document'
2
+ require 'pathname'
3
+
4
+ module CheckstyleFilter
5
+ module Git
6
+ class Filter
7
+ def self.filter(data, git_diff)
8
+ patches = ::Git::Diff::Parser.parse(git_diff)
9
+
10
+ document = REXML::Document.new data
11
+ document.elements.each('/checkstyle/file') do |file_element|
12
+ file_name = file_element.attribute('name') && file_element.attribute('name').value
13
+ if file_in_patches?(file_name, patches)
14
+ file_element.elements.each('error') do |error_element|
15
+ line = error_element.attribute('line') && error_element.attribute('line').value.to_i
16
+ unless file_element_error_line_no_in_patches?(file_name, patches, line)
17
+ error_element.remove
18
+ end
19
+ end
20
+ else
21
+ file_element.elements.each('error') do |error_element|
22
+ error_element.remove
23
+ end
24
+ end
25
+ end
26
+
27
+ document.to_s
28
+ end
29
+
30
+ def self.file_in_patches?(file_name, patches)
31
+ patches
32
+ .map(&:file)
33
+ .map { |file| Pathname.new(file).expand_path }
34
+ .include?(Pathname.new(file_name).expand_path)
35
+ end
36
+
37
+ def self.file_element_error_line_no_in_patches?(file_name, patches, line_no)
38
+ diff_patches = patches
39
+ .select { |patch| same_file?(patch.file, file_name) }
40
+ return false if diff_patches.empty?
41
+
42
+ modified_lines = Set.new
43
+ diff_patches.map do |patch|
44
+ patch.changed_lines.map do |line|
45
+ modified_lines << line.number
46
+ end
47
+ end
48
+
49
+ modified_lines.include?(line_no)
50
+ end
51
+
52
+ def self.same_file?(one, other)
53
+ Pathname.new(one).expand_path == Pathname.new(other).expand_path
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  module CheckstyleFilter
2
2
  module Git
3
- VERSION = '0.1.1'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkstyle_filter-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
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-18 00:00:00.000000000 Z
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -67,7 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: minitest
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nori
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -100,13 +114,12 @@ files:
100
114
  - bin/setup
101
115
  - checkstyle_filter-git.gemspec
102
116
  - example/example1.xml
103
- - example/github-pull-requests-files-response.json
104
117
  - example/invalid.rb
105
118
  - example/simple.rb
106
119
  - exe/checkstyle_filter-git
107
120
  - lib/checkstyle_filter/git.rb
108
121
  - lib/checkstyle_filter/git/cli.rb
109
- - lib/checkstyle_filter/git/diff_parser.rb
122
+ - lib/checkstyle_filter/git/filter.rb
110
123
  - lib/checkstyle_filter/git/version.rb
111
124
  homepage: https://github.com/packsaddle/ruby-checkstyle_filter-git
112
125
  licenses:
@@ -1,26 +0,0 @@
1
- [
2
- {
3
- "sha": "80adf33bacc9f387b6ac2e099945326b3e699fda",
4
- "filename": "lib/tachikoma/settings.rb",
5
- "status": "modified",
6
- "additions": 23,
7
- "deletions": 2,
8
- "changes": 25,
9
- "blob_url": "https://github.com/sanemat/tachikoma/blob/216e050fac8cb7133b8b19a1c0292f48e5994645/lib/tachikoma/settings.rb",
10
- "raw_url": "https://github.com/sanemat/tachikoma/raw/216e050fac8cb7133b8b19a1c0292f48e5994645/lib/tachikoma/settings.rb",
11
- "contents_url": "https://api.github.com/repos/sanemat/tachikoma/contents/lib/tachikoma/settings.rb?ref=216e050fac8cb7133b8b19a1c0292f48e5994645",
12
- "patch": "@@ -1,6 +1,27 @@\n require 'pathname'\n+\n module Tachikoma\n- def self.root\n- Pathname.new(File.dirname(File.dirname(File.dirname(__FILE__))))\n+ def self.root_path\n+ @root_path ||= Pathname.new(File.dirname(File.dirname(File.dirname(__FILE__))))\n+ end\n+\n+ def self.root_path=(root_path)\n+ @root_path = Pathname.new File.expand_path(root_path)\n+ end\n+\n+ def self.data_path\n+ @data_path ||= root_path.parent.join('data')\n+ end\n+\n+ def self.data_path=(data_path)\n+ @data_path = Pathname.new File.expand_path(data_path)\n+ end\n+\n+ def self.repos_path\n+ @repos_path ||= root_path.parent.join('repos')\n+ end\n+\n+ def self.repos_path=(repos_path)\n+ @repos_path = Pathname.new File.expand_path(repos_path)\n end\n end"
13
- },
14
- {
15
- "sha": "d71ff33adad9125f0939681435e2ad3531ca26cb",
16
- "filename": "lib/tasks/app.rake",
17
- "status": "modified",
18
- "additions": 9,
19
- "deletions": 11,
20
- "changes": 20,
21
- "blob_url": "https://github.com/sanemat/tachikoma/blob/216e050fac8cb7133b8b19a1c0292f48e5994645/lib/tasks/app.rake",
22
- "raw_url": "https://github.com/sanemat/tachikoma/raw/216e050fac8cb7133b8b19a1c0292f48e5994645/lib/tasks/app.rake",
23
- "contents_url": "https://api.github.com/repos/sanemat/tachikoma/contents/lib/tasks/app.rake?ref=216e050fac8cb7133b8b19a1c0292f48e5994645",
24
- "patch": "@@ -2,12 +2,10 @@ require 'httparty'\n require 'multi_json'\n require 'safe_yaml'\n require 'uri'\n+require 'tachikoma'\n \n namespace :tachikoma do\n @default_timestamp_format = '%Y%m%d%H%M%S'\n- @root_path = File.expand_path(File.join(__FILE__, '..', '..', '..'))\n- @data_path = File.join(@root_path, 'data')\n- @repos_path = File.join(@root_path, 'repos')\n \n # build_for = fenix-knight, github_token_key = TOKEN_FENIX_KNIGHT\n def github_token_key(build_for)\n@@ -50,9 +48,9 @@ namespace :tachikoma do\n if ENV['LOCAL_DATA_PATH'] && ENV['LOCAL_DATA_REMOTE_URL']\n raise \"local data path is empty\" if ENV['LOCAL_DATA_PATH'] == ''\n raise \"remote git repository of local data is empty\" if ENV['LOCAL_DATA_REMOTE_URL'] == ''\n- @data_path = File.absolute_path(ENV['LOCAL_DATA_PATH'])\n- rm_rf(@data_path) if Dir.exists?(@data_path)\n- sh \"git clone #{ENV['LOCAL_DATA_REMOTE_URL']} #{@data_path}\"\n+ Tachikoma.data_path = File.absolute_path(ENV['LOCAL_DATA_PATH'])\n+ rm_rf(Tachikoma.data_path) if Dir.exists?(Tachikoma.data_path)\n+ sh \"git clone #{ENV['LOCAL_DATA_REMOTE_URL']} #{Tachikoma.data_path}\"\n raise \"failed to clone remote repo: perhaps wrong git clone URL? #{ENV['LOCAL_DATA_REMOTE_URL']}\" unless $?.success?\n else\n warn \"`fetch_data` task requires LOCAL_DATA_PATH and LOCAL_DATA_REMOTE_URL environment variables\"\n@@ -65,7 +63,7 @@ namespace :tachikoma do\n @git_name = 'bot-motoko'\n @git_email = 'bot-motoko@al.sane.jp'\n @configure =\n- YAML.load_file(File.join(@data_path, \"#{@build_for}.yaml\"))\n+ YAML.load_file(File.join(Tachikoma.data_path, \"#{@build_for}.yaml\"))\n @fetch_url = @configure['url']\n @base_remote_branch = 'origin/master'\n @authorized_url = authorized_url_with_type(@fetch_url, @configure['type'], @github_token, @git_name)\n@@ -90,18 +88,18 @@ namespace :tachikoma do\n end\n \n task :clean do\n- rm_rf(Dir.glob('repos/*'))\n+ rm_rf(Dir.glob(Tachikoma.repos_path.to_s))\n end\n \n desc 'fetch'\n task fetch: :clean do\n- mkdir_p('repos')\n- sh \"git clone #{@fetch_url} repos/#{@build_for}\"\n+ mkdir_p(Tachikoma.repos_path.to_s)\n+ sh \"git clone #{@fetch_url} #{Tachikoma.repos_path.to_s}/#{@build_for}\"\n end\n \n desc 'bundle'\n task :bundle do\n- Dir.chdir(\"repos/#{@build_for}\") do\n+ Dir.chdir(\"#{Tachikoma.repos_path.to_s}/#{@build_for}\") do\n Bundler.with_clean_env do\n sh %Q!sed -i -e 's/^ruby/#ruby/' Gemfile!\n sh \"git config user.name #{@git_name}\""
25
- }
26
- ]
@@ -1,39 +0,0 @@
1
- module CheckstyleFilter
2
- module Git
3
- class DiffParser
4
- def self.parse(contents)
5
- body = false
6
- file_name = ''
7
- patch = []
8
- lines = contents.lines
9
- line_count = lines.count
10
- parsed = []
11
- lines.each_with_index do |line, count|
12
- case line.chomp
13
- when /^diff/
14
- unless patch.empty?
15
- parsed << { file_name: file_name,
16
- patch: ::Git::Diff::Parser::Patch.new(patch.join("\n")) }
17
- patch.clear
18
- file_name = ''
19
- end
20
- body = false
21
- when /^\-\-\-/
22
- when %r{^\+\+\+ b/(?<file_name>.*)}
23
- file_name = Regexp.last_match[:file_name]
24
- body = true
25
- when /^(?<body>[\ @\+\-\\].*)/
26
- patch << Regexp.last_match[:body] if body
27
- if !patch.empty? && body && line_count == count + 1
28
- parsed << { file_name: file_name,
29
- patch: ::Git::Diff::Parser::Patch.new(patch.join("\n")) }
30
- patch.clear
31
- file_name = ''
32
- end
33
- end
34
- end
35
- parsed
36
- end
37
- end
38
- end
39
- end