danger-suggester 0.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 +7 -0
- data/.circleci/config.yml +52 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +12 -0
- data/Dangerfile +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +102 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/danger-suggester.gemspec +28 -0
- data/lib/danger/danger_suggester.rb +73 -0
- data/lib/danger/suggester.rb +1 -0
- data/lib/danger/suggester/change.rb +44 -0
- data/lib/danger/suggester/file.rb +41 -0
- data/lib/danger/suggester/hunk.rb +37 -0
- data/lib/danger/suggester/suggestion.rb +25 -0
- data/lib/danger/suggester/version.rb +5 -0
- data/lib/danger_plugin.rb +1 -0
- metadata +137 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 914c57b0044329d100595db51bd52d30c73c31f2
|
|
4
|
+
data.tar.gz: 8c7216939ba27bcf0d7c07f59b5d95f3009048c1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 86deaebae81b426eea652bd67e1724a1d271b582977367b99a1919abab4bbe33c42107fbe026d25fd935a44513c875d292671252876beb63ffc29144a2ffaf90
|
|
7
|
+
data.tar.gz: 8e94a4dd2d0110dc41b26c7fd4fe4258466c4e140533d1db34775c39f0d9e4a27959288053498c89b2058539b1b317136e4fdf051e322a4e337a3e54b40d7191
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
jobs:
|
|
2
|
+
danger:
|
|
3
|
+
machine: true
|
|
4
|
+
steps:
|
|
5
|
+
- checkout
|
|
6
|
+
- run:
|
|
7
|
+
command: gem install bundler -v 1.17.1
|
|
8
|
+
name: gem install bundler -v 1.17.1
|
|
9
|
+
- run:
|
|
10
|
+
command: bundle install
|
|
11
|
+
name: bundle install
|
|
12
|
+
- run:
|
|
13
|
+
command: bundle exec rubocop --auto-correct
|
|
14
|
+
name: rubocop
|
|
15
|
+
- run:
|
|
16
|
+
command: bundle exec danger
|
|
17
|
+
name: danger
|
|
18
|
+
when: always
|
|
19
|
+
rspec:
|
|
20
|
+
machine: true
|
|
21
|
+
steps:
|
|
22
|
+
- checkout
|
|
23
|
+
- run:
|
|
24
|
+
command: gem install bundler -v 1.17.1
|
|
25
|
+
name: gem install bundler -v 1.17.1
|
|
26
|
+
- run:
|
|
27
|
+
command: bundle install
|
|
28
|
+
name: bundle install
|
|
29
|
+
- run:
|
|
30
|
+
command: bundle exec rspec
|
|
31
|
+
name: rspec
|
|
32
|
+
rubocop:
|
|
33
|
+
machine: true
|
|
34
|
+
steps:
|
|
35
|
+
- checkout
|
|
36
|
+
- run:
|
|
37
|
+
command: gem install bundler -v 1.17.1
|
|
38
|
+
name: gem install bundler -v 1.17.1
|
|
39
|
+
- run:
|
|
40
|
+
command: bundle install
|
|
41
|
+
name: bundle install
|
|
42
|
+
- run:
|
|
43
|
+
command: bundle exec rubocop
|
|
44
|
+
name: rubocop
|
|
45
|
+
version: 2
|
|
46
|
+
workflows:
|
|
47
|
+
version: 2
|
|
48
|
+
test:
|
|
49
|
+
jobs:
|
|
50
|
+
- danger
|
|
51
|
+
- rspec
|
|
52
|
+
- rubocop
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## 0.1.0 - 2018-11-15
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add features to suggest code changes through inline comments in pull requests.
|
data/Dangerfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
suggester.suggest
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
danger-suggester (0.1.0)
|
|
5
|
+
danger
|
|
6
|
+
git_diff
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
addressable (2.5.2)
|
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
|
13
|
+
ast (2.4.0)
|
|
14
|
+
claide (1.0.2)
|
|
15
|
+
claide-plugins (0.9.2)
|
|
16
|
+
cork
|
|
17
|
+
nap
|
|
18
|
+
open4 (~> 1.3)
|
|
19
|
+
coderay (1.1.2)
|
|
20
|
+
colored2 (3.1.2)
|
|
21
|
+
cork (0.3.0)
|
|
22
|
+
colored2 (~> 3.1)
|
|
23
|
+
danger (5.8.0)
|
|
24
|
+
claide (~> 1.0)
|
|
25
|
+
claide-plugins (>= 0.9.2)
|
|
26
|
+
colored2 (~> 3.1)
|
|
27
|
+
cork (~> 0.1)
|
|
28
|
+
faraday (~> 0.9)
|
|
29
|
+
faraday-http-cache (~> 1.0)
|
|
30
|
+
git (~> 1.5)
|
|
31
|
+
kramdown (~> 1.5)
|
|
32
|
+
no_proxy_fix
|
|
33
|
+
octokit (~> 4.7)
|
|
34
|
+
terminal-table (~> 1)
|
|
35
|
+
diff-lcs (1.3)
|
|
36
|
+
faraday (0.15.3)
|
|
37
|
+
multipart-post (>= 1.2, < 3)
|
|
38
|
+
faraday-http-cache (1.3.1)
|
|
39
|
+
faraday (~> 0.8)
|
|
40
|
+
git (1.5.0)
|
|
41
|
+
git_diff (0.4.1)
|
|
42
|
+
jaro_winkler (1.5.1)
|
|
43
|
+
kramdown (1.17.0)
|
|
44
|
+
method_source (0.9.2)
|
|
45
|
+
multipart-post (2.0.0)
|
|
46
|
+
nap (1.1.0)
|
|
47
|
+
no_proxy_fix (0.1.2)
|
|
48
|
+
octokit (4.13.0)
|
|
49
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
|
50
|
+
open4 (1.3.4)
|
|
51
|
+
parallel (1.12.1)
|
|
52
|
+
parser (2.5.3.0)
|
|
53
|
+
ast (~> 2.4.0)
|
|
54
|
+
powerpack (0.1.2)
|
|
55
|
+
pry (0.12.2)
|
|
56
|
+
coderay (~> 1.1.0)
|
|
57
|
+
method_source (~> 0.9.0)
|
|
58
|
+
public_suffix (3.0.3)
|
|
59
|
+
rainbow (3.0.0)
|
|
60
|
+
rake (10.5.0)
|
|
61
|
+
rspec (3.7.0)
|
|
62
|
+
rspec-core (~> 3.7.0)
|
|
63
|
+
rspec-expectations (~> 3.7.0)
|
|
64
|
+
rspec-mocks (~> 3.7.0)
|
|
65
|
+
rspec-core (3.7.1)
|
|
66
|
+
rspec-support (~> 3.7.0)
|
|
67
|
+
rspec-expectations (3.7.0)
|
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
69
|
+
rspec-support (~> 3.7.0)
|
|
70
|
+
rspec-mocks (3.7.0)
|
|
71
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
72
|
+
rspec-support (~> 3.7.0)
|
|
73
|
+
rspec-support (3.7.1)
|
|
74
|
+
rubocop (0.60.0)
|
|
75
|
+
jaro_winkler (~> 1.5.1)
|
|
76
|
+
parallel (~> 1.10)
|
|
77
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
78
|
+
powerpack (~> 0.1)
|
|
79
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
80
|
+
ruby-progressbar (~> 1.7)
|
|
81
|
+
unicode-display_width (~> 1.4.0)
|
|
82
|
+
ruby-progressbar (1.10.0)
|
|
83
|
+
sawyer (0.8.1)
|
|
84
|
+
addressable (>= 2.3.5, < 2.6)
|
|
85
|
+
faraday (~> 0.8, < 1.0)
|
|
86
|
+
terminal-table (1.8.0)
|
|
87
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
88
|
+
unicode-display_width (1.4.0)
|
|
89
|
+
|
|
90
|
+
PLATFORMS
|
|
91
|
+
ruby
|
|
92
|
+
|
|
93
|
+
DEPENDENCIES
|
|
94
|
+
bundler (~> 1.17)
|
|
95
|
+
danger-suggester!
|
|
96
|
+
pry
|
|
97
|
+
rake (~> 10.0)
|
|
98
|
+
rspec (~> 3.0)
|
|
99
|
+
rubocop
|
|
100
|
+
|
|
101
|
+
BUNDLED WITH
|
|
102
|
+
1.17.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Ryo Nakamura
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Danger::Suggester
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/r7kamura/workflows/danger-suggester)
|
|
4
|
+
[](http://www.rubydoc.info/github/r7kamura/danger-suggester)
|
|
5
|
+
|
|
6
|
+
A Danger plug-in to suggest code changes through inline comments in pull requests.
|
|
7
|
+
|
|
8
|
+
## Requirements
|
|
9
|
+
|
|
10
|
+
- Ruby 2.2 or higher
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'danger-suggester'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
And then execute:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
bundle
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or install it yourself as:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
gem install danger-suggester
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
Add this line to your application's Dangerfile:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
suggester.suggest
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
And then execute `danger` after correcting code by some linter tools (e.g. `rubocop --auto-correct`).
|
|
41
|
+
|
|
42
|
+
## Contributing
|
|
43
|
+
|
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/r7kamura/danger-suggester.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'danger/suggester'
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require 'irb'
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require 'danger/suggester/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'danger-suggester'
|
|
7
|
+
spec.version = Danger::Suggester::VERSION
|
|
8
|
+
spec.authors = ['Ryo Nakamura']
|
|
9
|
+
spec.email = ['r7kamura@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'A Danger plug-in to suggest code changes through inline comments in pull requests.'
|
|
12
|
+
spec.homepage = 'https://github.com/r7kamura/danger-suggester'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
|
+
|
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
|
+
end
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
|
+
|
|
22
|
+
spec.add_dependency 'danger'
|
|
23
|
+
spec.add_dependency 'git_diff'
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
28
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'danger'
|
|
2
|
+
require 'danger/suggester/file'
|
|
3
|
+
require 'danger/suggester/suggestion'
|
|
4
|
+
require 'git_diff'
|
|
5
|
+
|
|
6
|
+
module Danger
|
|
7
|
+
class DangerSuggester < ::Danger::Plugin
|
|
8
|
+
def suggest
|
|
9
|
+
suggestions_for_added_lines.each do |suggestion|
|
|
10
|
+
markdown(
|
|
11
|
+
suggestion.message,
|
|
12
|
+
file: suggestion.path,
|
|
13
|
+
line: suggestion.line
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# @return [Hash{String => Array<Integer>}]
|
|
21
|
+
def added_lines_in_commits
|
|
22
|
+
@added_lines_in_commits ||= begin
|
|
23
|
+
origin = ::Hash.new do |hash, key|
|
|
24
|
+
hash[key] = []
|
|
25
|
+
end
|
|
26
|
+
::GitDiff.from_string(diff_string_from_commits).files.each_with_object(origin) do |file, result|
|
|
27
|
+
result[file.b_path] = file.hunks.flat_map do |hunk|
|
|
28
|
+
hunk.lines.grep(::GitDiff::Line::Addition).map do |line|
|
|
29
|
+
line.line_number.right
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @return [String]
|
|
37
|
+
def diff_string_from_commits
|
|
38
|
+
git.diff.patch
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [String]
|
|
42
|
+
def diff_string_from_unstaged_changes
|
|
43
|
+
`git diff`
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [Array<Danger::Suggester::File>]
|
|
47
|
+
def files
|
|
48
|
+
::GitDiff.from_string(diff_string_from_unstaged_changes).files.map do |file|
|
|
49
|
+
::Danger::Suggester::File.new(file)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @return [Array<Danger::Suggester::Suggestion>]
|
|
54
|
+
def suggestions_for_added_lines
|
|
55
|
+
suggestions_for_unstaged_changes.select do |suggestion|
|
|
56
|
+
added_lines_in_commits[suggestion.path].include?(suggestion.line)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @return [Array<Danger::Suggester::Suggestion>]
|
|
61
|
+
def suggestions_for_unstaged_changes
|
|
62
|
+
files.select(&:suggestible?).flat_map do |file|
|
|
63
|
+
file.changes.select(&:suggestible?).map do |change|
|
|
64
|
+
::Danger::Suggester::Suggestion.new(
|
|
65
|
+
content: change.added_content,
|
|
66
|
+
line: change.first_line_number,
|
|
67
|
+
path: file.a_path
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'danger/suggester/version'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'git_diff'
|
|
2
|
+
|
|
3
|
+
module Danger
|
|
4
|
+
module Suggester
|
|
5
|
+
class Change
|
|
6
|
+
# @param [Array<GitDiff::Line::Context>]
|
|
7
|
+
def initialize(chunks)
|
|
8
|
+
@chunks = chunks
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def added_content
|
|
13
|
+
added_lines.map do |line|
|
|
14
|
+
line.content[1..-1]
|
|
15
|
+
end.join("\n")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @return [Integer]
|
|
19
|
+
def first_line_number
|
|
20
|
+
@chunks.first.line_number.left
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Boolean]
|
|
24
|
+
def suggestible?
|
|
25
|
+
deleted_lines.count == 1
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def added_lines
|
|
31
|
+
@chunks.drop_while do |line|
|
|
32
|
+
line.is_a?(::GitDiff::Line::Deletion)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @return [Integer]
|
|
37
|
+
def deleted_lines
|
|
38
|
+
@chunks.take_while do |line|
|
|
39
|
+
line.is_a?(::GitDiff::Line::Deletion)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'danger/suggester/hunk'
|
|
2
|
+
|
|
3
|
+
module Danger
|
|
4
|
+
module Suggester
|
|
5
|
+
class File
|
|
6
|
+
# @param [GitDiff::File] file
|
|
7
|
+
def initialize(file)
|
|
8
|
+
@file = file
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def a_path
|
|
13
|
+
@file.a_path
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @return [Array<Danger::Suggester::Change>]
|
|
17
|
+
def changes
|
|
18
|
+
hunks.flat_map(&:changes)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @return [Boolean]
|
|
22
|
+
def suggestible?
|
|
23
|
+
!renamed?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
# @return [Array<Danger::Suggester::Hunk>]
|
|
29
|
+
def hunks
|
|
30
|
+
@file.hunks.map do |hunk|
|
|
31
|
+
::Danger::Suggester::Hunk.new(hunk)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [Boolean]
|
|
36
|
+
def renamed?
|
|
37
|
+
@file.a_path != @file.b_path
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'danger/suggester/change'
|
|
2
|
+
require 'git_diff'
|
|
3
|
+
|
|
4
|
+
module Danger
|
|
5
|
+
module Suggester
|
|
6
|
+
class Hunk
|
|
7
|
+
# @param [GitDiff::Hunk] hunk
|
|
8
|
+
def initialize(hunk)
|
|
9
|
+
@hunk = hunk
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @return [Array<Danger::Suggester::Change>]
|
|
13
|
+
def changes
|
|
14
|
+
chunks_without_context.map do |chunk|
|
|
15
|
+
::Danger::Suggester::Change.new(chunk)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @return [Array<Array<GitDiff::Line::Context>>]
|
|
20
|
+
def chunks
|
|
21
|
+
@hunk.lines.chunk_while do |a, b|
|
|
22
|
+
a.instance_of?(::GitDiff::Line::Context) && b.instance_of?(::GitDiff::Line::Context) ||
|
|
23
|
+
a.instance_of?(::GitDiff::Line::Deletion) && b.instance_of?(::GitDiff::Line::Deletion) ||
|
|
24
|
+
a.instance_of?(::GitDiff::Line::Deletion) && b.instance_of?(::GitDiff::Line::Addition) ||
|
|
25
|
+
a.instance_of?(::GitDiff::Line::Addition) && b.instance_of?(::GitDiff::Line::Addition)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @return [Array<Array<GitDiff::Line::Context>>]
|
|
30
|
+
def chunks_without_context
|
|
31
|
+
chunks.reject do |chunk|
|
|
32
|
+
chunk.first.instance_of?(::GitDiff::Line::Context)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Danger
|
|
2
|
+
module Suggester
|
|
3
|
+
class Suggestion
|
|
4
|
+
# @return [Integer]
|
|
5
|
+
attr_reader :line
|
|
6
|
+
|
|
7
|
+
# @param [String]
|
|
8
|
+
attr_reader :path
|
|
9
|
+
|
|
10
|
+
# @param [String] content
|
|
11
|
+
# @param [Integer] line
|
|
12
|
+
# @param [String] path
|
|
13
|
+
def initialize(content:, line:, path:)
|
|
14
|
+
@content = content
|
|
15
|
+
@line = line
|
|
16
|
+
@path = path
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @return [String]
|
|
20
|
+
def message
|
|
21
|
+
"```suggestion\n#{@content}\n```"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'danger/danger_suggester'
|
metadata
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: danger-suggester
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ryo Nakamura
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: danger
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: git_diff
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.17'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.17'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '10.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '10.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
description:
|
|
84
|
+
email:
|
|
85
|
+
- r7kamura@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".circleci/config.yml"
|
|
91
|
+
- ".gitignore"
|
|
92
|
+
- ".rspec"
|
|
93
|
+
- ".rubocop.yml"
|
|
94
|
+
- CHANGELOG.md
|
|
95
|
+
- Dangerfile
|
|
96
|
+
- Gemfile
|
|
97
|
+
- Gemfile.lock
|
|
98
|
+
- LICENSE.txt
|
|
99
|
+
- README.md
|
|
100
|
+
- Rakefile
|
|
101
|
+
- bin/console
|
|
102
|
+
- bin/setup
|
|
103
|
+
- danger-suggester.gemspec
|
|
104
|
+
- lib/danger/danger_suggester.rb
|
|
105
|
+
- lib/danger/suggester.rb
|
|
106
|
+
- lib/danger/suggester/change.rb
|
|
107
|
+
- lib/danger/suggester/file.rb
|
|
108
|
+
- lib/danger/suggester/hunk.rb
|
|
109
|
+
- lib/danger/suggester/suggestion.rb
|
|
110
|
+
- lib/danger/suggester/version.rb
|
|
111
|
+
- lib/danger_plugin.rb
|
|
112
|
+
homepage: https://github.com/r7kamura/danger-suggester
|
|
113
|
+
licenses:
|
|
114
|
+
- MIT
|
|
115
|
+
metadata: {}
|
|
116
|
+
post_install_message:
|
|
117
|
+
rdoc_options: []
|
|
118
|
+
require_paths:
|
|
119
|
+
- lib
|
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ">="
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0'
|
|
130
|
+
requirements: []
|
|
131
|
+
rubyforge_project:
|
|
132
|
+
rubygems_version: 2.6.11
|
|
133
|
+
signing_key:
|
|
134
|
+
specification_version: 4
|
|
135
|
+
summary: A Danger plug-in to suggest code changes through inline comments in pull
|
|
136
|
+
requests.
|
|
137
|
+
test_files: []
|