danger 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -23
  3. data/lib/danger.rb +3 -4
  4. data/lib/danger/ci_source/circle.rb +1 -1
  5. data/lib/danger/{circle_api.rb → ci_source/circle_api.rb} +0 -0
  6. data/lib/danger/ci_source/drone.rb +18 -0
  7. data/lib/danger/ci_source/semaphore.rb +18 -0
  8. data/lib/danger/commands/local.rb +19 -10
  9. data/lib/danger/commands/runner.rb +30 -18
  10. data/lib/danger/comment_generators/github.md.erb +1 -1
  11. data/lib/danger/{scm_source → core_ext}/file_list.rb +1 -0
  12. data/lib/danger/danger_core/dangerfile.rb +217 -0
  13. data/lib/danger/danger_core/dangerfile_dsl.rb +29 -0
  14. data/lib/danger/{environment_manager.rb → danger_core/environment_manager.rb} +14 -6
  15. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +69 -0
  16. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +68 -0
  17. data/lib/danger/danger_core/plugins/dangerfile_import_plugin.rb +58 -0
  18. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +87 -0
  19. data/lib/danger/{standard_error.rb → danger_core/standard_error.rb} +1 -1
  20. data/lib/danger/{violation.rb → danger_core/violation.rb} +0 -0
  21. data/lib/danger/plugin_support/plugin.rb +31 -0
  22. data/lib/danger/plugin_support/plugin_parser.rb +70 -0
  23. data/lib/danger/{request_sources → request_source}/github.rb +2 -33
  24. data/lib/danger/scm_source/git_repo.rb +1 -30
  25. data/lib/danger/version.rb +1 -1
  26. metadata +79 -17
  27. data/lib/danger/available_values.rb +0 -29
  28. data/lib/danger/dangerfile.rb +0 -123
  29. data/lib/danger/dangerfile_dsl.rb +0 -159
  30. data/lib/danger/plugin.rb +0 -25
  31. data/lib/danger/plugins/protect_files.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcdcdc1039905ce7ed910c8e951042b5f2fd994c
4
- data.tar.gz: 96f2dd059e8d700ca3965e36339183e027a2c080
3
+ metadata.gz: f195902ac5ec8dbc7c67059f6484d9c548fa1b9b
4
+ data.tar.gz: af4335f0b4691d17bc27b801b17885f01e9ead07
5
5
  SHA512:
6
- metadata.gz: b7e6ad0524f308e7ecfdab0b80759dc123024f2a6bde3c141bdc6c9317f63ea36b95dd4964b12be97487247b24ca12f886b1effd52352735ea307b15eefd5d60
7
- data.tar.gz: a1fc5b70bfbd76637b683b2944942109732650f400d0415726e9d803f0ebd4b45001444f2c202ff873ecddcaf445acd77454d19d17e3a0f20f634f1c2060253c
6
+ metadata.gz: 9948b94a2189dd1e4f131f2f0e2265aa666322edfb59f4df8c741d91296f01d684059f11ef67878f6957532f6edba115fbd16071c8b48db01924d36a08584dbe
7
+ data.tar.gz: 44c3f8b65bd973eb45175b0b494e07749508e91514e55e8179785edcd567fffc736974eeacda00f850671761e72607463788b70ad6e1bc865e2d821c02950f9b
data/README.md CHANGED
@@ -8,12 +8,11 @@ Formalize your Pull Request etiquette.
8
8
  -------
9
9
 
10
10
  <p align="center">
11
- <a href="#installation">Installation</a> &bull;
12
- <a href="#usage">Usage</a> &bull;
11
+ <a href="#getting-started">Getting Started</a> &bull;
12
+ <a href="#usage-on-ci">Usage</a> &bull;
13
13
  <a href="#dsl">DSL</a> &bull;
14
- <a href="#constraints">Constraints</a> &bull;
15
- <a href="#advanced">Advanced</a> &bull;
16
- <a href="#contributing">Contributing</a>
14
+ <a href="#plugins">Plugins</a> &bull;
15
+ <a href="#test-locally-with-danger-local">Local</a>
17
16
  </p>
18
17
 
19
18
  -------
@@ -32,6 +31,8 @@ To get up and running quickly, just run
32
31
  bundle exec danger init
33
32
  ```
34
33
 
34
+ The guide will create a default `Dangerfile` and take you through the process of setting up an account for feedback on GitHub.
35
+
35
36
  ## Usage on CI
36
37
 
37
38
  ```
