danger-sonar 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/.gitignore +4 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +23 -0
- data/danger-sonar.gemspec +50 -0
- data/lib/danger_plugin.rb +1 -0
- data/lib/danger_sonar.rb +1 -0
- data/lib/sonar/gem_version.rb +3 -0
- data/lib/sonar/plugin.rb +261 -0
- data/spec/sonar_spec.rb +41 -0
- data/spec/spec_helper.rb +59 -0
- metadata +214 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 52aa585a26b951c8eb74168f47cd18ac5a8b76da
|
4
|
+
data.tar.gz: 36332b9a3bd110b7feaca6cae97670b7d8d48a90
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34f0cb7f72134c6d2b77c94bb1f1f3c021201eaf98d20e37ef65b5f2e9e32a259719e2a26010471edc96590c302e0cbac86b7e8020d31f0b0b4fca87ef329006
|
7
|
+
data.tar.gz: 2e407d24ce928eaeadeb4193ee4d87dfe8b08c706ad29d824bef00265b3f290e1e88a343d96592152b97bb55e2112affe955da7a569039c54c9f855f936f9afd
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# A guardfile for making Danger Plugins
|
2
|
+
# For more info see https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# To run, use `bundle exec guard`.
|
5
|
+
|
6
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
7
|
+
require 'guard/rspec/dsl'
|
8
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017 Manoj Babu <gmanojbabu@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,68 @@
|
|
1
|
+
# danger-sonar
|
2
|
+
|
3
|
+
A danger plugin to check for Sonar Qube violation.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install danger-sonar
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Methods and attributes from this plugin are available in
|
12
|
+
your `Dangerfile` under the `sonar` namespace.
|
13
|
+
|
14
|
+
Simply add below line to your Dangerfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
sonar.json_report_file = 'sonar-report.json'
|
18
|
+
sonar.lint_files
|
19
|
+
```
|
20
|
+
|
21
|
+
Pass below options to Sonar Scanner to generate JSON report
|
22
|
+
|
23
|
+
```sh
|
24
|
+
-Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json
|
25
|
+
```
|
26
|
+
The .json will be generated inside the .sonar directory.
|
27
|
+
|
28
|
+
For inline comments in your PR, add below line to your Dangerfile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
sonar.lint_files inline_mode:true
|
32
|
+
```
|
33
|
+
|
34
|
+
To lint selected files, add below line to your Dangerfile:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
sonar.lint_files [filename1, filename2, filename3,...]
|
38
|
+
```
|
39
|
+
|
40
|
+
To change messages, add below lines to your Dangerfile:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
sonar.failure_message = "Sonar lint fialed due to violations, fix them to merge your PR"
|
44
|
+
sonar.warning_message = "Fix Sonar violtions"
|
45
|
+
```
|
46
|
+
|
47
|
+
To write custom rules based on Sonar violations, use below properties to get violations count
|
48
|
+
```ruby
|
49
|
+
# To read blocker violations count
|
50
|
+
sonar.blocker_count
|
51
|
+
# To read critical violations count
|
52
|
+
sonar.critical_count
|
53
|
+
# To read major violations count
|
54
|
+
sonar.major_count
|
55
|
+
# To read minor violations count
|
56
|
+
sonar.minor_count > 0
|
57
|
+
```
|
58
|
+
|
59
|
+
## License
|
60
|
+
MIT
|
61
|
+
|
62
|
+
## Development
|
63
|
+
|
64
|
+
1. Clone this repo
|
65
|
+
2. Run `bundle install` to setup dependencies.
|
66
|
+
3. Run `bundle exec rake spec` to run the tests.
|
67
|
+
4. Use `bundle exec guard` to automatically have tests run as you make changes.
|
68
|
+
5. Make your changes.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:specs)
|
6
|
+
|
7
|
+
task default: :specs
|
8
|
+
|
9
|
+
task :spec do
|
10
|
+
Rake::Task['specs'].invoke
|
11
|
+
Rake::Task['rubocop'].invoke
|
12
|
+
Rake::Task['spec_docs'].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run RuboCop on the lib/specs directory'
|
16
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
17
|
+
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Ensure that the plugin passes `danger plugins lint`'
|
21
|
+
task :spec_docs do
|
22
|
+
sh 'bundle exec danger plugins lint'
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sonar/gem_version.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'danger-sonar'
|
8
|
+
spec.version = Sonar::VERSION
|
9
|
+
spec.authors = ['Manoj Babu']
|
10
|
+
spec.email = ['gmanojbabu@gmail.com']
|
11
|
+
spec.description = %q{A short description of danger-sonar.}
|
12
|
+
spec.summary = %q{A longer description of danger-sonar.}
|
13
|
+
spec.homepage = 'https://github.com/gmanojbabu/danger-sonar'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
|
22
|
+
spec.add_runtime_dependency 'git_diff_parser', '~> 3.2'
|
23
|
+
|
24
|
+
# General ruby development
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
|
28
|
+
# Testing support
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
30
|
+
|
31
|
+
# Linting code and docs
|
32
|
+
spec.add_development_dependency "rubocop", "~> 0.49.0"
|
33
|
+
spec.add_development_dependency "yard", "~> 0.9.11"
|
34
|
+
|
35
|
+
# Makes testing easy via `bundle exec guard`
|
36
|
+
spec.add_development_dependency 'guard', '~> 2.14'
|
37
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
38
|
+
|
39
|
+
# If you want to work on older builds of ruby
|
40
|
+
spec.add_development_dependency 'listen', '3.0.7'
|
41
|
+
|
42
|
+
# This gives you the chance to run a REPL inside your tests
|
43
|
+
# via:
|
44
|
+
#
|
45
|
+
# require 'pry'
|
46
|
+
# binding.pry
|
47
|
+
#
|
48
|
+
# This will stop test execution and let you inspect the results
|
49
|
+
spec.add_development_dependency 'pry', '~> 0'
|
50
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sonar/plugin'
|
data/lib/danger_sonar.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sonar/gem_version'
|
data/lib/sonar/plugin.rb
ADDED
@@ -0,0 +1,261 @@
|
|
1
|
+
require 'find'
|
2
|
+
require 'json'
|
3
|
+
require 'shellwords'
|
4
|
+
require 'git_diff_parser'
|
5
|
+
|
6
|
+
module Danger
|
7
|
+
|
8
|
+
# Analyse Sonar JSON report.
|
9
|
+
# JSON report is generated using [SonarQube Scanner](https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner) tool.
|
10
|
+
# Results are passed out as a table in markdown.
|
11
|
+
#
|
12
|
+
# @example Specifying Sonar JSON report file.
|
13
|
+
#
|
14
|
+
# # Runs a linter with comma style disabled
|
15
|
+
# sonar.json_report_file = 'sonar_report.json'
|
16
|
+
# sonar.lint_files
|
17
|
+
#
|
18
|
+
# @see gmanojbabu
|
19
|
+
# @tags swift, sonar, danger
|
20
|
+
#
|
21
|
+
class DangerSonar < Plugin
|
22
|
+
|
23
|
+
# The path to Sonar report JSON file
|
24
|
+
attr_accessor :json_report_file
|
25
|
+
|
26
|
+
# The path to Sonar configuration file
|
27
|
+
attr_accessor :config_file
|
28
|
+
|
29
|
+
# By default this plugin compairs each line in modifiled file against sonar issue line no, to turn off set this property to true, to check for file match
|
30
|
+
attr_accessor :ignore_file_line_change_check
|
31
|
+
|
32
|
+
attr_accessor :failure_message
|
33
|
+
|
34
|
+
attr_accessor :warning_message
|
35
|
+
|
36
|
+
# Total Sonar blocker issues found in PR changes
|
37
|
+
attr_accessor :blocker_count
|
38
|
+
|
39
|
+
# Total Sonar critical issues found in PR changes
|
40
|
+
attr_accessor :critical_count
|
41
|
+
|
42
|
+
# Total Sonar major issues found in PR changes
|
43
|
+
attr_accessor :major_count
|
44
|
+
|
45
|
+
# Total Sonar minor issues found in PR changes
|
46
|
+
attr_accessor :minor_count
|
47
|
+
|
48
|
+
# Total Sonar info issues found in PR changes
|
49
|
+
attr_accessor :info_count
|
50
|
+
|
51
|
+
# Lints Swift files.
|
52
|
+
# Generates a `markdown` list of issues(Blocker, Major, Minor, Info) for the prose in a corpus of .markdown and .md files.
|
53
|
+
#
|
54
|
+
# @param [String] files
|
55
|
+
# A globbed string which should return the files that you want to lint, defaults to nil.
|
56
|
+
# if nil, modified and added files from the diff will be used.
|
57
|
+
# @return [void]
|
58
|
+
#
|
59
|
+
def lint_files(files=nil, inline_mode: false)
|
60
|
+
# Fails if invalid JSON report file isn't installed
|
61
|
+
raise "Sonar report file name is empty" unless !json_report_file.empty?
|
62
|
+
|
63
|
+
# Extract excluded paths
|
64
|
+
excluded_paths = excluded_files_from_config(config_file)
|
65
|
+
|
66
|
+
# Extract swift files (ignoring excluded ones)
|
67
|
+
files = find_files(files, excluded_paths)
|
68
|
+
|
69
|
+
|
70
|
+
#file = File.read(json_report_file)
|
71
|
+
#sonar_report_data = JSON.parse(file)
|
72
|
+
|
73
|
+
# Prepare options
|
74
|
+
options = {
|
75
|
+
report: File.expand_path(json_report_file),
|
76
|
+
config: config_file
|
77
|
+
}
|
78
|
+
|
79
|
+
# Lint each file and collect the results
|
80
|
+
issues = analyse_sonar_report(files, options)
|
81
|
+
puts "Issues: #{issues}"
|
82
|
+
|
83
|
+
# Filter warnings and errors
|
84
|
+
blockers = issues.select { |issue| issue['severity'] == 'BLOCKER' }
|
85
|
+
citicals = issues.select { |issue| issue['severity'] == 'CRITICAL' }
|
86
|
+
majors = issues.select { |issue| issue['severity'] == 'MAJOR' }
|
87
|
+
minors = issues.select { |issue| issue['severity'] == 'MINOR' }
|
88
|
+
infos = issues.select { |issue| issue['severity'] == 'INFO' }
|
89
|
+
|
90
|
+
@blocker_count = if blockers.nil? then 0 else blockers.length end
|
91
|
+
@critical_count = if citicals.nil? then 0 else citicals.length end
|
92
|
+
@major_count = if majors.nil? then 0 else majors.length end
|
93
|
+
@minor_count = if minors.nil? then 0 else minors.length end
|
94
|
+
@info_count = if infos.nil? then 0 else infos.length end
|
95
|
+
|
96
|
+
if inline_mode
|
97
|
+
# Reprt with inline comment
|
98
|
+
send_inline_comment(blockers, "fail") unless blockers.empty?
|
99
|
+
send_inline_comment(citicals, "fail") unless citicals.empty?
|
100
|
+
send_inline_comment(majors, "fail") unless majors.empty?
|
101
|
+
send_inline_comment(minors, "warn") unless minors.empty?
|
102
|
+
send_inline_comment(infos, "warn") unless infos.empty?
|
103
|
+
else
|
104
|
+
# Report if any blockers or citicals or majors or minors or infos
|
105
|
+
if blockers.count > 0 || citicals.count > 0 || majors.count > 0 || minors.count > 0 || infos.count > 0
|
106
|
+
message = "### Sonar found issues top 50 in Blocker, Citical, Major, Minor and Info\n\n"
|
107
|
+
message << markdown_issues(blockers[0,49], 'Blocker') unless blockers.empty?
|
108
|
+
message << markdown_issues(citicals[0,49], 'Critical') unless citicals.empty?
|
109
|
+
message << markdown_issues(majors[0,49], 'Major') unless majors.empty?
|
110
|
+
message << markdown_issues(minors[0,49], 'Minor') unless minors.empty?
|
111
|
+
message << markdown_issues(infos[0,49], 'Info') unless infos.empty?
|
112
|
+
puts message
|
113
|
+
markdown message
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
if failure_message && (blockers.count > 0 || citicals.count > 0 || majors.count > 0)
|
118
|
+
fail(failure_message, sticky: false)
|
119
|
+
else
|
120
|
+
if warning_message && (minors.count > 0 || infos.count > 0)
|
121
|
+
fail(failure_message, sticky: false)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Analyses Sonar Report and finds files that has sonar issues
|
127
|
+
#
|
128
|
+
# @return [Array] sonar issues
|
129
|
+
def analyse_sonar_report(files, options)
|
130
|
+
issues = parse_sonar_report(options[:report])
|
131
|
+
# Filter issues that are part of modified files
|
132
|
+
issues = issues_in_files_patch(issues)
|
133
|
+
end
|
134
|
+
|
135
|
+
def issues_in_files_patch(issues)
|
136
|
+
files_patch_info = get_files_patch_info()
|
137
|
+
if ignore_file_line_change_check
|
138
|
+
return issues.select { |i| files_patch_info.keys.detect{ |k| k.to_s =~ /#{i['file']}/ } }
|
139
|
+
else
|
140
|
+
return issues.select do |i|
|
141
|
+
key = files_patch_info.keys.detect{ |k| k.include?(i['file']) }
|
142
|
+
key != nil && (files_patch_info["#{key}"] != nil && (i['line'].to_s.empty? || files_patch_info["#{key}"].include?(i['line'].to_i)))
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_files_patch_info()
|
148
|
+
modified_files_info = Hash.new
|
149
|
+
updated_files = (git.modified_files - git.deleted_files) + git.added_files
|
150
|
+
updated_files.each {|file|
|
151
|
+
file_info = git.diff_for_file(file)
|
152
|
+
file_patches = GitDiffParser.parse(file_info.patch)
|
153
|
+
file_patches.each do |patch|
|
154
|
+
if modified_files_info["#{File.expand_path(file)}"] == nil
|
155
|
+
modified_files_info[File.expand_path(file)] = Array(patch.changed_line_numbers)
|
156
|
+
else
|
157
|
+
modified_files_info[File.expand_path(file)].push(patch.changed_line_numbers)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
}
|
161
|
+
modified_files_info
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
def parse_sonar_report(report_file)
|
167
|
+
file = File.read(report_file)
|
168
|
+
sonar_report_data = JSON.parse(file)
|
169
|
+
issues = Array.new
|
170
|
+
sonar_report_data["issues"].each {|i|
|
171
|
+
issue = {}
|
172
|
+
issue["file"] = i["component"].to_s.split(":").last
|
173
|
+
issue["line"] = i["line"].to_s
|
174
|
+
issue['reason'] = i["message"].to_s
|
175
|
+
issue['severity'] = i["severity"].to_s
|
176
|
+
issue['isNew'] = i["isNew"].to_s
|
177
|
+
issue['startLine'] = i["startLine"].to_s
|
178
|
+
issue['endLine'] = i["endLine"].to_s
|
179
|
+
issue['status'] = i["status"].to_s
|
180
|
+
issues.push(issue)
|
181
|
+
}
|
182
|
+
return issues.
|
183
|
+
select {|issue| issue["isNew"] == "true" && issue["status"] == "OPEN"}
|
184
|
+
end
|
185
|
+
|
186
|
+
# Find swift files from the files glob
|
187
|
+
# If files are not provided it will use git modifield and added files
|
188
|
+
#
|
189
|
+
# @return [Array] swift files
|
190
|
+
def find_files(files=nil, excluded_paths=[])
|
191
|
+
# Assign files to lint
|
192
|
+
files = files ? Dir.glob(files) : (git.modified_files - git.deleted_files) + git.added_files
|
193
|
+
|
194
|
+
# Filter files to lint
|
195
|
+
return files.
|
196
|
+
# Make sure we don't fail when paths have spaces
|
197
|
+
map { |file| Shellwords.escape(file) }.
|
198
|
+
# Remove dups
|
199
|
+
uniq.
|
200
|
+
map { |file| File.expand_path(file) }.
|
201
|
+
# Reject files excluded on configuration
|
202
|
+
reject { |file|
|
203
|
+
excluded_paths.any? { |excluded_path|
|
204
|
+
Find.find(excluded_path).
|
205
|
+
map { |excluded_file| Shellwords.escape(excluded_file) }.
|
206
|
+
include?(file)
|
207
|
+
}
|
208
|
+
}
|
209
|
+
end
|
210
|
+
|
211
|
+
# Parses the configuration file and return the excluded files
|
212
|
+
#
|
213
|
+
# @return [Array] list of files excluded
|
214
|
+
def excluded_files_from_config(filepath)
|
215
|
+
config = if filepath
|
216
|
+
YAML.load_file(config_file)
|
217
|
+
else
|
218
|
+
{"excluded" => []}
|
219
|
+
end
|
220
|
+
|
221
|
+
excluded_paths = config['excluded'] || []
|
222
|
+
|
223
|
+
# Extract excluded paths
|
224
|
+
return excluded_paths.
|
225
|
+
map { |path| File.join(File.dirname(config_file), path) }.
|
226
|
+
map { |path| File.expand_path(path) }.
|
227
|
+
select { |path| File.exists?(path) || Dir.exists?(path) }
|
228
|
+
end
|
229
|
+
|
230
|
+
# Create a markdown table from Sonar issues
|
231
|
+
#
|
232
|
+
# @return [String]
|
233
|
+
def markdown_issues (results, heading)
|
234
|
+
message = "#### #{heading}\n\n"
|
235
|
+
|
236
|
+
message << "File | Line | Reason |\n"
|
237
|
+
message << "| --- | ----- | ----- |\n"
|
238
|
+
puts "Markdown resutls: #{results}"
|
239
|
+
results.each do |r|
|
240
|
+
filename = r['file'].split('/').last
|
241
|
+
line = r['line']
|
242
|
+
reason = r['reason']
|
243
|
+
|
244
|
+
message << "#{filename} | #{line} | #{reason} \n"
|
245
|
+
end
|
246
|
+
|
247
|
+
message
|
248
|
+
end
|
249
|
+
|
250
|
+
# Send inline comment with danger's warn or fail method
|
251
|
+
#
|
252
|
+
# @return [void]
|
253
|
+
def send_inline_comment (results, method)
|
254
|
+
dir = "#{Dir.pwd}/"
|
255
|
+
results.each do |r|
|
256
|
+
filename = r['file'].gsub(dir, "")
|
257
|
+
send(method, r['reason'], file: filename, line: r['line'])
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
data/spec/sonar_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
describe Danger::DangerSonar do
|
5
|
+
it 'should be a plugin' do
|
6
|
+
expect(Danger::DangerSonar.new(nil)).to be_a Danger::Plugin
|
7
|
+
end
|
8
|
+
|
9
|
+
#
|
10
|
+
# You should test your custom attributes and methods here
|
11
|
+
#
|
12
|
+
describe 'with Dangerfile' do
|
13
|
+
before do
|
14
|
+
@dangerfile = testing_dangerfile
|
15
|
+
@my_plugin = @dangerfile.sonar
|
16
|
+
end
|
17
|
+
|
18
|
+
# Some examples for writing tests
|
19
|
+
# You should replace these with your own.
|
20
|
+
|
21
|
+
it "Warns on a monday" do
|
22
|
+
monday_date = Date.parse("2016-07-11")
|
23
|
+
allow(Date).to receive(:today).and_return monday_date
|
24
|
+
|
25
|
+
@my_plugin.warn_on_mondays
|
26
|
+
|
27
|
+
expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"])
|
28
|
+
end
|
29
|
+
|
30
|
+
it "Does nothing on a tuesday" do
|
31
|
+
monday_date = Date.parse("2016-07-12")
|
32
|
+
allow(Date).to receive(:today).and_return monday_date
|
33
|
+
|
34
|
+
@my_plugin.warn_on_mondays
|
35
|
+
|
36
|
+
expect(@dangerfile.status_report[:warnings]).to eq([])
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
|
3
|
+
$:.unshift((ROOT + 'lib').to_s)
|
4
|
+
$:.unshift((ROOT + 'spec').to_s)
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
require 'rspec'
|
10
|
+
require 'danger'
|
11
|
+
|
12
|
+
# Use coloured output, it's the best.
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.filter_gems_from_backtrace "bundler"
|
15
|
+
config.color = true
|
16
|
+
config.tty = true
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'danger_plugin'
|
20
|
+
|
21
|
+
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
22
|
+
# If you are expanding these files, see if it's already been done ^.
|
23
|
+
|
24
|
+
# A silent version of the user interface,
|
25
|
+
# it comes with an extra function `.string` which will
|
26
|
+
# strip all ANSI colours from the string.
|
27
|
+
|
28
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
29
|
+
def testing_ui
|
30
|
+
@output = StringIO.new
|
31
|
+
def @output.winsize
|
32
|
+
[20, 9999]
|
33
|
+
end
|
34
|
+
|
35
|
+
cork = Cork::Board.new(out: @output)
|
36
|
+
def cork.string
|
37
|
+
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
38
|
+
end
|
39
|
+
cork
|
40
|
+
end
|
41
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
42
|
+
|
43
|
+
# Example environment (ENV) that would come from
|
44
|
+
# running a PR on TravisCI
|
45
|
+
def testing_env
|
46
|
+
{
|
47
|
+
'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
|
48
|
+
'TRAVIS_PULL_REQUEST' => '800',
|
49
|
+
'TRAVIS_REPO_SLUG' => 'artsy/eigen',
|
50
|
+
'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
|
51
|
+
'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# A stubbed out Dangerfile for use in tests
|
56
|
+
def testing_dangerfile
|
57
|
+
env = Danger::EnvironmentManager.new(testing_env)
|
58
|
+
Danger::Dangerfile.new(env, testing_ui)
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danger-sonar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manoj Babu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-28 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: git_diff_parser
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
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.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
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.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.49.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.49.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.11
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.11
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.14'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.14'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '4.7'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '4.7'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: listen
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 3.0.7
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 3.0.7
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: A short description of danger-sonar.
|
168
|
+
email:
|
169
|
+
- gmanojbabu@gmail.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".travis.yml"
|
176
|
+
- Gemfile
|
177
|
+
- Guardfile
|
178
|
+
- LICENSE.txt
|
179
|
+
- README.md
|
180
|
+
- Rakefile
|
181
|
+
- danger-sonar.gemspec
|
182
|
+
- lib/danger_plugin.rb
|
183
|
+
- lib/danger_sonar.rb
|
184
|
+
- lib/sonar/gem_version.rb
|
185
|
+
- lib/sonar/plugin.rb
|
186
|
+
- spec/sonar_spec.rb
|
187
|
+
- spec/spec_helper.rb
|
188
|
+
homepage: https://github.com/gmanojbabu/danger-sonar
|
189
|
+
licenses:
|
190
|
+
- MIT
|
191
|
+
metadata: {}
|
192
|
+
post_install_message:
|
193
|
+
rdoc_options: []
|
194
|
+
require_paths:
|
195
|
+
- lib
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
requirements: []
|
207
|
+
rubyforge_project:
|
208
|
+
rubygems_version: 2.5.2.3
|
209
|
+
signing_key:
|
210
|
+
specification_version: 4
|
211
|
+
summary: A longer description of danger-sonar.
|
212
|
+
test_files:
|
213
|
+
- spec/sonar_spec.rb
|
214
|
+
- spec/spec_helper.rb
|