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
@@ -4,7 +4,7 @@ require 'redcarpet'
4
4
 
5
5
  module Danger
6
6
  class GitHub
7
- attr_accessor :ci_source, :pr_json, :issue_json, :environment, :base_commit, :head_commit, :support_tokenless_auth, :ignored_violations, :github_host
7
+ attr_accessor :ci_source, :pr_json, :issue_json, :environment, :support_tokenless_auth, :ignored_violations, :github_host
8
8
 
9
9
  def initialize(ci_source, environment)
10
10
  self.ci_source = ci_source
@@ -21,10 +21,7 @@ module Danger
21
21
 
22
22
  def client
23
23
  raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN`" if !@token && !support_tokenless_auth
24
-
25
- @client ||= Octokit::Client.new(
26
- access_token: @token
27
- )
24
+ @client ||= Octokit::Client.new(access_token: @token)
28
25
  end
29
26
 
30
27
  def markdown_parser
@@ -48,34 +45,6 @@ module Danger
48
45
  self.issue_json = client.get(href)
49
46
  end
50
47
 
51
- def base_commit
52
- self.pr_json[:base][:sha]
53
- end
54
-
55
- def head_commit
56
- self.pr_json[:head][:sha]
57
- end
58
-
59
- def branch_for_merge
60
- self.pr_json[:base][:ref]
61
- end
62
-
63
- def pr_title
64
- self.pr_json[:title].to_s
65
- end
66
-
67
- def pr_body
68
- self.pr_json[:body].to_s
69
- end
70
-
71
- def pr_author
72
- self.pr_json[:user][:login].to_s
73
- end
74
-
75
- def pr_labels
76
- self.issue_json[:labels].map { |l| l[:name] }
77
- end
78
-
79
48
  # Sending data to GitHub
80
49
  def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [])
81
50
  comment_result = {}
@@ -4,8 +4,7 @@ require 'git'
4
4
 
5
5
  module Danger
6
6
  class GitRepo
7
- attr_accessor :diff
8
- attr_accessor :log
7
+ attr_accessor :diff, :log
9
8
 
10
9
  def diff_for_folder(folder, from: "master", to: 'HEAD')
11
10
  repo = Git.open folder
@@ -16,33 +15,5 @@ module Danger
16
15
  def exec(string)
17
16
  `git #{string}`.strip
18
17
  end
19
-
20
- def added_files
21
- Danger::FileList.new(@diff.select { |diff| diff.type == "new" }.map(&:path))
22
- end
23
-
24
- def deleted_files
25
- Danger::FileList.new(@diff.select { |diff| diff.type == "deleted" }.map(&:path))
26
- end
27
-
28
- def modified_files
29
- Danger::FileList.new(@diff.stats[:files].keys)
30
- end
31
-
32
- def lines_of_code
33
- @diff.lines
34
- end
35
-
36
- def deletions
37
- @diff.deletions
38
- end
39
-
40
- def insertions
41
- @diff.insertions
42
- end
43
-
44
- def commits
45
- log.to_a
46
- end
47
18
  end
48
19
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "0.7.4".freeze
2
+ VERSION = "0.8.0".freeze
3
3
  DESCRIPTION = "Automate your PR etiquette.".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-04 00:00:00.000000000 Z
12
+ date: 2016-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -166,19 +166,19 @@ dependencies:
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  - !ruby/object:Gem::Dependency
169
- name: fastlane
169
+ name: pry
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - ">="
173
173
  - !ruby/object:Gem::Version
174
- version: 1.49.0
174
+ version: '0'
175
175
  type: :development
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
178
178
  requirements:
179
179
  - - ">="
180
180
  - !ruby/object:Gem::Version
181
- version: 1.49.0
181
+ version: '0'
182
182
  - !ruby/object:Gem::Dependency
183
183
  name: rubocop
184
184
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +193,62 @@ dependencies:
193
193
  - - "~>"
194
194
  - !ruby/object:Gem::Version
195
195
  version: 0.38.0
196
+ - !ruby/object:Gem::Dependency
197
+ name: yard
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ - !ruby/object:Gem::Dependency
211
+ name: listen
212
+ requirement: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - '='
215
+ - !ruby/object:Gem::Version
216
+ version: 3.0.7
217
+ type: :development
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - '='
222
+ - !ruby/object:Gem::Version
223
+ version: 3.0.7
224
+ - !ruby/object:Gem::Dependency
225
+ name: guard
226
+ requirement: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ type: :development
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ - !ruby/object:Gem::Dependency
239
+ name: guard-rspec
240
+ requirement: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ type: :development
246
+ prerelease: false
247
+ version_requirements: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ version: '0'
196
252
  description: Create a Dangerfile to introspect your pull request in CI, makes it easy
