danger-warnings_next_generation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ ROOT = Pathname.new(File.expand_path("..", __dir__))
5
+ $:.unshift((ROOT + "lib").to_s)
6
+ $:.unshift((ROOT + "spec").to_s)
7
+
8
+ require "bundler/setup"
9
+
10
+ require "rspec"
11
+ require "danger"
12
+ require "mocha"
13
+
14
+ require "simplecov"
15
+
16
+ SimpleCov.start
17
+
18
+ if `git remote -v` == ""
19
+ puts "You cannot run tests without setting a local git remote on this repo"
20
+ puts "It's a weird side-effect of Danger's internals."
21
+ exit(0)
22
+ end
23
+
24
+ # Use coloured output, it's the best.
25
+ RSpec.configure do |config|
26
+ config.filter_gems_from_backtrace "bundler"
27
+ config.color = true
28
+ config.tty = true
29
+ config.mock_with :mocha
30
+ end
31
+
32
+ require "danger_plugin"
33
+
34
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
35
+ # If you are expanding these files, see if it's already been done ^.
36
+
37
+ # A silent version of the user interface,
38
+ # it comes with an extra function `.string` which will
39
+ # strip all ANSI colours from the string.
40
+
41
+ # rubocop:disable Lint/NestedMethodDefinition
42
+ def testing_ui
43
+ @output = StringIO.new
44
+ def @output.winsize
45
+ [20, 9999]
46
+ end
47
+
48
+ cork = Cork::Board.new(out: @output)
49
+ def cork.string
50
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
51
+ end
52
+ cork
53
+ end
54
+ # rubocop:enable Lint/NestedMethodDefinition
55
+
56
+ # Example environment (ENV) that would come from
57
+ # running a PR on TravisCI
58
+ def testing_env
59
+ {
60
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
61
+ "TRAVIS_PULL_REQUEST" => "800",
62
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
63
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
64
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio",
65
+ }
66
+ end
67
+
68
+ # A stubbed out Dangerfile for use in tests
69
+ def testing_dangerfile
70
+ env = Danger::EnvironmentManager.new(testing_env)
71
+ Danger::Dangerfile.new(env, testing_ui)
72
+ end
@@ -0,0 +1,248 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("spec_helper", __dir__)
4
+ MARKDOWN_FIRST_TABLE_INDEX = 4
5
+ JAVA_ALL_BASELINE = "/var/lib/jenkins/workspace/projectname/b2b-app-android-analyze/repository/"
6
+
7
+ module Danger
8
+ describe Danger::DangerWarningsNextGeneration do
9
+ it "should be a plugin" do
10
+ expect(Danger::DangerWarningsNextGeneration.new(nil)).to be_a Danger::Plugin
11
+ end
12
+
13
+ describe "with Dangerfile" do
14
+ before do
15
+ @dangerfile = testing_dangerfile
16
+ @my_plugin = @dangerfile.warnings_next_generation
17
+ end
18
+
19
+ describe "overview_report" do
20
+ it "all zero displays star, zero, zero" do
21
+ aggregation_return("/assets/aggregation_single.json")
22
+ overview_return("/assets/java_zero.json")
23
+ @my_plugin.overview_report(include: ["java"])
24
+
25
+ markdowns = @dangerfile.status_report[:markdowns]
26
+ expect(markdowns.length).to be(1)
27
+
28
+ rows = markdowns.first.message.split("\n")
29
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 1)
30
+ expect(rows[MARKDOWN_FIRST_TABLE_INDEX]).to include("|:star:|0|0|")
31
+ end
32
+
33
+ it "new issues zero displays zero" do
34
+ aggregation_return("/assets/aggregation_single.json")
35
+ overview_return("/assets/java_zero_new.json")
36
+ @my_plugin.overview_report
37
+
38
+ markdowns = @dangerfile.status_report[:markdowns]
39
+ expect(markdowns.length).to be(1)
40
+
41
+ rows = markdowns.first.message.split("\n")
42
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 1)
43
+ expect(rows[MARKDOWN_FIRST_TABLE_INDEX]).to include("|8|0|4|")
44
+ end
45
+
46
+ it "displays correct issue sizes" do
47
+ aggregation_return("/assets/aggregation_single.json")
48
+ overview_return("/assets/java.json")
49
+ @my_plugin.overview_report
50
+
51
+ markdowns = @dangerfile.status_report[:markdowns]
52
+ expect(markdowns.length).to be(1)
53
+
54
+ rows = markdowns.first.message.split("\n")
55
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 1)
56
+ expect(rows[MARKDOWN_FIRST_TABLE_INDEX]).to include("|3|2|1|")
57
+ end
58
+
59
+ it "list all entries" do
60
+ aggregation_return("/assets/aggregation.json")
61
+ overview_return("/assets/java.json")
62
+ @my_plugin.overview_report
63
+
64
+ markdowns = @dangerfile.status_report[:markdowns]
65
+ expect(markdowns.length).to be(1)
66
+
67
+ rows = markdowns.first.message.split("\n")
68
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 8)
69
+ end
70
+
71
+ it "no configuration list all entries" do
72
+ aggregation_return("/assets/aggregation.json")
73
+ overview_return("/assets/java.json")
74
+ @my_plugin.overview_report
75
+
76
+ markdowns = @dangerfile.status_report[:markdowns]
77
+ expect(markdowns.length).to be(1)
78
+
79
+ rows = markdowns.first.message.split("\n")
80
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 8)
81
+ end
82
+
83
+ it "single include adds target entry" do
84
+ aggregation_return("/assets/aggregation.json")
85
+ overview_return("/assets/java.json")
86
+ @my_plugin.overview_report(include: ["java"])
87
+
88
+ markdowns = @dangerfile.status_report[:markdowns]
89
+ expect(markdowns.length).to be(1)
90
+
91
+ rows = markdowns.first.message.split("\n")
92
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 1)
93
+ expect(rows[MARKDOWN_FIRST_TABLE_INDEX]).to include("Java Warnings")
94
+ end
95
+
96
+ it "multiple include adds valid entries" do
97
+ aggregation_return("/assets/aggregation.json")
98
+ overview_return("/assets/java.json")
99
+ @my_plugin.overview_report(include: %w(java pmd))
100
+
101
+ markdowns = @dangerfile.status_report[:markdowns]
102
+ expect(markdowns.length).to be(1)
103
+
104
+ rows = markdowns.first.message.split("\n")
105
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 2)
106
+ expect(rows[MARKDOWN_FIRST_TABLE_INDEX]).to include("Java Warnings")
107
+ expect(rows[MARKDOWN_FIRST_TABLE_INDEX + 1]).to include("PMD Warnings")
108
+ end
109
+
110
+ it "empty includes add no overview" do
111
+ aggregation_return("/assets/aggregation.json")
112
+ overview_return("/assets/java.json")
113
+ @my_plugin.overview_report(include: [])
114
+
115
+ markdowns = @dangerfile.status_report[:markdowns]
116
+ expect(markdowns.length).to be(0)
117
+ end
118
+
119
+ it "wrong includes add no overview" do
120
+ aggregation_return("/assets/aggregation.json")
121
+ overview_return("/assets/java.json")
122
+ @my_plugin.overview_report(include: ["not_existing"])
123
+
124
+ markdowns = @dangerfile.status_report[:markdowns]
125
+ expect(markdowns.length).to be(0)
126
+ end
127
+ end
128
+
129
+ describe "tools_report" do
130
+ it "list all entries" do
131
+ aggregation_return("/assets/aggregation_single.json")
132
+ details_return("/assets/java_all.json")
133
+ @my_plugin.tools_report
134
+
135
+ markdowns = @dangerfile.status_report[:markdowns]
136
+ expect(markdowns.length).to be(1)
137
+
138
+ rows = markdowns.first.message.split("\n")
139
+ expect(rows.length).to be(MARKDOWN_FIRST_TABLE_INDEX + 8)
140
+ end
141
+
142
+ it "no configuration list all warnings reports" do
143
+ aggregation_return("/assets/aggregation.json")
144
+ details_return("/assets/java_all.json")
145
+ @my_plugin.tools_report
146
+
147
+ markdowns = @dangerfile.status_report[:markdowns]
148
+ expect(markdowns.length).to be(8)
149
+ end
150
+
151
+ it "single include adds table" do
152
+ aggregation_return("/assets/aggregation.json")
153
+ details_return("/assets/java_all.json")
154
+ @my_plugin.tools_report(include: ["java"])
155
+
156
+ markdowns = @dangerfile.status_report[:markdowns]
157
+ expect(markdowns.length).to be(1)
158
+ expect(markdowns.first.message).to include("Java Warnings")
159
+ end
160
+
161
+ it "multiple include adds table for each" do
162
+ aggregation_return("/assets/aggregation.json")
163
+ details_return("/assets/java_all.json")
164
+ @my_plugin.tools_report(include: %w(java pmd))
165
+
166
+ markdowns = @dangerfile.status_report[:markdowns]
167
+ expect(markdowns.length).to be(2)
168
+
169
+ expect(markdowns[0].message).to include("Java Warnings")
170
+ expect(markdowns[1].message).to include("PMD Warnings")
171
+ end
172
+
173
+ it "empty includes add no overview" do
174
+ aggregation_return("/assets/aggregation.json")
175
+ details_return("/assets/java_all.json")
176
+ @my_plugin.tools_report(include: [])
177
+
178
+ markdowns = @dangerfile.status_report[:markdowns]
179
+ expect(markdowns.length).to be(0)
180
+ end
181
+
182
+ it "wrong includes add no overview" do
183
+ aggregation_return("/assets/aggregation.json")
184
+ details_return("/assets/java_all.json")
185
+ @my_plugin.tools_report(include: ["not_existing"])
186
+
187
+ markdowns = @dangerfile.status_report[:markdowns]
188
+ expect(markdowns.length).to be(0)
189
+ end
190
+
191
+ it "inline missing baseline raises error" do
192
+ aggregation_return("/assets/aggregation_single.json")
193
+ details_return("/assets/java_all.json")
194
+ expect { @my_plugin.tools_report(inline: true) }.to raise_error(/set 'baseline'/)
195
+ end
196
+
197
+ it "creates inline comments" do
198
+ aggregation_return("/assets/aggregation_single.json")
199
+ details_return("/assets/java_all.json")
200
+ target_files_return_java_all
201
+ @my_plugin.tools_report(inline: true, baseline: JAVA_ALL_BASELINE)
202
+
203
+ markdowns = @dangerfile.status_report[:markdowns]
204
+ expect(markdowns.length).to be(0)
205
+
206
+ messages = @dangerfile.status_report[:messages]
207
+ expect(messages.length).to be(8)
208
+ end
209
+
210
+ it "inline comments remove baseline" do
211
+ aggregation_return("/assets/aggregation_single.json")
212
+ details_return("/assets/java_all.json")
213
+ target_files_return_java_all
214
+ @my_plugin.tools_report(inline: true, baseline: JAVA_ALL_BASELINE)
215
+
216
+ message = @dangerfile.violation_report[:messages].first
217
+ expect(message.file).not_to include(JAVA_ALL_BASELINE)
218
+ expect(message.file.chars.first).not_to eql("/")
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
224
+
225
+ def aggregation_return(file)
226
+ content = File.read(File.dirname(__FILE__) + file)
227
+ json = JSON.parse(content)
228
+ @my_plugin.stubs(:aggregation_result).returns(json)
229
+ end
230
+
231
+ def overview_return(file)
232
+ content = File.read(File.dirname(__FILE__) + file)
233
+ json = JSON.parse(content)
234
+ @my_plugin.stubs(:overview_result).returns(json)
235
+ end
236
+
237
+ def details_return(file)
238
+ content = File.read(File.dirname(__FILE__) + file)
239
+ json = JSON.parse(content)
240
+ @my_plugin.stubs(:details_result).returns(json)
241
+ end
242
+
243
+ def target_files_return_java_all
244
+ @my_plugin.stubs(:target_files).returns(["app/src/main/java/com/projectname/b2bshop/fragment/gallery/ImageGalleryFragment.kt",
245
+ "app/src/main/java/com/projectname/b2bshop/webservice/requestqueue/RequestQueue.java",
246
+ "app/src/main/java/com/projectname/b2bshop/webservice/requestqueue/RequestQueueImpl.java",
247
+ "app/src/main/java/com/projectname/b2bshop/fragment/ProductDetailPageFragment.kt"])
248
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-warnings_next_generation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Schwamberger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
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.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.16'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.16'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov-console
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.68'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.68'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.2'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.9'
153
+ description: Danger plugin to for Jenkins-Warnings-Next-Generation plugin.
154
+ email:
155
+ - kyaak.dev@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rubocop.yml"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - danger-warnings_next_generation.gemspec
168
+ - lib/danger_plugin.rb
169
+ - lib/danger_warnings_next_generation.rb
170
+ - lib/warnings_next_generation/gem_version.rb
171
+ - lib/warnings_next_generation/markdown_table.rb
172
+ - lib/warnings_next_generation/plugin.rb
173
+ - sonar-project.properties
174
+ - spec/assets/aggregation.json
175
+ - spec/assets/aggregation_single.json
176
+ - spec/assets/example/aggregation.json
177
+ - spec/assets/example/detail_android_lint.json
178
+ - spec/assets/example/detail_detekt.json
179
+ - spec/assets/example/detail_pmd.json
180
+ - spec/assets/example/overview_android_lint.json
181
+ - spec/assets/example/overview_detekt.json
182
+ - spec/assets/example/overview_pmd.json
183
+ - spec/assets/java.json
184
+ - spec/assets/java_all.json
185
+ - spec/assets/java_zero.json
186
+ - spec/assets/java_zero_new.json
187
+ - spec/spec_helper.rb
188
+ - spec/warnings_next_generation_spec.rb
189
+ homepage: https://github.com/Kyaak/danger-warnings_next_generation
190
+ licenses:
191
+ - MIT
192
+ metadata: {}
193
+ post_install_message:
194
+ rdoc_options: []
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: 2.3.0
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ requirements: []
208
+ rubygems_version: 3.0.3
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: Read Jenkins warnings-ng reports and comment pull request with found issues.
212
+ test_files:
213
+ - spec/assets/aggregation.json
214
+ - spec/assets/aggregation_single.json
215
+ - spec/assets/example/aggregation.json
216
+ - spec/assets/example/detail_android_lint.json
217
+ - spec/assets/example/detail_detekt.json
218
+ - spec/assets/example/detail_pmd.json
219
+ - spec/assets/example/overview_android_lint.json
220
+ - spec/assets/example/overview_detekt.json
221
+ - spec/assets/example/overview_pmd.json
222
+ - spec/assets/java.json
223
+ - spec/assets/java_all.json
224
+ - spec/assets/java_zero.json
225
+ - spec/assets/java_zero_new.json
226
+ - spec/spec_helper.rb
227
+ - spec/warnings_next_generation_spec.rb