@@ -40,19 +41,9 @@ bundle exec danger
40
41
 
41
42
  This will look at your `Dangerfile` and update the pull request accordingly. While you are setting up Danger, you may want to use: `--verbose` for more debug information.
42
43
 
43
- **Supported CIs**: Travis CI, CircleCI, Jenkins, Xcode Server and Buildkite.
44
-
45
- ### Making your own
46
- If the CI server you're using isn't available yet, you can build it yourself:
44
+ ## CI Support
47
45
 
48
- Take a look at some of the [already existing integrations](https://github.com/danger/danger/tree/master/lib/danger/ci_source). The class has 2 mandatory methods:
49
-
50
- - `self.validates?` which should detect if the CI is active (detecting via ENV variables, mostly)
51
- - `initialize` which should set 2 variables:
52
- - `self.repo_slug` the repo slug, in `org/repo` or `user/repo` format.
53
- - `self.pull_request_id` the number of the pull request that the CI is testing (often available in ENV variables)
54
-
55
- We'd love to see pull requests for new integrations!
46
+ Danger currently is supported on Travis CI, Circle CI, Xcode Bots via Buildasaur, BuildKite, Jenkins, Semaphore, and Drone CI. These work via environment variables, so it's easy to extend to include your own.
56
47
 
57
48
  ## What happens?
58
49
 
@@ -127,7 +118,7 @@ Command | Description
127
118
 
128
119
  ## Plugins
129
120
 
130
- Danger was built with a platform in mind: It can be used with any kind of software project and allows you to write your own action to have structured source code.
121
+ Danger was built with a platform in mind: she can be used with any kind of software project and allows you to write your own action to have structured source code.
131
122
 
132
123
  In your `Dangerfile` you can import local or remote actions using
133
124
 
@@ -150,10 +141,6 @@ danger new_plugin
150
141
 
151
142
  This will generate a new Ruby file which you can modify to fit your needs.
152
143
 
153
- ## Support
154
-
155
- Danger currently is supported on Travis CI, Circle CI, BuildKite and Jenkins. These work via environment variables, so it's easy to extend to include your own.
156
-
157
144
  ## Advanced
158
145
 
159
146
  You can access more detailed information by accessing the following variables
@@ -169,12 +156,25 @@ open to turning useful bits into the official API.
169
156
 
170
157
  ## Test locally with `danger local`
171
158
 
172
- You can use `danger local` to run Danger in an environment similar to how it will be ran on CI. By default Danger will look
159
+ You can use `danger local` to run Danger in an environment similar to how she will be ran on CI. By default Danger will look
173
160
  at the most recently merged PR, then run your `Dangerfile` against that Pull Request. This is really useful when making changes.
174
161
 
175
162
  If you have a specific PR in mind that you'd like to work against, make sure you have it merged in your current git
176
163
  history, then append `--use-merged-pr=[id]` to the command.
177
164
 
165
+ ### Adding a new CI
166
+ If the CI server you're using isn't available yet, you can build it yourself:
167
+
168
+ Take a look at some of the [already existing integrations](https://github.com/danger/danger/tree/master/lib/danger/ci_source). The class has 2 mandatory methods:
169
+
170
+ - `self.validates?` which should detect if the CI is active (detecting via ENV variables, mostly)
171
+ - `initialize` which should set 2 variables:
172
+ - `self.repo_slug` the repo slug, in `org/repo` or `user/repo` format.
173
+ - `self.pull_request_id` the number of the pull request that the CI is testing (often available in ENV variables)
174
+
175
+ We'd love to see pull requests for new integrations!
176
+
177
+
178
178
  ## Suppress Violations
179
179
 
180
180
  You can tell Danger to ignore a specific warning or error by commenting on the PR body:
@@ -199,6 +199,11 @@ fail("PR needs labels", sticky: false) if pr_labels.empty?
199
199
 
200
200
  Here are some real-world Dangerfiles: [artsy/eigen](https://github.com/artsy/eigen/blob/master/Dangerfile), [danger/danger](https://github.com/danger/danger/blob/master/Dangerfile), [artsy/elan](https://github.com/artsy/elan/blob/master/Dangerfile) and more!
201
201
 
202
+ ## Usage with GitHub Enterprise
203
+ Danger allows usage with GitHub Enterprise by setting 2 environment variables:
204
+ - `DANGER_GITHUB_HOST` to the host that GitHub is running on
205
+ - `DANGER_GITHUB_API_HOST` to the host that the GitHub Enterprise API is reachable on.
206
+
202
207
  ## License, Contributor's Guidelines and Code of Conduct
203
208
 
204
209
  [Join our Slack Group](https://danger-slack.herokuapp.com/)
@@ -1,9 +1,8 @@
1
1
  require "danger/version"
2
- require "danger/dangerfile"
3
- require "danger/environment_manager"
2
+ require "danger/danger_core/dangerfile"
3
+ require "danger/danger_core/environment_manager"
4
4
  require "danger/commands/runner"
5
- require "danger/available_values"
6
- require "danger/plugin"
5
+ require "danger/plugin_support/plugin"
7
6
  require "danger/core_ext/string"
8
7
 
9
8
  require "claide"
@@ -1,6 +1,6 @@
1
1
  # https://circleci.com/docs/environment-variables
2
2
  require 'uri'
3
- require 'danger/circle_api'
3
+ require 'danger/ci_source/circle_api'
4
4
 
5
5
  module Danger
6
6
  module CISource
@@ -0,0 +1,18 @@
1
+ # http://readme.drone.io/usage/variables/
2
+
3
+ module Danger
4
+ module CISource
5
+ class Drone < CI
6
+ def self.validates?(env)
7
+ return !env["DRONE"].nil?
8
+ end
9
+
10
+ def initialize(env)
11
+ self.repo_slug = env["DRONE_REPO"]
12
+ if env["DRONE_PULL_REQUEST"].to_i > 0
13
+ self.pull_request_id = env["DRONE_PULL_REQUEST"]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # https://semaphoreci.com/docs/available-environment-variables.html
2
+
3
+ module Danger
4
+ module CISource
5
+ class Semaphore < CI
6
+ def self.validates?(env)
7
+ return !env["SEMAPHORE"].nil?
8
+ end
9
+
10
+ def initialize(env)
11
+ self.repo_slug = env["SEMAPHORE_REPO_SLUG"]
12
+ if env["PULL_REQUEST_NUMBER"].to_i > 0
13
+ self.pull_request_id = env["PULL_REQUEST_NUMBER"]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -11,7 +11,7 @@ module Danger
11
11
 
12
12
  def self.options
13
13
  [
14
- ['--use-merged-pr=[#id]', 'The ID of an alreadty merged PR inside your history to use as a reference for the local run.']
14
+ ['--use-merged-pr=[#id]', 'The ID of an already merged PR inside your history to use as a reference for the local run.']
15
15
  ].concat(super)
16
16
  end
17
17
 
@@ -26,8 +26,9 @@ module Danger
26
26
  ENV["DANGER_USE_LOCAL_GIT"] = "YES"
27
27
  ENV["LOCAL_GIT_PR_ID"] = @pr_num if @pr_num
28
28
 
29
- dm = Dangerfile.new
30
- dm.env = EnvironmentManager.new(ENV)
29
+ env = EnvironmentManager.new(ENV)
30
+ dm = Dangerfile.new(env)
31
+ dm.init_plugins
31
32
 
32
33
  source = dm.env.ci_source
33
34
  if source.nil? or source.repo_slug.empty?
@@ -49,16 +50,24 @@ module Danger
49
50
  # We can use tokenless here, as it's running on someone's computer
50
51
  # and is IP locked, as opposed to on the CI.
51
52
  gh.support_tokenless_auth = true
52
- gh.fetch_details
53
53
 
54
- dm.env.request_source = gh
54
+ begin
55
+ gh.fetch_details
56
+ rescue Octokit::NotFound
57
+ puts "Local repository was not found on GitHub. If you're trying to test a private repository please provide a valid API token through " + "DANGER_GITHUB_API_TOKEN".yellow + " environment variable."
58
+ return
59
+ end
55
60
 
56
- dm.env.scm = GitRepo.new
61
+ dm.env.request_source = gh
57
62
 
58
- dm.env.ensure_danger_branches_are_setup
59
- dm.env.scm.diff_for_folder(".", from: dm.env.ci_source.base_commit, to: dm.env.ci_source.head_commit)
60
- dm.parse(Pathname.new(@dangerfile_path))
61
- dm.print_results
63
+ begin
64
+ dm.env.ensure_danger_branches_are_setup
65
+ dm.env.scm.diff_for_folder(".", from: dm.env.ci_source.base_commit, to: dm.env.ci_source.head_commit)
66
+ dm.parse(Pathname.new(@dangerfile_path))
67
+ dm.print_results
68
+ ensure
69
+ dm.env.clean_up
70
+ end
62
71
  end
63
72
  end
64
73
  end
@@ -6,11 +6,13 @@ module Danger
6
6
 
7
7
  self.summary = 'Run the Dangerfile.'
8
8
  self.command = 'danger'
9
+ self.version = Danger::VERSION
9
10
 
10
11
  self.plugin_prefixes = %w(claide danger)
11
12
 
12
13
  def initialize(argv)
13
- @dangerfile_path = "Dangerfile" if File.exist? "Dangerfile"
14
+ dangerfile = argv.option('dangerfile', 'Dangerfile')
15
+ @dangerfile_path = dangerfile if File.exist? dangerfile
14
16
  @base = argv.option('base')
15
17
  @head = argv.option('head')
16
18
  super
@@ -26,37 +28,47 @@ module Danger
26
28
  def self.options
27
29
  [
28
30
  ['--base=[master|dev|stable]', 'A branch/tag/commit to use as the base of the diff'],
29
- ['--head=[master|dev|stable]', 'A branch/tag/commit to use as the head']
31
+ ['--head=[master|dev|stable]', 'A branch/tag/commit to use as the head'],
32
+ ['--dangerfile=<path/to/dangerfile>', 'The location of your Dangerfile']
30
33
  ].concat(super)
31
34
  end
32
35
 
33
36
  def run
34
- # The order of the following commands is *really* important
35
- dm = Dangerfile.new
36
- dm.verbose = verbose
37
- dm.env = EnvironmentManager.new(ENV)
38
- return unless dm.env.ci_source # if it's not a PR
37
+ env = EnvironmentManager.new(ENV)
38
+ dm = Dangerfile.new(env)
39
39
 
40
- dm.env.fill_environment_vars
41
- dm.env.ensure_danger_branches_are_setup
40
+ if dm.env.pr?
41
+ dm.verbose = verbose
42
+ dm.init_plugins
42
43
 
43
- # Offer the chance for a user to specify a branch through the command line
44
- ci_base = @base || dm.env.danger_head_branch
45
- ci_head = @head || dm.env.danger_base_branch
46
- dm.env.scm.diff_for_folder(".", from: ci_base, to: ci_head)
44
+ dm.env.fill_environment_vars
47
45
 
48
- dm.parse Pathname.new(@dangerfile_path)
46
+ begin
47
+ dm.env.ensure_danger_branches_are_setup
49
48
 
50
- post_results(dm)
49
+ # Offer the chance for a user to specify a branch through the command line
50
+ ci_base = @base || dm.env.danger_head_branch
51
+ ci_head = @head || dm.env.danger_base_branch
52
+ dm.env.scm.diff_for_folder(".", from: ci_base, to: ci_head)
51
53
 
52
- dm.env.clean_up
54
+ dm.parse Pathname.new(@dangerfile_path)
53
55
 
54
- dm.print_results
56
+ post_results dm
57
+ dm.print_results
58
+ ensure
59
+ dm.env.clean_up
60
+ end
61
+ else
62
+ puts "Not a Pull Request - skipping `danger` run"
63
+ end
55
64
  end
56
65
 
57
66
  def post_results(dm)
58
67
  gh = dm.env.request_source
59
- gh.update_pull_request!(warnings: dm.warnings, errors: dm.errors, messages: dm.messages, markdowns: dm.markdowns)
68
+ violations = dm.violation_report
69
+ status = dm.status_report
70
+
71
+ gh.update_pull_request!(warnings: violations[:warnings], errors: violations[:errors], messages: violations[:messages], markdowns: status[:markdowns])
60
72
  end
61
73
  end
62
74
  end
@@ -36,6 +36,6 @@
36
36
  <%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
37
37
  <% end %>
38
38
 
39
- <p align="right" data-meta="generated_by_danger" data-base-commit="<%= @base_commit %>" data-head-commit="<%= @head_commit %>" >
39
+ <p align="right" data-meta="generated_by_danger">
40
40
  Generated by :no_entry_sign: <a href="https://github.com/danger/danger/">danger</a>
41
41
  </p>
@@ -2,6 +2,7 @@ module Danger
2
2
  class FileList < Array
3
3
  # Information about pattern: http://ruby-doc.org/core-2.2.0/File.html#method-c-fnmatch
4
4
  # e.g. "**/something.*" for any file called something with any extension
5
+
5
6
  def include?(pattern)
6
7
  self.each do |current|
7
8
  return true if File.fnmatch(pattern, current)
@@ -0,0 +1,217 @@
1
+ # So much was ripped direct from CocoaPods-Core - thanks!
2
+
3
+ require 'danger/danger_core/dangerfile_dsl'
4
+ require 'danger/danger_core/standard_error'
5
+
6
+ require 'danger/danger_core/plugins/dangerfile_messaging_plugin'
7
+ require 'danger/danger_core/plugins/dangerfile_import_plugin'
8
+ require 'danger/danger_core/plugins/dangerfile_git_plugin'
9
+ require 'danger/danger_core/plugins/dangerfile_github_plugin'
10
+
11
+ require 'danger/danger_core/plugins/dangerfile_github_plugin'
12
+
13
+ module Danger
14
+ class Dangerfile
15
+ include Danger::Dangerfile::DSL
16
+
17
+ attr_accessor :env, :verbose, :plugins
18
+
19
+ # @return [Pathname] the path where the Dangerfile was loaded from. It is nil
20
+ # if the Dangerfile was generated programmatically.
21
+ #
22
+ attr_accessor :defined_in_file
23
+
24
+ # @return [String] a string useful to represent the Dangerfile in a message
25
+ # presented to the user.
26
+ #
27
+ def to_s
28
+ 'Dangerfile'
29
+ end
30
+
31
+ # These are the classes that are allowed to also use method_missing
32
+ # in order to provide broader plugin support
33
+ def core_plugin_classes
34
+ [
35
+ Danger::DangerfileMessagingPlugin,
36
+ Danger::DangerfileImportPlugin,
37
+ Danger::DangerfileGitHubPlugin,
38
+ Danger::DangerfileGitPlugin
39
+ ]
40
+ end
41
+
42
+ # Both of these methods exist on all objects
43
+ # http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-warn
44
+ # http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-fail
45
+ # However, as we're using using them in the DSL, they won't
46
+ # get method_missing called correctly.
47
+
48
+ def warn(*args, &blk)
49
+ method_missing(:warn, *args, &blk)
50
+ end
51
+
52
+ def fail(*args, &blk)
53
+ method_missing(:fail, *args, &blk)
54
+ end
55
+
56
+ # When an undefined method is called, we check to see if it's something
57
+ # that the DSLs have, then starts looking at plugins support.
58
+ def method_missing(method_sym, *arguments, &_block)
59
+ @core_plugins.each do |plugin|
60
+ if plugin.public_methods(false).include?(method_sym)
61
+ return plugin.send(method_sym, *arguments)
62
+ end
63
+ end
64
+ super
65
+ end
66
+
67
+ def initialize(env_manager)
68
+ @plugins = {}
69
+ @core_plugins = []
70
+
71
+ # Triggers the core plugins
72
+ @env = env_manager
73
+
74
+ # Triggers local plugins from the root of a project
75
+ Dir["./danger_plugins/*.rb"].each do |file|
76
+ require File.expand_path(file)
77
+ end
78
+
79
+ refresh_plugins if env_manager.pr?
80
+ end
81
+
82
+ # Iterate through available plugin classes and initialize them with
83
+ # a reference to this Dangerfile
84
+ def refresh_plugins
85
+ plugins = ObjectSpace.each_object(Class).select { |klass| klass < Danger::Plugin }
86
+ plugins.each do |klass|
87
+ next if klass.singleton_class?
88
+ plugin = klass.new(self)
89
+ next if plugin.nil? || @plugins[klass]
90
+
91
+ name = plugin.class.instance_name
92
+ self.class.send(:attr_reader, name)
93
+ instance_variable_set("@#{name}", plugin)
94
+
95
+ @plugins[klass] = plugin
96
+ @core_plugins << plugin if core_plugin_classes.include? klass
97
+ end
98
+ end
99
+ alias init_plugins refresh_plugins
100
+
101
+ def core_dsl_attributes
102
+ @core_plugins.map { |plugin| { plugin: plugin, methods: plugin.public_methods(false) } }
103
+ end
104
+
105
+ def external_dsl_attributes
106
+ plugins.values.reject { |plugin| @core_plugins.include? plugin } .map { |plugin| { plugin: plugin, methods: plugin.public_methods(false) } }
107
+ end
108
+
109
+ def method_values_for_plugin_hashes(plugin_hashes)
110
+ plugin_hashes.flat_map do |plugin_hash|
111
+ plugin = plugin_hash[:plugin]
112
+ methods = plugin_hash[:methods].reject { |name| plugin.method(name).arity != 0 }
113
+
114
+ methods.map do |method|
115
+ value = plugin.send(method)
116
+ value = value.scan(/.{,80}/).to_a.each(&:strip!).join("\n") if method == :pr_body
117
+
118
+ # So that we either have one value per row
119
+ # or we have [] for an empty array
120
+ value = value.join("\n") if value.kind_of?(Array) && value.count > 0
121
+ [method.to_s, value]
122
+ end
123
+ end
124
+ end
125
+
126
+ # Iterates through the DSL's attributes, and table's the output
127
+ def print_known_info
128
+ rows = []
129
+ rows += method_values_for_plugin_hashes(core_dsl_attributes)
130
+ rows << ["---", "---"]
131
+ rows += method_values_for_plugin_hashes(external_dsl_attributes)
132
+ rows << ["---", "---"]
133
+ rows << ["SCM", env.scm.class]
134
+ rows << ["Source", env.ci_source.class]
135
+ rows << ["Requests", env.request_source.class]
136
+ rows << ["Base Commit", env.meta_info_for_base]
137
+ rows << ["Head Commit", env.meta_info_for_head]
138
+
139
+ params = {}
140
+ params[:rows] = rows.each { |current| current[0] = current[0].yellow }
141
+ params[:title] = "Danger v#{Danger::VERSION}\nDSL Attributes".green
142
+
143
+ puts ""
144
+ puts Terminal::Table.new(params)
145
+ puts ""
146
+ end
147
+
148
+ # Parses the file at a path, optionally takes the content of the file for DI
149
+ #
150
+ def parse(path, contents = nil)
151
+ print_known_info if verbose
152
+
153
+ contents ||= File.open(path, 'r:utf-8', &:read)
154
+
155
+ # Work around for Rubinius incomplete encoding in 1.9 mode
156
+ if contents.respond_to?(:encoding) && contents.encoding.name != 'UTF-8'
157
+ contents.encode!('UTF-8')
158
+ end
159
+
160
+ if contents.tr!('“”‘’‛', %(""'''))
161
+ # Changes have been made
162
+ puts "Your #{path.basename} has had smart quotes sanitised. " \
163
+ 'To avoid issues in the future, you should not use ' \
164
+ 'TextEdit for editing it. If you are not using TextEdit, ' \
165
+ 'you should turn off smart quotes in your editor of choice.'.red
166
+ end
167
+
168
+ if contents.include?("puts")
169
+ puts "You used `puts` in your Dangerfile. To print out text to GitHub use `message` instead"
170
+ end
171
+
172
+ self.defined_in_file = path
173
+ instance_eval do
174
+ # rubocop:disable Lint/RescueException
175
+ begin
176
+ # rubocop:disable Eval
177
+ eval(contents, nil, path.to_s)
178
+ # rubocop:enable Eval
179
+ rescue Exception => e
180
+ message = "Invalid `#{path.basename}` file: #{e.message}"
181
+ raise DSLError.new(message, path, e.backtrace, contents)
182
+ end
183
+ # rubocop:enable Lint/RescueException
184
+ end
185
+ end
186
+
187
+ def print_results
188
+ status = status_report
189
+ return if (status[:errors] + status[:warnings] + status[:messages] + status[:markdowns]).count == 0
190
+
191
+ puts ""
192
+ puts "danger results:"
193
+ [:errors, :warnings, :messages].each do |current|
194
+ params = {}
195
+ params[:rows] = status[current].map { |item| [item] }
196
+ next unless params[:rows].count > 0
197
+ params[:title] = case current
198
+ when :errors
199
+ current.to_s.capitalize.red
200
+ when :warnings
201
+ current.to_s.capitalize.yellow
202
+ else
203
+ current.to_s.capitalize
204
+ end
205
+
206
+ puts ""
207
+ puts Terminal::Table.new(params)
208
+ puts ""
209
+ end
210
+
211
+ puts "Markdown: ".green if status[:markdowns].count > 0
212
+ status[:markdowns].each do |current_markdown|
213
+ puts current_markdown
214
+ end
215
+ end
216
+ end
217
+ end