danger-ios_logs 0.1.0

This diff has not been reviewed by any users.
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 117f880787c83e92c01c35f4fbced8bb21fc7657
4
+ data.tar.gz: 28a1c651ba18c6b97fc765c8161b9d0591865fa7
5
+ SHA512:
6
+ metadata.gz: 6fccf0c0096a05ac547580fa3d09d4ddaa6caf9165a87a0ce81736956d1221af00de427a4922d276d7d6866226974b5c3bfa1bf38b7f1222c0cbcaa66a28974c
7
+ data.tar.gz: d9e3c976cc9ee4c296afde6146387b73a3e91ee5a8ece1fe484456957eaadd84db6eb7c49b950775053bd768b919e23860d50e752457e425625d826d35f9fb9a
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
@@ -0,0 +1,4 @@
1
+ Metrics/LineLength:
2
+ Max: 110
3
+ Metrics/AbcSize:
4
+ Max: 16.5
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.0
8
+ - 2.1.3
9
+ - 2.3.3
10
+ - 2.4.0
11
+
12
+ script:
13
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-ios_logs.gemspec
4
+ gemspec
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-ios_logs (0.1.0)
5
+ danger-plugin-api (~> 1.0)
6
+ git_diff_parser (~> 2.3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.0)
12
+ public_suffix (~> 2.0, >= 2.0.2)
13
+ ast (2.3.0)
14
+ claide (1.0.1)
15
+ claide-plugins (0.9.2)
16
+ cork
17
+ nap
18
+ open4 (~> 1.3)
19
+ coderay (1.1.1)
20
+ colored (1.2)
21
+ colored2 (3.1.2)
22
+ cork (0.2.0)
23
+ colored (~> 1.2)
24
+ danger (4.2.2)
25
+ claide (~> 1.0)
26
+ claide-plugins (>= 0.9.2)
27
+ colored2 (~> 3.1)
28
+ cork (~> 0.1)
29
+ faraday (~> 0.9)
30
+ faraday-http-cache (~> 1.0)
31
+ git (~> 1)
32
+ kramdown (~> 1.5)
33
+ octokit (~> 4.2)
34
+ terminal-table (~> 1)
35
+ danger-plugin-api (1.0.0)
36
+ danger (> 2.0)
37
+ diff-lcs (1.3)
38
+ faraday (0.11.0)
39
+ multipart-post (>= 1.2, < 3)
40
+ faraday-http-cache (1.3.1)
41
+ faraday (~> 0.8)
42
+ ffi (1.9.17)
43
+ formatador (0.2.5)
44
+ git (1.3.0)
45
+ git_diff_parser (2.3.0)
46
+ guard (2.14.1)
47
+ formatador (>= 0.2.4)
48
+ listen (>= 2.7, < 4.0)
49
+ lumberjack (~> 1.0)
50
+ nenv (~> 0.1)
51
+ notiffany (~> 0.0)
52
+ pry (>= 0.9.12)
53
+ shellany (~> 0.0)
54
+ thor (>= 0.18.1)
55
+ guard-compat (1.2.1)
56
+ guard-rspec (4.7.3)
57
+ guard (~> 2.1)
58
+ guard-compat (~> 1.1)
59
+ rspec (>= 2.99.0, < 4.0)
60
+ kramdown (1.13.2)
61
+ listen (3.0.7)
62
+ rb-fsevent (>= 0.9.3)
63
+ rb-inotify (>= 0.9.7)
64
+ lumberjack (1.0.11)
65
+ method_source (0.8.2)
66
+ multipart-post (2.0.0)
67
+ nap (1.1.0)
68
+ nenv (0.3.0)
69
+ notiffany (0.1.1)
70
+ nenv (~> 0.1)
71
+ shellany (~> 0.0)
72
+ octokit (4.6.2)
73
+ sawyer (~> 0.8.0, >= 0.5.3)
74
+ open4 (1.3.4)
75
+ parser (2.4.0.0)
76
+ ast (~> 2.2)
77
+ powerpack (0.1.1)
78
+ pry (0.10.4)
79
+ coderay (~> 1.1.0)
80
+ method_source (~> 0.8.1)
81
+ slop (~> 3.4)
82
+ public_suffix (2.0.5)
83
+ rainbow (2.2.1)
84
+ rake (10.5.0)
85
+ rb-fsevent (0.9.8)
86
+ rb-inotify (0.9.8)
87
+ ffi (>= 0.5.0)
88
+ rspec (3.5.0)
89
+ rspec-core (~> 3.5.0)
90
+ rspec-expectations (~> 3.5.0)
91
+ rspec-mocks (~> 3.5.0)
92
+ rspec-core (3.5.4)
93
+ rspec-support (~> 3.5.0)
94
+ rspec-expectations (3.5.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.5.0)
97
+ rspec-mocks (3.5.0)
98
+ diff-lcs (>= 1.2.0, < 2.0)
99
+ rspec-support (~> 3.5.0)
100
+ rspec-support (3.5.0)
101
+ rubocop (0.47.1)
102
+ parser (>= 2.3.3.1, < 3.0)
103
+ powerpack (~> 0.1)
104
+ rainbow (>= 1.99.1, < 3.0)
105
+ ruby-progressbar (~> 1.7)
106
+ unicode-display_width (~> 1.0, >= 1.0.1)
107
+ ruby-progressbar (1.8.1)
108
+ sawyer (0.8.1)
109
+ addressable (>= 2.3.5, < 2.6)
110
+ faraday (~> 0.8, < 1.0)
111
+ shellany (0.0.1)
112
+ slop (3.6.0)
113
+ terminal-table (1.7.3)
114
+ unicode-display_width (~> 1.1.1)
115
+ thor (0.19.4)
116
+ unicode-display_width (1.1.3)
117
+ yard (0.9.8)
118
+
119
+ PLATFORMS
120
+ ruby
121
+
122
+ DEPENDENCIES
123
+ bundler (~> 1.3)
124
+ danger-ios_logs!
125
+ guard (~> 2.14)
126
+ guard-rspec (~> 4.7)
127
+ listen (= 3.0.7)
128
+ pry
129
+ rake (~> 10.0)
130
+ rspec (~> 3.4)
131
+ rubocop (~> 0.41)
132
+ yard (~> 0.8)
133
+
134
+ BUNDLED WITH
135
+ 1.14.4
@@ -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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 PGS Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,60 @@
1
+
2
+ [![Travis](https://img.shields.io/travis/PGSSoft/danger-ios_logs.svg)](https://travis-ci.org/PGSSoft/danger-ios_logs)
3
+ [![Gem](https://img.shields.io/gem/v/danger-ios_logs.svg)](https://rubygems.org/gems/danger-ios_logs)
4
+ [![License](https://img.shields.io/github/license/PGSSoft/danger-ios_logs.svg)](https://github.com/PGSSoft/danger-ios_logs/blob/master/LICENSE)
5
+
6
+ ### ios_logs
7
+
8
+ This is a danger plugin to detect any `NSLog`/`print` entries left in the code.
9
+
10
+ <blockquote>Ensure, by warning, there are no `NSLog`/`print` entries left in the modified code
11
+ <pre>
12
+ ios_logs.check</pre>
13
+ </blockquote>
14
+
15
+ <blockquote>Ensure, by fail, there are no `NSLog`/`print` entries left in the modified code
16
+ <pre>
17
+ ios_logs.check :fail</pre>
18
+ </blockquote>
19
+
20
+ <blockquote>Ensure, there are no `print` left in the modified code. Ignore `NSLog`
21
+ <pre>
22
+ ios_logs.nslog = false
23
+ ios_logs.check</pre>
24
+ </blockquote>
25
+
26
+
27
+
28
+ #### Attributes
29
+
30
+ `nslog` - Notify usage of `NSLog`. `true` by default
31
+
32
+ `print` - Notify usage of `print`. `true` by default
33
+
34
+ `prints` - List of `print` in changeset
35
+
36
+ `nslogs` - List of `NSLog` in changeset
37
+
38
+ `logs` - Combined list of both `NSLog` and `print`
39
+
40
+
41
+
42
+
43
+ #### Methods
44
+
45
+ `check` - Checks if in the changed code `NSLog` or `print` are used.
46
+
47
+
48
+ ## License
49
+
50
+ The project is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
+
52
+ ## About
53
+ The project maintained by software development agency [PGS Software](https://www.pgs-soft.com).
54
+ See our other [open-source projects](https://github.com/PGSSoft) or [contact us](https://www.pgs-soft.com/contact-us) to develop your product.
55
+
56
+ ## Follow us
57
+
58
+ [![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=https://github.com/PGSSoft/danger-ios_logs)
59
+ [![Twitter Follow](https://img.shields.io/twitter/follow/pgssoftware.svg?style=social&label=Follow)](https://twitter.com/pgssoftware)
60
+
@@ -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 'ios_logs/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-ios_logs'
8
+ spec.version = IosLogs::VERSION
9
+ spec.authors = ['Bartosz Janda', 'Joanna Bednarz']
10
+ spec.email = ['bjanda@pgs-soft.com', 'jbednarz@pgs-soft.com']
11
+ spec.description = 'Danger plugin to detect any NSLog/print entries left in the code'
12
+ spec.summary = 'Danger plugin to detect any NSLog/print entries left in the code'
13
+ spec.homepage = 'https://github.com/PGSSoft/danger-ios_logs'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
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', '~> 2.3.0'
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.41'
33
+ spec.add_development_dependency 'yard', '~> 0.8'
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 @@
1
+ require 'ios_logs/gem_version'
@@ -0,0 +1,2 @@
1
+ require 'ios_logs/plugin'
2
+ require 'ios_logs/file_log'
@@ -0,0 +1,5 @@
1
+ # rubocop:disable Style/StructInheritance
2
+
3
+ module Danger
4
+ class FileLog < Struct.new(:file, :line); end
5
+ end
@@ -0,0 +1,3 @@
1
+ module IosLogs
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,176 @@
1
+ require 'git_diff_parser'
2
+
3
+ module Danger
4
+ # This is a danger plugin to detect any `NSLog`/`print` entries left in the code.
5
+ #
6
+ # @example Ensure, by warning, there are no `NSLog`/`print` entries left in the modified code
7
+ #
8
+ # ios_logs.check
9
+ #
10
+ # @example Ensure, by fail, there are no `NSLog`/`print` entries left in the modified code
11
+ #
12
+ # ios_logs.check :fail
13
+ #
14
+ # @example Ensure, there are no `print` left in the modified code. Ignore `NSLog`
15
+ #
16
+ # ios_logs.nslog = false
17
+ # ios_logs.check
18
+ #
19
+ # @see Bartosz Janda/danger-ios_logs
20
+ # @tags ios, logs, print, nslog, swift
21
+ #
22
+ class DangerIosLogs < Plugin
23
+ NSLOG_REGEXP = /\s+NSLog\s*\(/
24
+ PRINT_REGEXP = /\s+print\s*\(/
25
+
26
+ NSLOG_MESSAGE = 'There remain `NSLog` in the modified code.'.freeze
27
+ PRINT_MESSAGE = 'There remain `print` in the modified code.'.freeze
28
+
29
+ #
30
+ # Notify usage of `NSLog`. `true` by default
31
+ #
32
+ # @return [Bool]
33
+ attr_accessor :nslog
34
+
35
+ #
36
+ # Notify usage of `print`. `true` by default
37
+ #
38
+ # @return [Bool]
39
+ attr_accessor :print
40
+
41
+ #
42
+ # List of `print` in changeset
43
+ #
44
+ # @return [Array<FileLog>] List of `print`
45
+ attr_accessor :prints
46
+
47
+ #
48
+ # List of `NSLog` in changeset
49
+ #
50
+ # @return [Array<FileLog>] List of `NSLog`
51
+ attr_accessor :nslogs
52
+
53
+ #
54
+ # Combined list of both `NSLog` and `print`
55
+ #
56
+ # @return [Array<FileLog>] List of `NSLog` and `print`
57
+ attr_accessor :logs
58
+
59
+ #
60
+ # Initialize plugin
61
+ # @param dangerfile [Dangerfile] Dangerfile used to initialize plugin
62
+ #
63
+ # @return [DangerIosLogs] Initialized DangerIosLogs plugin
64
+ def initialize(dangerfile)
65
+ super
66
+ @print = true
67
+ @nslog = true
68
+ @nslogs = []
69
+ @prints = []
70
+ end
71
+
72
+ #
73
+ # Combined list of both NSLog and print
74
+ #
75
+ # @return [Array<FileLog>] List of `NSLog` and `print`
76
+ def logs
77
+ prints + nslogs
78
+ end
79
+
80
+ #
81
+ # Checks if in the changed code `NSLog` or `print` are used.
82
+ # @param method = :warn [Symbol] Used method to indicate log method usage.
83
+ # By default `:warn`. Possible values: `:message`, `:warn`, `:fail`
84
+ #
85
+ # @return [Void]
86
+ def check(method = :warn)
87
+ raise 'Unsupported method' unless [:message, :warn, :fail].include?(method)
88
+ @nslogs = []
89
+ @prints = []
90
+
91
+ check_files files_of_interest
92
+
93
+ print_logs method
94
+ end
95
+
96
+ private
97
+
98
+ #
99
+ # Checks if in the files `NSLog` or `print` are used.
100
+ # @param files [Array<String>] List of interested / modified files to check.
101
+ #
102
+ # @return [Void]
103
+ def check_files(files)
104
+ files.each { |file| check_file(file) if file.is_a? String }
105
+ end
106
+
107
+ #
108
+ # List of interested files.
109
+ #
110
+ # @return [Array<String>] List of interested / modified files to check.
111
+ def files_of_interest
112
+ git.modified_files + git.added_files
113
+ end
114
+
115
+ #
116
+ # Checks if in the file `NSLog` or `print` are used.
117
+ # @param file [String] Modified file to check.
118
+ #
119
+ # @return [Void]
120
+ def check_file(file)
121
+ changed_lines(file).each do |line|
122
+ check_line(file, line)
123
+ end
124
+ end
125
+
126
+ #
127
+ # Returns changed lines in modified file.
128
+ # @param file [String] Path to modified files.
129
+ #
130
+ # @return [Array<GitDiffParser::Line>] Modified lines
131
+ def changed_lines(file)
132
+ diff = git.diff_for_file(file)
133
+ GitDiffParser::Patch.new(diff.patch).changed_lines
134
+ end
135
+
136
+ #
137
+ # Check line if contains any `NSLog` or `print`
138
+ # @param file [String] Path to file
139
+ # @param line [GitDiffParser::Line] Line number
140
+ #
141
+ # @return [Void]
142
+ def check_line(file, line)
143
+ prints << Danger::FileLog.new(file, line.number) if @print && !line.content.match(PRINT_REGEXP).nil?
144
+ nslogs << Danger::FileLog.new(file, line.number) if @nslog && !line.content.match(NSLOG_REGEXP).nil?
145
+ end
146
+
147
+ #
148
+ # Print logs
149
+ # @param method [Symbol] Method to indicate usage
150
+ #
151
+ # @return [Void]
152
+ def print_logs(method)
153
+ print_log_for(@prints, PRINT_MESSAGE, method)
154
+ print_log_for(@nslogs, NSLOG_MESSAGE, method)
155
+ end
156
+
157
+ #
158
+ # Print logs for given logs set and message
159
+ # @param logs [Array<FileLog>] List of `NSLog` or `print`
160
+ # @param message [String] Message to print
161
+ # @param method [Symbol] Method to indicate usage
162
+ #
163
+ # @return [Void]
164
+ def print_log_for(logs, message, method)
165
+ logs.each do |log|
166
+ public_send(
167
+ method,
168
+ message,
169
+ sticky: false,
170
+ file: log.file,
171
+ line: log.line
172
+ )
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,130 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'shared_example_groups/files_in_changeset'
3
+ require 'shared_example_groups/files_not_in_changeset'
4
+ require 'shared_example_groups/logs_in_dockerfile'
5
+
6
+ # rubocop:disable Metrics/BlockLength
7
+
8
+ module Danger
9
+ describe Danger::DangerIosLogs do
10
+ it 'should be a plugin' do
11
+ expect(described_class).to be < Danger::Plugin
12
+ end
13
+
14
+ context 'with Dangerfile' do
15
+ before do
16
+ @dangerfile = testing_dangerfile
17
+ @ios_logs = @dangerfile.ios_logs
18
+ end
19
+
20
+ context 'changed files containing newly introduced logs' do
21
+ before do
22
+ patch = <<PATCH
23
+ + NSLog("Some log")
24
+ + func foo() {
25
+ + }
26
+ + print("Some other log")
27
+ PATCH
28
+
29
+ modified = Git::Diff::DiffFile.new(
30
+ 'base',
31
+ path: 'some/file.rb',
32
+ patch: patch
33
+ )
34
+ added = Git::Diff::DiffFile.new(
35
+ 'base',
36
+ path: 'another/stuff.rb',
37
+ patch: '+ print(\"More logs\")'
38
+ )
39
+
40
+ allow(@dangerfile.git).to receive(:diff_for_file).with('some/file.rb').and_return(modified)
41
+ allow(@dangerfile.git).to receive(:diff_for_file).with('another/stuff.rb').and_return(added)
42
+ allow(@dangerfile.git).to receive(:modified_files).and_return(['some/file.rb'])
43
+ allow(@dangerfile.git).to receive(:added_files).and_return(['another/stuff.rb'])
44
+ end
45
+
46
+ some_file_0th_line = Danger::FileLog.new('some/file.rb', 0)
47
+ some_file_3rd_line = Danger::FileLog.new('some/file.rb', 3)
48
+ another_stuff = Danger::FileLog.new('another/stuff.rb', 0)
49
+
50
+ context 'warns when files in the changeset' do
51
+ before do
52
+ @ios_logs.check
53
+ end
54
+
55
+ it_behaves_like 'files in changeset' do
56
+ let(:log_method) { warnings }
57
+ end
58
+ end
59
+
60
+ context 'fails when files in the changeset' do
61
+ before do
62
+ @ios_logs.check :fail
63
+ end
64
+
65
+ it_behaves_like 'files in changeset' do
66
+ let(:log_method) { failures }
67
+ end
68
+ end
69
+
70
+ context 'expose logs to the dangerfile' do
71
+ before do
72
+ @ios_logs.check
73
+ end
74
+
75
+ it_behaves_like 'logs in dockerfile', [some_file_3rd_line, another_stuff] do
76
+ let(:logs) { @ios_logs.prints }
77
+ end
78
+
79
+ it_behaves_like 'logs in dockerfile', [some_file_0th_line] do
80
+ let(:logs) { @ios_logs.nslogs }
81
+ end
82
+
83
+ it_behaves_like 'logs in dockerfile', [some_file_3rd_line, another_stuff, some_file_0th_line] do
84
+ let(:logs) { @ios_logs.logs }
85
+ end
86
+ end
87
+ end
88
+
89
+ context 'changed files not containing a NSLog nor print' do
90
+ before do
91
+ modified = Git::Diff::DiffFile.new(
92
+ 'base',
93
+ path: 'some/file.rb',
94
+ patch: '+ an added line'
95
+ )
96
+ allow(@dangerfile.git).to receive(:diff_for_file).with('some/file.rb').and_return(modified)
97
+ allow(@dangerfile.git).to receive(:modified_files).and_return(['some/file.rb'])
98
+ allow(@dangerfile.git).to receive(:added_files).and_return([])
99
+
100
+ @ios_logs.check
101
+ end
102
+
103
+ it_behaves_like 'files not in changeset'
104
+ end
105
+
106
+ context 'no files are in changeset' do
107
+ before do
108
+ allow(@dangerfile.git).to receive(:modified_files).and_return([])
109
+ allow(@dangerfile.git).to receive(:added_files).and_return([])
110
+
111
+ @ios_logs.check
112
+ end
113
+
114
+ it_behaves_like 'files not in changeset'
115
+ end
116
+
117
+ it 'does not raise when git returns nil' do
118
+ invalid = [nil, 0, false]
119
+ allow(@dangerfile.git).to receive(:modified_files).and_return(invalid)
120
+ allow(@dangerfile.git).to receive(:added_files).and_return(invalid)
121
+
122
+ expect { @ios_logs.check }.to_not raise_error
123
+ end
124
+
125
+ it 'raise if used wrong method' do
126
+ expect { @ios_logs.check(:wrong_method) }.to raise_error('Unsupported method')
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,17 @@
1
+ shared_examples_for 'files in changeset' do
2
+ it 'should have three logs' do
3
+ expect(log_method.length).to eq(3)
4
+ end
5
+
6
+ it 'has `print` log in first log element' do
7
+ expect(log_method[0]).to eq('There remain `print` in the modified code.')
8
+ end
9
+
10
+ it 'has `print` log in second log element' do
11
+ expect(log_method[1]).to eq('There remain `print` in the modified code.')
12
+ end
13
+
14
+ it 'has `NSLog` log in third log element' do
15
+ expect(log_method[2]).to eq('There remain `NSLog` in the modified code.')
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ shared_examples_for 'files not in changeset' do
2
+ it 'should have no message' do
3
+ expect(messages).to be_empty
4
+ end
5
+
6
+ it 'should have no warnings' do
7
+ expect(warnings).to be_empty
8
+ end
9
+
10
+ it 'should have no failures' do
11
+ expect(failures).to be_empty
12
+ end
13
+
14
+ it 'should have no markdowns' do
15
+ expect(markdowns).to be_empty
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ shared_examples_for 'logs in dockerfile' do |log_files|
2
+ it "should have #{log_files.count} logs" do
3
+ expect(logs.length).to eq(log_files.count)
4
+ end
5
+
6
+ log_files.each_index do |index|
7
+ log_file = log_files[index]
8
+ it "should have log in #{log_file.file} at $#{log_file.line}" do
9
+ expect(logs[index]).to eq(log_file)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,75 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.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
60
+
61
+ def messages
62
+ @dangerfile.status_report[:messages]
63
+ end
64
+
65
+ def failures
66
+ @dangerfile.status_report[:errors]
67
+ end
68
+
69
+ def warnings
70
+ @dangerfile.status_report[:warnings]
71
+ end
72
+
73
+ def markdowns
74
+ @dangerfile.status_report[:markdowns].map(&:message)
75
+ end
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-ios_logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bartosz Janda
8
+ - Joanna Bednarz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-02-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: danger-plugin-api
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: git_diff_parser
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 2.3.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.4'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.4'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.41'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.41'
98
+ - !ruby/object:Gem::Dependency
99
+ name: yard
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.8'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.8'
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2.14'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.14'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '4.7'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '4.7'
140
+ - !ruby/object:Gem::Dependency
141
+ name: listen
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '='
145
+ - !ruby/object:Gem::Version
146
+ version: 3.0.7
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '='
152
+ - !ruby/object:Gem::Version
153
+ version: 3.0.7
154
+ - !ruby/object:Gem::Dependency
155
+ name: pry
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: Danger plugin to detect any NSLog/print entries left in the code
169
+ email:
170
+ - bjanda@pgs-soft.com
171
+ - jbednarz@pgs-soft.com
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - ".gitignore"
177
+ - ".rubocop.yml"
178
+ - ".travis.yml"
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - Guardfile
182
+ - LICENSE
183
+ - README.md
184
+ - Rakefile
185
+ - danger-ios_logs.gemspec
186
+ - lib/danger_ios_logs.rb
187
+ - lib/danger_plugin.rb
188
+ - lib/ios_logs/file_log.rb
189
+ - lib/ios_logs/gem_version.rb
190
+ - lib/ios_logs/plugin.rb
191
+ - spec/ios_logs_spec.rb
192
+ - spec/shared_example_groups/files_in_changeset.rb
193
+ - spec/shared_example_groups/files_not_in_changeset.rb
194
+ - spec/shared_example_groups/logs_in_dockerfile.rb
195
+ - spec/spec_helper.rb
196
+ homepage: https://github.com/PGSSoft/danger-ios_logs
197
+ licenses:
198
+ - MIT
199
+ metadata: {}
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubyforge_project:
216
+ rubygems_version: 2.6.8
217
+ signing_key:
218
+ specification_version: 4
219
+ summary: Danger plugin to detect any NSLog/print entries left in the code
220
+ test_files:
221
+ - spec/ios_logs_spec.rb
222
+ - spec/shared_example_groups/files_in_changeset.rb
223
+ - spec/shared_example_groups/files_not_in_changeset.rb
224
+ - spec/shared_example_groups/logs_in_dockerfile.rb
225
+ - spec/spec_helper.rb