danger-warnings_next_generation 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +32 -0
- data/.rubocop.yml +665 -0
- data/.travis.yml +34 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +165 -0
- data/Rakefile +28 -0
- data/danger-warnings_next_generation.gemspec +41 -0
- data/lib/danger_plugin.rb +3 -0
- data/lib/danger_warnings_next_generation.rb +3 -0
- data/lib/warnings_next_generation/gem_version.rb +5 -0
- data/lib/warnings_next_generation/markdown_table.rb +45 -0
- data/lib/warnings_next_generation/plugin.rb +214 -0
- data/sonar-project.properties +9 -0
- data/spec/assets/aggregation.json +53 -0
- data/spec/assets/aggregation_single.json +11 -0
- data/spec/assets/example/aggregation.json +23 -0
- data/spec/assets/example/detail_android_lint.json +78 -0
- data/spec/assets/example/detail_detekt.json +186 -0
- data/spec/assets/example/detail_pmd.json +5 -0
- data/spec/assets/example/overview_android_lint.json +43 -0
- data/spec/assets/example/overview_detekt.json +43 -0
- data/spec/assets/example/overview_pmd.json +29 -0
- data/spec/assets/java.json +36 -0
- data/spec/assets/java_all.json +150 -0
- data/spec/assets/java_zero.json +36 -0
- data/spec/assets/java_zero_new.json +36 -0
- data/spec/spec_helper.rb +72 -0
- data/spec/warnings_next_generation_spec.rb +248 -0
- metadata +227 -0
data/.travis.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
cache:
|
4
|
+
directories:
|
5
|
+
- bundle
|
6
|
+
|
7
|
+
before_install:
|
8
|
+
- gem update --system
|
9
|
+
- gem install bundler
|
10
|
+
|
11
|
+
rvm:
|
12
|
+
- 2.3
|
13
|
+
- 2.4
|
14
|
+
- 2.5
|
15
|
+
- 2.6
|
16
|
+
|
17
|
+
addons:
|
18
|
+
sonarcloud:
|
19
|
+
organization: "kyaak-github"
|
20
|
+
token:
|
21
|
+
secure: "oNSbUcGFI1VJAJug8zcuGCUStXR8Ou3qcVCjgfgMdEVDcopCZF428ws4YmOywK4D9xhH++bkdqRBiR7mr5kOlUP/VMTl8rBiHJm2XrJQnY9UqBflSbT3HRSkIbgh9gS1BrlOOsyAu6//TPdCsARwE2n/3iiyDfh7A5KdRaIXlY8NaPHk9iAB/+spYMxXeFCfhvHURHqYcr8lAyHaLda0Ph+l+qSut+AMzvUlnH9cQvM2+109+XbZo6YoHALNRgkgXMXF84N9RlhWfFBx3RR+jDFy8mPPy3+5pphyIEXQgxMZ6PUrte5jYsnno32FdA3ewl75NakXzTj+kZUqnrnteOBkZMSD5aU+9CZRqBgCZcBMjQ2fTUkGUL+m1rBdnpeBUtzvdHZW9rrOC51gHbA3twWR9aSzoS062ZVPskr0pssSq2zp69Zer0aKUiHHIfA5te+CdxSfE3BvDlxMCF/MGob3A2KBLl50CJLmk4UQtvs8/mtTW5t9MK3ai7/A/OsT/C2rQn8sMo6RtYNlAqzzpCdFiXpsYqVo2IfLtDatZ8Ti9srRLO2DsOUJW+vpYh4UgbH6A9mhtn/HInoJzNzlGLAJqFbpY9TnuD0cILYZIY2Jk2DlaL+a5//L9sT2Mz2nA1kwsPnIui9LwnK+RupUo9pfrjD9jeKaGolNz0qF0Bc="
|
22
|
+
|
23
|
+
script:
|
24
|
+
- bundle exec rake spec
|
25
|
+
- sonar-scanner
|
26
|
+
|
27
|
+
deploy:
|
28
|
+
provider: rubygems
|
29
|
+
api_key:
|
30
|
+
secure: "hGaoShdpKLUwc3HS3p6opjf6Z+/Ez2OLtco2RoavhyKavnPS1uUJ1XdfVp/2ZgW5LDPPpbq7EDRcnKK1dd/4WpDP/UMM2xxEKIhUhQrQPf9LvyTOUXyRird0aSmPYMmGReCIr5Bgg+BxL3AuagMxCUNWKADMLTEGd/7sbyTzf1Pv+XKNEnek+BdmmrQp/w/dOubn/vsjBGxqU3+barGxl/0ImGRlkDplv5VIqoZtf3l3LRNCQ4K4VX7hRveHv3hK6NpsKoqrcK9Uzj3GyGxrEnfnNiSlPa2oeohctJiDYk8fgcvTcckdVfMra+YNk2gpS/YeEC9dEbSsfPykeuZa/Ss+8O64bPg435Zj51AEzw9YgyezLHuN6KRtm8Hb73nL+8+1JW58OEzMCypG6KVcHHSf9Tir3hh0mgxCCrsHpblBNpGyiEKOFLdnsHuM0RotP4gC0R2OB7QRb4IVRhcvS5QDRi1WNwz4dzYe6WpWT4CGSsm/RpqfljtlLnDjHGCB5O3ybY4AYh3giueoDEKsr94q7y1Z0dXTbl+3UZi20vVBcakl4NFlbuoq4/zRpJYDGU2/qXV0molb030DIL+jQtfJkt08MveZJ/9pn4MbPQarDbNvpKyq4nuaqfYrS1NIAtkIYwROnl3GXxnocudDVuZCohNNaxpridnFgPSlD6k="
|
31
|
+
gem: danger-warnings_next_generation
|
32
|
+
on:
|
33
|
+
branch: master
|
34
|
+
rvm: 2.6
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2019 Martin Schwamberger <kyaak.dev@gmail.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
<h1 align="center">danger-warnings_next_generation</h1>
|
2
|
+
|
3
|
+
<div align="center">
|
4
|
+
<!-- Sonar Cloud -->
|
5
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
6
|
+
<img src="https://sonarcloud.io/images/project_badges/sonarcloud-white.svg"
|
7
|
+
alt="Sonar Cloud" />
|
8
|
+
</a>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
</br>
|
12
|
+
|
13
|
+
<div align="center">
|
14
|
+
<!-- Version -->
|
15
|
+
<a href="https://badge.fury.io/rb/danger-warnings_next_generation">
|
16
|
+
<img src="https://badge.fury.io/rb/danger-warnings.svg" alt="Version" />
|
17
|
+
</a>
|
18
|
+
<!-- Downloads -->
|
19
|
+
<a href="https://badge.fury.io/rb/danger-warnings_next_generation">
|
20
|
+
<img src="https://img.shields.io/gem/dt/danger-warnings.svg" alt="Downloads" />
|
21
|
+
</a>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div align="center">
|
25
|
+
<!-- Build Status -->
|
26
|
+
<a href="https://travis-ci.org/Kyaak/danger-warnings_next_generation">
|
27
|
+
<img src="https://img.shields.io/travis/choojs/choo/develop.svg"
|
28
|
+
alt="Build Status" />
|
29
|
+
</a>
|
30
|
+
<!-- Coverage -->
|
31
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
32
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=coverage"
|
33
|
+
alt="Coverage" />
|
34
|
+
</a>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div align="center">
|
38
|
+
<!-- Reliability Rating -->
|
39
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
40
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=reliability_rating"
|
41
|
+
alt="Reliability Rating" />
|
42
|
+
</a>
|
43
|
+
<!-- Security Rating -->
|
44
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
45
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=security_rating"
|
46
|
+
alt="Security Rating" />
|
47
|
+
</a>
|
48
|
+
<!-- Maintainabiltiy -->
|
49
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
50
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=sqale_rating"
|
51
|
+
alt="Maintainabiltiy" />
|
52
|
+
</a>
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<div align="center">
|
56
|
+
<!-- Code Smells -->
|
57
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
58
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=code_smells"
|
59
|
+
alt="Code Smells" />
|
60
|
+
</a>
|
61
|
+
<!-- Bugs -->
|
62
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
63
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=bugs"
|
64
|
+
alt="Bugs" />
|
65
|
+
</a>
|
66
|
+
<!-- Vulnerabilities -->
|
67
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
68
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=vulnerabilities"
|
69
|
+
alt="Vulnerabilities" />
|
70
|
+
</a>
|
71
|
+
<!-- Technical Dept -->
|
72
|
+
<a href="https://sonarcloud.io/dashboard?id=Kyaak_danger-warnings_next_generation">
|
73
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=Kyaak_danger-warnings_next_generation&metric=sqale_index"
|
74
|
+
alt="Technical Dept" />
|
75
|
+
</a>
|
76
|
+
</div>
|
77
|
+
</br>
|
78
|
+
|
79
|
+
This [danger](https://github.com/danger/danger) plugin generates overview and detail reports for code analysis results. :detective: <br>
|
80
|
+
|
81
|
+
This plugin is inspired and works only with the jenkins [warnings-ng-plugin](https://github.com/jenkinsci/warnings-ng-plugin) :bowing_man:
|
82
|
+
|
83
|
+
|
84
|
+
To avoid an overload of issues in the pull request, only issues for changed files are listed.
|
85
|
+
The overview report will always contain the number of total, new and fixed issues.
|
86
|
+
|
87
|
+
|
88
|
+
## How it looks like
|
89
|
+
|
90
|
+
### Warnings Next Generation Overview
|
91
|
+
|
92
|
+
|**Tool**|:beetle:|:x:|:white_check_mark:|
|
93
|
+
|:---|:---:|:---:|:---:|
|
94
|
+
|Android Lint Warnings|10|0|3|
|
95
|
+
|PMD Warnings|:star:|0|0|
|
96
|
+
|Detekt Warnings|10|5|5|
|
97
|
+
|Checkstyle|:star:|0|3|
|
98
|
+
|
99
|
+
### Java Warnings
|
100
|
+
|
101
|
+
|**Severity**|**File**|**Description**|
|
102
|
+
|---|---|---|
|
103
|
+
|NORMAL|ProductDetailPageFragment.kt:135|[Deprecation] 'getColor(Int): Int' is deprecated. Deprecated in Java|
|
104
|
+
|NORMAL|ImageGalleryFragment.kt:40|[] Type mismatch: inferred type is java.util.ArrayList<String!>? but kotlin.collections.ArrayList<String> /* = java.util.ArrayList<String> */ was expected|
|
105
|
+
|NORMAL|ImageGalleryFragment.kt:87|[Deprecation] 'getColor(Int): Int' is deprecated. Deprecated in Java|
|
106
|
+
|NORMAL|ImageGalleryFragment.kt:90|[Deprecation] 'getColor(Int): Int' is deprecated. Deprecated in Java|
|
107
|
+
|
108
|
+
|
109
|
+
### As inline
|
110
|
+
```text
|
111
|
+
NORMAL
|
112
|
+
[Deprecation]
|
113
|
+
getColor(Int): Int' is deprecated. Deprecated in Java
|
114
|
+
```
|
115
|
+
|
116
|
+
## Installation
|
117
|
+
|
118
|
+
$ gem install danger-warnings_next_generation
|
119
|
+
|
120
|
+
## Usage
|
121
|
+
|
122
|
+
<blockquote>Show overview and tool reports for all found analytic tools.
|
123
|
+
<pre>
|
124
|
+
warnings_next_generation.report
|
125
|
+
</pre>
|
126
|
+
</blockquote>
|
127
|
+
|
128
|
+
<blockquote>Show overview and tool reports for selected analytic tools
|
129
|
+
<pre>
|
130
|
+
warnings_next_generation.report(
|
131
|
+
# must match tool id
|
132
|
+
include: ['android-lint', 'java', 'pmd']
|
133
|
+
)
|
134
|
+
</pre>
|
135
|
+
</blockquote>
|
136
|
+
|
137
|
+
<blockquote>Show overview and tool reports with inline comments
|
138
|
+
<pre>
|
139
|
+
warnings_next_generation.report(
|
140
|
+
inline: true,
|
141
|
+
# inline comments require a baseline
|
142
|
+
# file: "/var/lib/jenkins/workspace/projectname/repository/app/src/main/java/com/projectname/b2bshop/fragment/gallery/ImageGalleryFragment.kt
|
143
|
+
# baseline: "/var/lib/jenkins/workspace/projectname/repository/
|
144
|
+
baseline: '/path/to/workspace/repository/root'
|
145
|
+
)
|
146
|
+
</pre>
|
147
|
+
</blockquote>
|
148
|
+
|
149
|
+
<blockquote>Only overview report
|
150
|
+
<pre>
|
151
|
+
warnings_next_generation.overview_report(
|
152
|
+
include: ['java']
|
153
|
+
)
|
154
|
+
</pre>
|
155
|
+
</blockquote>
|
156
|
+
|
157
|
+
<blockquote>Only tools report
|
158
|
+
<pre>
|
159
|
+
warnings_next_generation.tools_report(
|
160
|
+
include: ['java', 'pmd']
|
161
|
+
inline: true,
|
162
|
+
baseline: '/path/to/workspace/repository/root'
|
163
|
+
)
|
164
|
+
</pre>
|
165
|
+
</blockquote>
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "rubocop/rake_task"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:specs)
|
8
|
+
|
9
|
+
task default: :specs
|
10
|
+
|
11
|
+
task :spec do
|
12
|
+
Rake::Task["specs"].invoke
|
13
|
+
Rake::Task["rubocop"].invoke
|
14
|
+
Rake::Task["spec_docs"].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run RuboCop on the lib/specs directory"
|
18
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
19
|
+
task.patterns = %w(lib/**/*.rb spec/**/*.rb)
|
20
|
+
task.fail_on_error = false
|
21
|
+
task.formatters = %w(simple json)
|
22
|
+
task.options = %w(--out rubocop-result.json)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Ensure that the plugin passes `danger plugins lint`"
|
26
|
+
task :spec_docs do
|
27
|
+
sh "bundle exec danger plugins lint"
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path("lib", __dir__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require "warnings_next_generation/gem_version.rb"
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "danger-warnings_next_generation"
|
10
|
+
spec.version = WarningsNextGeneration::VERSION
|
11
|
+
spec.authors = ["Martin Schwamberger"]
|
12
|
+
spec.email = ["kyaak.dev@gmail.com"]
|
13
|
+
spec.description = "Danger plugin to for Jenkins-Warnings-Next-Generation plugin."
|
14
|
+
spec.summary = "Read Jenkins warnings-ng reports and comment pull request with found issues."
|
15
|
+
spec.homepage = "https://github.com/Kyaak/danger-warnings_next_generation"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.required_ruby_version = ">=2.3.0"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
|
26
|
+
|
27
|
+
# General ruby development
|
28
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
29
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
30
|
+
|
31
|
+
# Testing support
|
32
|
+
spec.add_development_dependency "mocha", "~> 1.8"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
34
|
+
spec.add_development_dependency "simplecov", "~> 0.16"
|
35
|
+
spec.add_development_dependency "simplecov-console", "~> 0.4"
|
36
|
+
|
37
|
+
# Linting code and docs
|
38
|
+
spec.add_development_dependency "rubocop", "~> 0.68"
|
39
|
+
spec.add_development_dependency "rubocop-performance", "~> 1.2"
|
40
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
41
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WarningsNextGeneration
|
4
|
+
class MarkdownTable
|
5
|
+
COLUMN_SEPARATOR = "|"
|
6
|
+
HEADER_SEPARATOR = "-"
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@header = COLUMN_SEPARATOR.dup
|
10
|
+
@header_separator = COLUMN_SEPARATOR.dup
|
11
|
+
@lines = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def overview_header(*args)
|
15
|
+
args.each_with_index do |item, index|
|
16
|
+
@header << "#{item}#{COLUMN_SEPARATOR}"
|
17
|
+
@header_separator << if index.zero?
|
18
|
+
":#{HEADER_SEPARATOR}#{COLUMN_SEPARATOR}"
|
19
|
+
else
|
20
|
+
":#{HEADER_SEPARATOR}:#{COLUMN_SEPARATOR}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def detail_header(*args)
|
26
|
+
args.each do |item|
|
27
|
+
@header << "#{item}#{COLUMN_SEPARATOR}"
|
28
|
+
@header_separator << "#{HEADER_SEPARATOR}#{COLUMN_SEPARATOR}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def line(*args)
|
33
|
+
line = COLUMN_SEPARATOR.dup
|
34
|
+
args.each do |item|
|
35
|
+
line << "#{item}#{COLUMN_SEPARATOR}"
|
36
|
+
end
|
37
|
+
@lines << line
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_markdown
|
41
|
+
result = +"#{@header}\n#{@header_separator}\n"
|
42
|
+
result << @lines.join("\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
# Generate code analysis reports on pull requests based on jenkins warnings-next-generation-plugin.
|
5
|
+
#
|
6
|
+
# @example Generate overview and tool reports for all code coverage tools.
|
7
|
+
# warnings_next_generation.report
|
8
|
+
#
|
9
|
+
# @example Generate only overview report.
|
10
|
+
# warnings_next_generation.overview_report
|
11
|
+
#
|
12
|
+
# @example Generate table of issues for all tools.
|
13
|
+
# warnings_next_generation.tools_report
|
14
|
+
#
|
15
|
+
# @example Include only specific tools.
|
16
|
+
# warnings_next_generation.tools_report(include: ['java', 'android-lint'])
|
17
|
+
#
|
18
|
+
# @example Create inline comments instead of issue table.
|
19
|
+
# warnings_next_generation.tools_report(inline: true, baseline: 'path/to/workspace/repository')
|
20
|
+
#
|
21
|
+
# @see Kyaak/danger-warnings_next_generation
|
22
|
+
# @tags danger, warnings, jenkins, warnings-ng, warnings-next-generation, code-analysis, analysis
|
23
|
+
class DangerWarningsNextGeneration < Plugin
|
24
|
+
require "json"
|
25
|
+
require "open-uri"
|
26
|
+
require_relative "markdown_table"
|
27
|
+
|
28
|
+
EMOJI_BEETLE = ":beetle:"
|
29
|
+
EMOJI_X = ":x:"
|
30
|
+
EMOJI_CHECK_MARK = ":white_check_mark:"
|
31
|
+
EMOJI_STAR = ":star:"
|
32
|
+
TABLE_HEADER_TOOL = "**Tool**"
|
33
|
+
TABLE_HEADER_FILE = "**File**"
|
34
|
+
TABLE_HEADER_SEVERITY = "**Severity**"
|
35
|
+
TABLE_HEADER_DESCRIPTION = "**Description**"
|
36
|
+
WNG_OVERVIEW_TITLE = "### Warnings Next Generation Overview"
|
37
|
+
|
38
|
+
def initialize(dangerfile)
|
39
|
+
@target_files = []
|
40
|
+
super(dangerfile)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create all reports.
|
44
|
+
# Passes arguments to each report.
|
45
|
+
#
|
46
|
+
# @param args Configuration settings
|
47
|
+
# @return [void]
|
48
|
+
def report(*args)
|
49
|
+
options = args.first
|
50
|
+
overview_report(options)
|
51
|
+
tools_report(options)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Create an overview report.
|
55
|
+
#
|
56
|
+
# @param args Configuration settings
|
57
|
+
# @return [void]
|
58
|
+
def overview_report(*args)
|
59
|
+
overview_table = WarningsNextGeneration::MarkdownTable.new
|
60
|
+
overview_table.overview_header(TABLE_HEADER_TOOL, EMOJI_BEETLE, EMOJI_X, EMOJI_CHECK_MARK)
|
61
|
+
options = args.first
|
62
|
+
tool_ids = include(options)
|
63
|
+
entry_count = 0
|
64
|
+
|
65
|
+
tools = tool_entries
|
66
|
+
tools.each do |tool|
|
67
|
+
name = tool["name"]
|
68
|
+
url = tool["latestUrl"]
|
69
|
+
id = tool["id"]
|
70
|
+
|
71
|
+
if use_include_option?(options)
|
72
|
+
next unless tool_ids.include?(id)
|
73
|
+
end
|
74
|
+
overview = overview_result(url)
|
75
|
+
entry_count += 1
|
76
|
+
overview_entry(overview_table, name, overview)
|
77
|
+
end
|
78
|
+
|
79
|
+
if use_include_option?(options)
|
80
|
+
return if entry_count.zero?
|
81
|
+
end
|
82
|
+
markdown("#{WNG_OVERVIEW_TITLE}\n\n#{overview_table.to_markdown}")
|
83
|
+
end
|
84
|
+
|
85
|
+
# Create tools reports.
|
86
|
+
#
|
87
|
+
# @param args Configuration settings
|
88
|
+
# @return [void]
|
89
|
+
def tools_report(*args)
|
90
|
+
options = args.first
|
91
|
+
tool_ids = include(options)
|
92
|
+
|
93
|
+
tools = tool_entries
|
94
|
+
tools.each do |tool|
|
95
|
+
name = tool["name"]
|
96
|
+
url = tool["latestUrl"]
|
97
|
+
id = tool["id"]
|
98
|
+
|
99
|
+
if use_include_option?(options)
|
100
|
+
next unless tool_ids.include?(id)
|
101
|
+
end
|
102
|
+
if inline?(options) && check_baseline(options)
|
103
|
+
inline_report(url, baseline(options))
|
104
|
+
else
|
105
|
+
tool_table(name, url)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def include(options)
|
113
|
+
options && !options[:include].nil? ? options[:include] : []
|
114
|
+
end
|
115
|
+
|
116
|
+
def inline?(options)
|
117
|
+
options && !options[:inline].nil? ? options[:inline] : false
|
118
|
+
end
|
119
|
+
|
120
|
+
def baseline(options)
|
121
|
+
base = options && !options[:baseline].nil? ? options[:baseline] : nil
|
122
|
+
if base && !base.chars.last.eql?("/")
|
123
|
+
base << "/"
|
124
|
+
end
|
125
|
+
base
|
126
|
+
end
|
127
|
+
|
128
|
+
def check_baseline(options)
|
129
|
+
raise "Please set 'baseline' for correct inline comments." unless baseline(options)
|
130
|
+
|
131
|
+
true
|
132
|
+
end
|
133
|
+
|
134
|
+
def use_include_option?(options)
|
135
|
+
!options.nil? && !options[:include].nil?
|
136
|
+
end
|
137
|
+
|
138
|
+
def tool_table(name, url)
|
139
|
+
details = details_result(url)
|
140
|
+
issues = details["issues"]
|
141
|
+
|
142
|
+
table = WarningsNextGeneration::MarkdownTable.new
|
143
|
+
table.detail_header(TABLE_HEADER_SEVERITY, TABLE_HEADER_FILE, TABLE_HEADER_DESCRIPTION)
|
144
|
+
issues.each do |issue|
|
145
|
+
severity = issue["severity"]
|
146
|
+
file = File.basename(issue["fileName"])
|
147
|
+
line = issue["lineStart"]
|
148
|
+
message = issue["message"]
|
149
|
+
category = issue["category"]
|
150
|
+
table.line(severity, "#{file}:#{line}", "[#{category}] #{message}")
|
151
|
+
end
|
152
|
+
content = +"### #{name}\n\n"
|
153
|
+
content << table.to_markdown
|
154
|
+
markdown(content)
|
155
|
+
end
|
156
|
+
|
157
|
+
def inline_report(url, baseline)
|
158
|
+
details = details_result(url)
|
159
|
+
issues = details["issues"]
|
160
|
+
|
161
|
+
issues.each do |issue|
|
162
|
+
severity = issue["severity"]
|
163
|
+
file = issue["fileName"].gsub(baseline, "")
|
164
|
+
line = issue["lineStart"]
|
165
|
+
message = issue["message"]
|
166
|
+
category = issue["category"]
|
167
|
+
|
168
|
+
next unless file_in_changeset?(file)
|
169
|
+
|
170
|
+
inline_message = "#{severity}\n[#{category}]\n#{message}"
|
171
|
+
message(inline_message, file: file, line: line)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def tool_entries
|
176
|
+
json = aggregation_result
|
177
|
+
json["tools"]
|
178
|
+
end
|
179
|
+
|
180
|
+
def overview_entry(table, name, overview)
|
181
|
+
fixed = overview["fixedSize"]
|
182
|
+
new = overview["newSize"]
|
183
|
+
total = overview["totalSize"]
|
184
|
+
table.line(name, num_star(total), new, fixed)
|
185
|
+
end
|
186
|
+
|
187
|
+
def file_in_changeset?(file)
|
188
|
+
target_files.include?(file)
|
189
|
+
end
|
190
|
+
|
191
|
+
def target_files
|
192
|
+
@target_files ||= git.modified_files + git.added_files
|
193
|
+
end
|
194
|
+
|
195
|
+
def num_star(number)
|
196
|
+
number.to_i.zero? ? EMOJI_STAR : number
|
197
|
+
end
|
198
|
+
|
199
|
+
def details_result(url)
|
200
|
+
content = OpenURI.open("#{url}/all/api/json").read
|
201
|
+
JSON.parse(content)
|
202
|
+
end
|
203
|
+
|
204
|
+
def overview_result(url)
|
205
|
+
content = OpenURI.open("#{url}/api/json").read
|
206
|
+
JSON.parse(content)
|
207
|
+
end
|
208
|
+
|
209
|
+
def aggregation_result
|
210
|
+
content = OpenURI.open("#{ENV['BUILD_URL']}/warnings-ng/api/json").read
|
211
|
+
JSON.parse(content)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
sonar.projectKey=Kyaak_danger-warnings_next_generation
|
2
|
+
sonar.sources=lib
|
3
|
+
sonar.tests=spec
|
4
|
+
|
5
|
+
sonar.ruby.file.suffixes=rb,ruby
|
6
|
+
sonar.ruby.coverage.reportPath=coverage/.resultset.json
|
7
|
+
sonar.ruby.coverage.framework=RSpec
|
8
|
+
sonar.ruby.rubocopConfig=.rubocop.yml
|
9
|
+
sonar.ruby.rubocop.reportPath=rubocop-result.json
|
@@ -0,0 +1,53 @@
|
|
1
|
+
{
|
2
|
+
"_class": "io.jenkins.plugins.analysis.core.restapi.AggregationApi",
|
3
|
+
"tools": [
|
4
|
+
{
|
5
|
+
"id": "maven",
|
6
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/maven",
|
7
|
+
"name": "Maven Warnings",
|
8
|
+
"threshold": 9
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"id": "java",
|
12
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/java",
|
13
|
+
"name": "Java Warnings",
|
14
|
+
"threshold": 1
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"id": "javadoc",
|
18
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/javadoc",
|
19
|
+
"name": "JavaDoc Warnings",
|
20
|
+
"threshold": 0
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"id": "checkstyle",
|
24
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/checkstyle",
|
25
|
+
"name": "CheckStyle Warnings",
|
26
|
+
"threshold": 0
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"id": "pmd",
|
30
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/pmd",
|
31
|
+
"name": "PMD Warnings",
|
32
|
+
"threshold": 671
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"id": "spotbugs",
|
36
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/spotbugs",
|
37
|
+
"name": "SpotBugs Warnings",
|
38
|
+
"threshold": 0
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"id": "cpd",
|
42
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/cpd",
|
43
|
+
"name": "CPD Warnings",
|
44
|
+
"threshold": 123
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"id": "open-tasks",
|
48
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/open-tasks",
|
49
|
+
"name": "Open Tasks Scanner Warnings",
|
50
|
+
"threshold": 11
|
51
|
+
}
|
52
|
+
]
|
53
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"_class": "io.jenkins.plugins.analysis.core.restapi.AggregationApi",
|
3
|
+
"tools": [
|
4
|
+
{
|
5
|
+
"id": "java",
|
6
|
+
"latestUrl": "http://localhost:8080/view/White%20Mountains/job/New%20-%20Pipeline%20-%20Simple%20Model/26/java",
|
7
|
+
"name": "Java Warnings",
|
8
|
+
"threshold": 1
|
9
|
+
}
|
10
|
+
]
|
11
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"_class": "io.jenkins.plugins.analysis.core.restapi.AggregationApi",
|
3
|
+
"tools": [
|
4
|
+
{
|
5
|
+
"id": "android-lint",
|
6
|
+
"latestUrl": "https://example-jenkins.de/job/danger/10/android-lint",
|
7
|
+
"name": "Android Lint Warnings",
|
8
|
+
"size": 4
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"id": "pmd",
|
12
|
+
"latestUrl": "https://example-jenkins.de/job/danger/10/pmd",
|
13
|
+
"name": "PMD Warnings",
|
14
|
+
"size": 0
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"id": "detekt",
|
18
|
+
"latestUrl": "https://example-jenkins.de/job/danger/10/detekt",
|
19
|
+
"name": "Detekt Warnings",
|
20
|
+
"size": 10
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|