danger-ad_licenselint 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e1147bc11ec4609617531e4f35ded80e5ed823673b59553b240b71a7d02605f1
4
+ data.tar.gz: 9095eba40b60ae7a5154deb89aabf9c0be073220c51e3a71bed5776924600b45
5
+ SHA512:
6
+ metadata.gz: c9aaa770a433616ccd9a604bcaba1b6828c2a5356e798d08c0d9c0e7c1151c1904d5bda41e2c85413ee2fb24305c900b5d45e4a2ca023dbad6ef2dd898d9e2c1
7
+ data.tar.gz: 7705f712e7fdc1881a1b79105ea1c56ee1f975a0bd8603e803367f70666ab78b452d03204e19d2bbb83e5aa4030a7793d8770b5b05ab482e95dd99cbd932b825
data/.rubocop.yml ADDED
@@ -0,0 +1,152 @@
1
+ # Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+
3
+ # If you don't like these settings, just delete this file :)
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.0
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+ Enabled: true
11
+
12
+ # kind_of? is a good way to check a type
13
+ Style/ClassCheck:
14
+ EnforcedStyle: kind_of?
15
+
16
+ # It's better to be more explicit about the type
17
+ Style/BracesAroundHashParameters:
18
+ Enabled: false
19
+
20
+ # specs sometimes have useless assignments, which is fine
21
+ Lint/UselessAssignment:
22
+ Exclude:
23
+ - '**/spec/**/*'
24
+
25
+ # We could potentially enable the 2 below:
26
+ Layout/IndentHash:
27
+ Enabled: false
28
+
29
+ Layout/AlignHash:
30
+ Enabled: false
31
+
32
+ # HoundCI doesn't like this rule
33
+ Layout/DotPosition:
34
+ Enabled: false
35
+
36
+ # We allow !! as it's an easy way to convert ot boolean
37
+ Style/DoubleNegation:
38
+ Enabled: false
39
+
40
+ # Cop supports --auto-correct.
41
+ Lint/UnusedBlockArgument:
42
+ Enabled: false
43
+
44
+ # We want to allow class Fastlane::Class
45
+ Style/ClassAndModuleChildren:
46
+ Enabled: false
47
+
48
+ Metrics/AbcSize:
49
+ Max: 60
50
+
51
+ # The %w might be confusing for new users
52
+ Style/WordArray:
53
+ MinSize: 19
54
+
55
+ # raise and fail are both okay
56
+ Style/SignalException:
57
+ Enabled: false
58
+
59
+ # Better too much 'return' than one missing
60
+ Style/RedundantReturn:
61
+ Enabled: false
62
+
63
+ # Having if in the same line might not always be good
64
+ Style/IfUnlessModifier:
65
+ Enabled: false
66
+
67
+ # and and or is okay
68
+ Style/AndOr:
69
+ Enabled: false
70
+
71
+ # Configuration parameters: CountComments.
72
+ Metrics/ClassLength:
73
+ Max: 350
74
+
75
+ Metrics/CyclomaticComplexity:
76
+ Max: 17
77
+
78
+ # Configuration parameters: AllowURI, URISchemes.
79
+ Metrics/LineLength:
80
+ Max: 370
81
+
82
+ # Configuration parameters: CountKeywordArgs.
83
+ Metrics/ParameterLists:
84
+ Max: 10
85
+
86
+ Metrics/PerceivedComplexity:
87
+ Max: 18
88
+
89
+ # Sometimes it's easier to read without guards
90
+ Style/GuardClause:
91
+ Enabled: false
92
+
93
+ # something = if something_else
94
+ # that's confusing
95
+ Style/ConditionalAssignment:
96
+ Enabled: false
97
+
98
+ # Better to have too much self than missing a self
99
+ Style/RedundantSelf:
100
+ Enabled: false
101
+
102
+ Metrics/MethodLength:
103
+ Max: 60
104
+
105
+ # We're not there yet
106
+ Style/Documentation:
107
+ Enabled: false
108
+
109
+ # Adds complexity
110
+ Style/IfInsideElse:
111
+ Enabled: false
112
+
113
+ # danger specific
114
+
115
+ Style/BlockComments:
116
+ Enabled: false
117
+
118
+ Layout/MultilineMethodCallIndentation:
119
+ EnforcedStyle: indented
120
+
121
+ # FIXME: 25
122
+ Metrics/BlockLength:
123
+ Max: 345
124
+ Exclude:
125
+ - "**/*_spec.rb"
126
+
127
+ Style/MixinGrouping:
128
+ Enabled: false
129
+
130
+ Style/FileName:
131
+ Enabled: false
132
+
133
+ Layout/IndentHeredoc:
134
+ Enabled: false
135
+
136
+ Style/SpecialGlobalVars:
137
+ Enabled: false
138
+
139
+ PercentLiteralDelimiters:
140
+ PreferredDelimiters:
141
+ "%": ()
142
+ "%i": ()
143
+ "%q": ()
144
+ "%Q": ()
145
+ "%r": "{}"
146
+ "%s": ()
147
+ "%w": ()
148
+ "%W": ()
149
+ "%x": ()
150
+
151
+ Security/YAMLLoad:
152
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-ad_licenselint.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,189 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-ad_licenselint (1.0.0)
5
+ ad_licenselint (~> 1.1)
6
+ danger-plugin-api (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.4.5)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ ad_licenselint (1.1.0)
17
+ cocoapods-core (~> 1.9)
18
+ colorize (~> 0.8)
19
+ terminal-table (~> 1.8)
20
+ addressable (2.7.0)
21
+ public_suffix (>= 2.0.2, < 5.0)
22
+ algoliasearch (1.27.5)
23
+ httpclient (~> 2.8, >= 2.8.3)
24
+ json (>= 1.5.1)
25
+ ast (2.4.2)
26
+ claide (1.0.3)
27
+ claide-plugins (0.9.2)
28
+ cork
29
+ nap
30
+ open4 (~> 1.3)
31
+ cocoapods-core (1.10.1)
32
+ activesupport (> 5.0, < 6)
33
+ addressable (~> 2.6)
34
+ algoliasearch (~> 1.0)
35
+ concurrent-ruby (~> 1.1)
36
+ fuzzy_match (~> 2.0.4)
37
+ nap (~> 1.0)
38
+ netrc (~> 0.11)
39
+ public_suffix
40
+ typhoeus (~> 1.0)
41
+ coderay (1.1.3)
42
+ colored2 (3.1.2)
43
+ colorize (0.8.1)
44
+ concurrent-ruby (1.1.8)
45
+ cork (0.3.0)
46
+ colored2 (~> 3.1)
47
+ danger (8.2.3)
48
+ claide (~> 1.0)
49
+ claide-plugins (>= 0.9.2)
50
+ colored2 (~> 3.1)
51
+ cork (~> 0.1)
52
+ faraday (>= 0.9.0, < 2.0)
53
+ faraday-http-cache (~> 2.0)
54
+ git (~> 1.7)
55
+ kramdown (~> 2.3)
56
+ kramdown-parser-gfm (~> 1.0)
57
+ no_proxy_fix
58
+ octokit (~> 4.7)
59
+ terminal-table (>= 1, < 4)
60
+ danger-plugin-api (1.0.0)
61
+ danger (> 2.0)
62
+ diff-lcs (1.4.4)
63
+ ethon (0.12.0)
64
+ ffi (>= 1.3.0)
65
+ faraday (1.3.0)
66
+ faraday-net_http (~> 1.0)
67
+ multipart-post (>= 1.2, < 3)
68
+ ruby2_keywords
69
+ faraday-http-cache (2.2.0)
70
+ faraday (>= 0.8)
71
+ faraday-net_http (1.0.1)
72
+ ffi (1.15.0)
73
+ formatador (0.2.5)
74
+ fuzzy_match (2.0.4)
75
+ git (1.8.1)
76
+ rchardet (~> 1.8)
77
+ guard (2.16.2)
78
+ formatador (>= 0.2.4)
79
+ listen (>= 2.7, < 4.0)
80
+ lumberjack (>= 1.0.12, < 2.0)
81
+ nenv (~> 0.1)
82
+ notiffany (~> 0.0)
83
+ pry (>= 0.9.12)
84
+ shellany (~> 0.0)
85
+ thor (>= 0.18.1)
86
+ guard-compat (1.2.1)
87
+ guard-rspec (4.7.3)
88
+ guard (~> 2.1)
89
+ guard-compat (~> 1.1)
90
+ rspec (>= 2.99.0, < 4.0)
91
+ httpclient (2.8.3)
92
+ i18n (1.8.9)
93
+ concurrent-ruby (~> 1.0)
94
+ json (2.5.1)
95
+ kramdown (2.3.1)
96
+ rexml
97
+ kramdown-parser-gfm (1.1.0)
98
+ kramdown (~> 2.0)
99
+ listen (3.0.7)
100
+ rb-fsevent (>= 0.9.3)
101
+ rb-inotify (>= 0.9.7)
102
+ lumberjack (1.2.8)
103
+ method_source (1.0.0)
104
+ minitest (5.14.4)
105
+ multipart-post (2.1.1)
106
+ nap (1.1.0)
107
+ nenv (0.3.0)
108
+ netrc (0.11.0)
109
+ no_proxy_fix (0.1.2)
110
+ notiffany (0.1.3)
111
+ nenv (~> 0.1)
112
+ shellany (~> 0.0)
113
+ octokit (4.20.0)
114
+ faraday (>= 0.9)
115
+ sawyer (~> 0.8.0, >= 0.5.3)
116
+ open4 (1.3.4)
117
+ parallel (1.20.1)
118
+ parser (3.0.0.0)
119
+ ast (~> 2.4.1)
120
+ pry (0.14.0)
121
+ coderay (~> 1.1)
122
+ method_source (~> 1.0)
123
+ public_suffix (4.0.6)
124
+ rainbow (3.0.0)
125
+ rake (10.5.0)
126
+ rb-fsevent (0.10.4)
127
+ rb-inotify (0.10.1)
128
+ ffi (~> 1.0)
129
+ rchardet (1.8.0)
130
+ regexp_parser (2.1.1)
131
+ rexml (3.2.4)
132
+ rspec (3.10.0)
133
+ rspec-core (~> 3.10.0)
134
+ rspec-expectations (~> 3.10.0)
135
+ rspec-mocks (~> 3.10.0)
136
+ rspec-core (3.10.1)
137
+ rspec-support (~> 3.10.0)
138
+ rspec-expectations (3.10.1)
139
+ diff-lcs (>= 1.2.0, < 2.0)
140
+ rspec-support (~> 3.10.0)
141
+ rspec-mocks (3.10.2)
142
+ diff-lcs (>= 1.2.0, < 2.0)
143
+ rspec-support (~> 3.10.0)
144
+ rspec-support (3.10.2)
145
+ rubocop (1.11.0)
146
+ parallel (~> 1.10)
147
+ parser (>= 3.0.0.0)
148
+ rainbow (>= 2.2.2, < 4.0)
149
+ regexp_parser (>= 1.8, < 3.0)
150
+ rexml
151
+ rubocop-ast (>= 1.2.0, < 2.0)
152
+ ruby-progressbar (~> 1.7)
153
+ unicode-display_width (>= 1.4.0, < 3.0)
154
+ rubocop-ast (1.4.1)
155
+ parser (>= 2.7.1.5)
156
+ ruby-progressbar (1.11.0)
157
+ ruby2_keywords (0.0.4)
158
+ sawyer (0.8.2)
159
+ addressable (>= 2.3.5)
160
+ faraday (> 0.8, < 2.0)
161
+ shellany (0.0.1)
162
+ terminal-table (1.8.0)
163
+ unicode-display_width (~> 1.1, >= 1.1.1)
164
+ thor (1.1.0)
165
+ thread_safe (0.3.6)
166
+ typhoeus (1.4.0)
167
+ ethon (>= 0.9.0)
168
+ tzinfo (1.2.9)
169
+ thread_safe (~> 0.1)
170
+ unicode-display_width (1.7.0)
171
+ yard (0.9.26)
172
+
173
+ PLATFORMS
174
+ ruby
175
+
176
+ DEPENDENCIES
177
+ bundler (~> 2.0)
178
+ danger-ad_licenselint!
179
+ guard (~> 2.14)
180
+ guard-rspec (~> 4.7)
181
+ listen (= 3.0.7)
182
+ pry
183
+ rake (~> 10.0)
184
+ rspec (~> 3.4)
185
+ rubocop
186
+ yard
187
+
188
+ BUNDLED WITH
189
+ 2.1.4
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) 2021 Pierre Felgines <pierre.felgines@fabernovel.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,33 @@
1
+ # Danger ad_licenselint
2
+
3
+ A [Danger Ruby](https://github.com/danger/danger) plugin for [ad_licenselint](https://github.com/faberNovel/ad_licenselint/)
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install danger-ad_licenselint
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ The easiest way to use is just add this line to your Dangerfile:
14
+
15
+ ```ruby
16
+ ad_licenselint.lint_licenses
17
+ ```
18
+
19
+ By default, `danger-ad_licenselint` will add a comment to your PR for pods that are modified (added or updated).
20
+
21
+ If you want to post inline comments for modified pods, run
22
+
23
+ ```ruby
24
+ ad_licenselint.lint_licenses inline_mode: true
25
+ ```
26
+
27
+ ## Development
28
+
29
+ 1. Clone this repo
30
+ 2. Run `bundle install` to setup dependencies.
31
+ 3. Run `bundle exec rake spec` to run the tests.
32
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
33
+ 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 'ad_licenselint/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-ad_licenselint'
8
+ spec.version = AdLicenselint::VERSION
9
+ spec.authors = ['Pierre Felgines']
10
+ spec.email = ['pierre.felgines@fabernovel.com']
11
+ spec.description = %q{Danger plugin for ad_licenselint}
12
+ spec.summary = %q{Danger plugin for ad_licenselint}
13
+ spec.homepage = 'https://github.com/fabernovel/danger-ad_licenselint'
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 'ad_licenselint', '~> 1.1'
23
+
24
+ # General ruby development
25
+ spec.add_development_dependency 'bundler', '~> 2.0'
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"
33
+ spec.add_development_dependency "yard"
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'
50
+ end
@@ -0,0 +1,3 @@
1
+ module AdLicenselint
2
+ VERSION = "1.0.0".freeze
3
+ end
@@ -0,0 +1,121 @@
1
+ require 'ad_licenselint'
2
+ require 'cocoapods-core'
3
+
4
+ module Danger
5
+ # Lint license from pods in your Podfile
6
+ # This is done using the gem ad_licenselint
7
+ #
8
+ # You should replace these comments with a public description of your library.
9
+ #
10
+ # @example Specifying options
11
+ #
12
+ # ad_licenselint.lint_licenses(inline_mode: true)
13
+ #
14
+ # @see fabernovel/danger-ad_licenselint
15
+ # @tags license, lint, podfile, cocoapods, ad_licenselint
16
+ #
17
+ class DangerAdLicenselint < Plugin
18
+
19
+ # Provides additional logging diagnostic information
20
+ #
21
+ # @return [Boolean]
22
+ attr_accessor :verbose
23
+
24
+ # Lints licenses from pods in Podfile.
25
+ # Generates a `markdown` list of warnings either inline or globally.
26
+ #
27
+ # @param [Boolean] inline_mode
28
+ # Create a review on the Podfile directly if set to true
29
+ # @return [void]
30
+ #
31
+
32
+ def lint_licenses(inline_mode: false)
33
+ return if git.modified_files.grep(/Podfile/).empty?
34
+
35
+ runner = ADLicenseLint::Runner.new({
36
+ format: ADLicenseLint::Constant::MARKDOWN_FORMAT_OPTION,
37
+ path: ".",
38
+ all: false,
39
+ only: get_modified_pods_from_diff
40
+ })
41
+ report = runner.create_report
42
+
43
+ if inline_mode
44
+ post_inline_messages(report)
45
+ else
46
+ post_global_message(runner.format(report))
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def write_to_file(content)
53
+ result = nil
54
+ Tempfile.create { |f|
55
+ f.write(content)
56
+ f.rewind
57
+ result = yield(f.path)
58
+ }
59
+ result
60
+ end
61
+
62
+ def line_for_content(subcontent, full_content)
63
+ lines = full_content.split("\n")
64
+ matching_line = nil
65
+ lines.each_with_index { |line_content, index|
66
+ matching_line = index if line_content.include?(subcontent)
67
+ }
68
+ matching_line + 1
69
+ end
70
+
71
+ def comment_for_report(report)
72
+ comment = []
73
+ comment << "*License linter*"
74
+ comment << ""
75
+ comment << "The license `#{report.license_name}` for the pod [#{report.pod_name}](#{report.source_url}) has not been automatically validated."
76
+ comment << "Verify license below:"
77
+ comment << "<details>"
78
+ comment << "<summary>License</summary>"
79
+ comment << ""
80
+ comment << "```"
81
+ comment << report.license_content
82
+ comment << "```"
83
+ comment << "</details>"
84
+ comment.join("\n")
85
+ end
86
+
87
+ def get_modified_pods_from_diff
88
+ after_podfile = write_to_file(git.info_for_file("Podfile")[:after]) { |path|
89
+ Pod::Podfile.from_file path
90
+ }
91
+ before_lockfile = write_to_file(git.info_for_file("Podfile.lock")[:before]) { |path|
92
+ Pod::Lockfile.from_file(Pathname(path))
93
+ }
94
+ changes = before_lockfile.detect_changes_with_podfile(after_podfile)
95
+ changes[:added] + changes[:changed]
96
+ end
97
+
98
+ def post_inline_messages(report)
99
+ podfile_content = git.info_for_file("Podfile")[:after]
100
+ report
101
+ .entries
102
+ .each { |pod_report|
103
+ line = line_for_content(pod_report.pod_name, podfile_content)
104
+ warn(
105
+ comment_for_report(pod_report),
106
+ file: "Podfile",
107
+ line: line
108
+ )
109
+ }
110
+ end
111
+
112
+ def post_global_message(message)
113
+ markdown(message)
114
+ end
115
+
116
+ def log(text)
117
+ puts(text) if @verbose
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1 @@
1
+ require "ad_licenselint/gem_version"
@@ -0,0 +1 @@
1
+ require "ad_licenselint/plugin"
@@ -0,0 +1,46 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerAdLicenselint do
5
+ it "should be a plugin" do
6
+ expect(Danger::DangerAdLicenselint.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.ad_licenselint
16
+
17
+ # mock the PR data
18
+ # you can then use this, eg. github.pr_author, later in the spec
19
+ json = File.read(File.dirname(__FILE__) + '/support/fixtures/github_pr.json') # example json: `curl https://api.github.com/repos/danger/danger-plugin-template/pulls/18 > github_pr.json`
20
+ allow(@my_plugin.github).to receive(:pr_json).and_return(json)
21
+ end
22
+
23
+ # Some examples for writing tests
24
+ # You should replace these with your own.
25
+
26
+ it "Warns on a monday" do
27
+ monday_date = Date.parse("2016-07-11")
28
+ allow(Date).to receive(:today).and_return monday_date
29
+
30
+ @my_plugin.warn_on_mondays
31
+
32
+ expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"])
33
+ end
34
+
35
+ it "Does nothing on a tuesday" do
36
+ monday_date = Date.parse("2016-07-12")
37
+ allow(Date).to receive(:today).and_return monday_date
38
+
39
+ @my_plugin.warn_on_mondays
40
+
41
+ expect(@dangerfile.status_report[:warnings]).to eq([])
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,65 @@
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
+ if `git remote -v` == ''
13
+ puts "You cannot run tests without setting a local git remote on this repo"
14
+ puts "It's a weird side-effect of Danger's internals."
15
+ exit(0)
16
+ end
17
+
18
+ # Use coloured output, it's the best.
19
+ RSpec.configure do |config|
20
+ config.filter_gems_from_backtrace "bundler"
21
+ config.color = true
22
+ config.tty = true
23
+ end
24
+
25
+ require "danger_plugin"
26
+
27
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
28
+ # If you are expanding these files, see if it's already been done ^.
29
+
30
+ # A silent version of the user interface,
31
+ # it comes with an extra function `.string` which will
32
+ # strip all ANSI colours from the string.
33
+
34
+ # rubocop:disable Lint/NestedMethodDefinition
35
+ def testing_ui
36
+ @output = StringIO.new
37
+ def @output.winsize
38
+ [20, 9999]
39
+ end
40
+
41
+ cork = Cork::Board.new(out: @output)
42
+ def cork.string
43
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
44
+ end
45
+ cork
46
+ end
47
+ # rubocop:enable Lint/NestedMethodDefinition
48
+
49
+ # Example environment (ENV) that would come from
50
+ # running a PR on TravisCI
51
+ def testing_env
52
+ {
53
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
54
+ "TRAVIS_PULL_REQUEST" => "800",
55
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
56
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
57
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
58
+ }
59
+ end
60
+
61
+ # A stubbed out Dangerfile for use in tests
62
+ def testing_dangerfile
63
+ env = Danger::EnvironmentManager.new(testing_env)
64
+ Danger::Dangerfile.new(env, testing_ui)
65
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-ad_licenselint
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pierre Felgines
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-23 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: ad_licenselint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
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'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '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'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
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: Danger plugin for ad_licenselint
168
+ email:
169
+ - pierre.felgines@fabernovel.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".rubocop.yml"
175
+ - Gemfile
176
+ - Gemfile.lock
177
+ - Guardfile
178
+ - LICENSE.txt
179
+ - README.md
180
+ - Rakefile
181
+ - danger-ad_licenselint.gemspec
182
+ - lib/ad_licenselint/gem_version.rb
183
+ - lib/ad_licenselint/plugin.rb
184
+ - lib/danger_ad_licenselint.rb
185
+ - lib/danger_plugin.rb
186
+ - spec/ad_licenselint_spec.rb
187
+ - spec/spec_helper.rb
188
+ homepage: https://github.com/fabernovel/danger-ad_licenselint
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
+ rubygems_version: 3.0.3
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: Danger plugin for ad_licenselint
211
+ test_files:
212
+ - spec/ad_licenselint_spec.rb
213
+ - spec/spec_helper.rb