197
253
  to enforce social conventions like changelogs and tests.
198
254
  email:
@@ -209,33 +265,38 @@ files:
209
265
  - lib/assets/DangerfileTemplate
210
266
  - lib/assets/PluginTemplate.rb.template
211
267
  - lib/danger.rb
212
- - lib/danger/available_values.rb
213
268
  - lib/danger/ci_source/buildkite.rb
214
269
  - lib/danger/ci_source/ci_source.rb
215
270
  - lib/danger/ci_source/circle.rb
271
+ - lib/danger/ci_source/circle_api.rb
272
+ - lib/danger/ci_source/drone.rb
216
273
  - lib/danger/ci_source/jenkins.rb
217
274
  - lib/danger/ci_source/local_git_repo.rb
275
+ - lib/danger/ci_source/semaphore.rb
218
276
  - lib/danger/ci_source/travis.rb
219
277
  - lib/danger/ci_source/xcode_server.rb
220
- - lib/danger/circle_api.rb
221
278
  - lib/danger/commands/init.rb
222
279
  - lib/danger/commands/init_helpers/interviewer.rb
223
280
  - lib/danger/commands/local.rb
224
281
  - lib/danger/commands/new_plugin.rb
225
282
  - lib/danger/commands/runner.rb
226
283
  - lib/danger/comment_generators/github.md.erb
284
+ - lib/danger/core_ext/file_list.rb
227
285
  - lib/danger/core_ext/string.rb
228
- - lib/danger/dangerfile.rb
229
- - lib/danger/dangerfile_dsl.rb
230
- - lib/danger/environment_manager.rb
231
- - lib/danger/plugin.rb
232
- - lib/danger/plugins/protect_files.rb
233
- - lib/danger/request_sources/github.rb
234
- - lib/danger/scm_source/file_list.rb
286
+ - lib/danger/danger_core/dangerfile.rb
287
+ - lib/danger/danger_core/dangerfile_dsl.rb
288
+ - lib/danger/danger_core/environment_manager.rb
289
+ - lib/danger/danger_core/plugins/dangerfile_git_plugin.rb
290
+ - lib/danger/danger_core/plugins/dangerfile_github_plugin.rb
291
+ - lib/danger/danger_core/plugins/dangerfile_import_plugin.rb
292
+ - lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb
293
+ - lib/danger/danger_core/standard_error.rb
294
+ - lib/danger/danger_core/violation.rb
295
+ - lib/danger/plugin_support/plugin.rb
296
+ - lib/danger/plugin_support/plugin_parser.rb
297
+ - lib/danger/request_source/github.rb
235
298
  - lib/danger/scm_source/git_repo.rb
236
- - lib/danger/standard_error.rb
237
299
  - lib/danger/version.rb
238
- - lib/danger/violation.rb
239
300
  homepage: http://github.com/danger/danger
240
301
  licenses:
241
302
  - MIT
@@ -256,8 +317,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
317
  version: '0'
257
318
  requirements: []
258
319
  rubyforge_project:
259
- rubygems_version: 2.4.8
320
+ rubygems_version: 2.2.2
260
321
  signing_key:
261
322
  specification_version: 4
262
323
  summary: Automate your PR etiquette.
263
324
  test_files: []
325
+ has_rdoc:
@@ -1,29 +0,0 @@
1
- module Danger
2
- # Defines all the values that should be available in someone's Dangerfile
3
- class AvailableValues
4
- def self.all
5
- self.scm + self.request_source
6
- end
7
-
8
- def self.scm
9
- [
10
- :lines_of_code,
11
- :modified_files,
12
- :deleted_files,
13
- :added_files,
14
- :deletions,
15
- :insertions,
16
- :commits
17
- ]
18
- end
19
-
20
- def self.request_source
21
- [
22
- :pr_title,
23
- :pr_body,
24
- :pr_author,
25
- :pr_labels
26
- ]
27
- end
28
- end
29
- end
@@ -1,123 +0,0 @@
1
- # So much was ripped direct from CocoaPods-Core - thanks!
2
-
3
- require 'danger/dangerfile_dsl'
4
- require 'danger/standard_error'
5
-
6
- module Danger
7
- class Dangerfile
8
- include Danger::Dangerfile::DSL
9
-
10
- attr_accessor :env, :warnings, :errors, :messages, :markdowns, :verbose
11
-
12
- # @return [Pathname] the path where the Dangerfile was loaded from. It is nil
13
- # if the Dangerfile was generated programmatically.
14
- #
15
- attr_accessor :defined_in_file
16
-
17
- # @return [String] a string useful to represent the Dangerfile in a message
18
- # presented to the user.
19
- #
20
- def to_s
21
- 'Dangerfile'
22
- end
23
-
24
- # Iterates through the DSL's attributes, and table's the output
25
- def print_known_info
26
- rows = []
27
-
28
- AvailableValues.all.each do |key|
29
- value = self.send(key)
30
- value = value.scan(/.{,80}/).to_a.each(&:strip!).join("\n") if key == :pr_body
31
-
32
- # So that we either have one value per row
33
- # or we have [] for an empty array
34
- value = value.join("\n") if value.kind_of?(Array) && value.count > 0
35
-
36
- rows << [key.to_s, value]
37
- end
38
-
39
- rows << ["---", "---"]
40
- rows << ["SCM", env.scm.class]
41
- rows << ["Source", env.ci_source.class]
42
- rows << ["Requests", env.request_source.class]
43
- rows << ["Base Commit", env.meta_info_for_base]
44
- rows << ["Head Commit", env.meta_info_for_head]
45
-
46
- params = {}
47
- params[:rows] = rows.each { |current| current[0] = current[0].yellow }
48
- params[:title] = "Danger v#{Danger::VERSION}\nDSL Attributes".green
49
-
50
- puts ""
51
- puts Terminal::Table.new(params)
52
- puts ""
53
- end
54
-
55
- # Parses the file at a path, optionally takes the content of the file for DI
56
- #
57
- def parse(path, contents = nil)
58
- print_known_info if verbose
59
-
60
- contents ||= File.open(path, 'r:utf-8', &:read)
61
-
62
- # Work around for Rubinius incomplete encoding in 1.9 mode
63
- if contents.respond_to?(:encoding) && contents.encoding.name != 'UTF-8'
64
- contents.encode!('UTF-8')
65
- end
66
-
67
- if contents.tr!('“”‘’‛', %(""'''))
68
- # Changes have been made
69
- puts "Your #{path.basename} has had smart quotes sanitised. " \
70
- 'To avoid issues in the future, you should not use ' \
71
- 'TextEdit for editing it. If you are not using TextEdit, ' \
72
- 'you should turn off smart quotes in your editor of choice.'.red
73
- end
74
-
75
- if contents.include?("puts")
76
- puts "You used `puts` in your Dangerfile. To print out text to GitHub use `message` instead"
77
- end
78
-
79
- self.defined_in_file = path
80
- instance_eval do
81
- # rubocop:disable Lint/RescueException
82
- begin
83
- # rubocop:disable Eval
84
- eval(contents, nil, path.to_s)
85
- # rubocop:enable Eval
86
- rescue Exception => e
87
- message = "Invalid `#{path.basename}` file: #{e.message}"
88
- raise DSLError.new(message, path, e.backtrace, contents)
89
- end
90
- # rubocop:enable Lint/RescueException
91
- end
92
- end
93
-
94
- def print_results
95
- return if (self.errors + self.warnings + self.messages + self.markdowns).count == 0
96
-
97
- puts ""
98
- puts "danger results:"
99
- [:errors, :warnings, :messages].each do |current|
100
- params = {}
101
- params[:rows] = self.send(current).collect { |a| [a.message] }
102
- next unless params[:rows].count > 0
103
- params[:title] = case current
104
- when :errors
105
- current.to_s.capitalize.red
106
- when :warnings
107
- current.to_s.capitalize.yellow
108
- else
109
- current.to_s.capitalize
110
- end
111
-
112
- puts ""
113
- puts Terminal::Table.new(params)
114
- puts ""
115
- end
116
-
117
- puts "Markdown: ".green if self.markdowns.count > 0
118
- self.markdowns.each do |current_markdown|
119
- puts current_markdown
120
- end
121
- end
122
- end
123
- end
@@ -1,159 +0,0 @@
1
- require 'danger/violation'
2
-
3
- module Danger
4
- class Dangerfile
5
- module DSL
6
- # @!group Enviroment
7
- # @return [EnvironmentManager] Provides access to the raw Travis/Circle/Buildkite/GitHub
8
- # objects, which you can use to pull out extra bits of information. _Warning_
9
- # the api of these objects is **not** considered a part of the Dangerfile public
10
- # API, and is viable to change occasionally on the whims of developers.
11
-
12
- attr_reader :env
13
-
14
- def initialize
15
- self.warnings = []
16
- self.errors = []
17
- self.messages = []
18
- self.markdowns = []
19
-
20
- load_default_plugins
21
- end
22
-
23
- def import(path)
24
- raise "`import` requires a string" unless path.kind_of?(String)
25
- path += ".rb" unless path.end_with?(".rb")
26
-
27
- if path.start_with?("http")
28
- import_url(path)
29
- else
30
- import_local(path)
31
- end
32
- end
33
-
34
- # Download a remote plugin and use it locally
35
- #
36
- # @param [String] url
37
- # https URL to the Ruby file to use
38
- def import_url(url)
39
- raise "URL is not https, for security reasons `danger` only supports encrypted requests" unless url.start_with?("https://")
40
-
41
- require 'tmpdir'
42
- require 'faraday'
43
- require 'faraday_middleware'
44
-
45
- @http_client ||= Faraday.new do |b|
46
- b.use FaradayMiddleware::FollowRedirects
47
- b.adapter :net_http
48
- end
49
- content = @http_client.get(url)
50
-
51
- Dir.mktmpdir do |dir|
52
- path = File.join(dir, "temporary_remote_action.rb")
53
- File.write(path, content.body)
54
- import_local(path)
55
- end
56
- end
57
-
58
- # Import one or more local plugins
59
- #
60
- # @param [String] path
61
- # The path to the file to import
62
- # Can also be a pattern (./**/*plugin.rb)
63
- def import_local(path)
64
- Dir[path].each do |file|
65
- require File.expand_path(file) # without the expand_path it would fail if the path doesn't start with ./
66
- end
67
- end
68
-
69
- def should_ignore_violation(message)
70
- env.request_source.ignored_violations.include? message
71
- end
72
-
73
- # Declares a CI blocking error
74
- #
75
- # @param [String] message
76
- # The message to present to the user
77
- # @param [Boolean] sticky
78
- # Whether the message should be kept after it was fixed
79
- def fail(message, sticky: true)
80
- return if should_ignore_violation(message)
81
- self.errors << Violation.new(message, sticky)
82
- puts "Raising error '#{message}'"
83
- end
84
-
85
- # Specifies a problem, but not critical
86
- #
87
- # @param [String] message
88
- # The message to present to the user
89
- # @param [Boolean] sticky
90
- # Whether the message should be kept after it was fixed
91
- def warn(message, sticky: true)
92
- return if should_ignore_violation(message)
93
- self.warnings << Violation.new(message, sticky)
94
- puts "Printing warning '#{message}'"
95
- end
96
-
97
- # Print out a generate message on the PR
98
- #
99
- # @param [String] message
100
- # The message to present to the user
101
- # @param [Boolean] sticky
102
- # Whether the message should be kept after it was fixed
103
- def message(message, sticky: true)
104
- self.messages << Violation.new(message, sticky)
105
- puts "Printing message '#{message}'"
106
- end
107
-
108
- # Print markdown to below the table
109
- #
110
- # @param [String] message
111
- # The markdown based message to be printed below the table
112
- def markdown(message)
113
- self.markdowns << message
114
- puts "Printing markdown #{message}"
115
- end
116
-
117
- # When an undefined method is called, we check to see if it's something
118
- # that either the `scm` or the `request_source` can handle.
119
- # This opens us up to letting those object extend themselves naturally.
120
- # This will also look for plugins
121
- def method_missing(method_sym, *arguments, &_block)
122
- # SCM Source
123
- if AvailableValues.scm.include?(method_sym)
124
- return env.scm.send(method_sym)
125
- end
126
-
127
- # Request Source
128
- if AvailableValues.request_source.include?(method_sym)
129
- return env.request_source.send(method_sym)
130
- end
131
-
132
- # Plugins
133
- class_name = method_sym.to_s.danger_class
134
- if Danger::Dangerfile::DSL.const_defined?(class_name)
135
- plugin_ref = Danger::Dangerfile::DSL.const_get(class_name)
136
- if plugin_ref < Plugin
137
- plugin_ref.new(self).run(*arguments)
138
- else
139
- raise "'#{method_sym}' is not a valid danger plugin".red
140
- end
141
- else
142
- raise "Unknown method '#{method_sym}', please check out the documentation for available plugins".red
143
- end
144
- end
145
-
146
- private
147
-
148
- def load_default_plugins
149
- Dir["./lib/danger/plugins/*.rb"].each do |file|
150
- require File.expand_path(file)
151
- end
152
-
153
- Dir["./danger_plugins/*.rb"].each do |file|
154
- require File.expand_path(file)
155
- end
156
- end
157
- end
158
- end
159
- end