danger 0.8.4 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/bin/danger +1 -1
  3. data/lib/danger.rb +12 -12
  4. data/lib/danger/ci_source/buildkite.rb +5 -5
  5. data/lib/danger/ci_source/ci_source.rb +2 -2
  6. data/lib/danger/ci_source/circle.rb +11 -11
  7. data/lib/danger/ci_source/drone.rb +5 -5
  8. data/lib/danger/ci_source/jenkins.rb +4 -4
  9. data/lib/danger/ci_source/local_git_repo.rb +10 -10
  10. data/lib/danger/ci_source/semaphore.rb +5 -5
  11. data/lib/danger/ci_source/travis.rb +6 -6
  12. data/lib/danger/ci_source/xcode_server.rb +2 -2
  13. data/lib/danger/commands/init.rb +66 -66
  14. data/lib/danger/commands/init_helpers/interviewer.rb +14 -14
  15. data/lib/danger/commands/local.rb +9 -8
  16. data/lib/danger/commands/plugins/plugin_new.rb +8 -8
  17. data/lib/danger/commands/plugins/plugin_readme.rb +2 -2
  18. data/lib/danger/commands/runner.rb +3 -3
  19. data/lib/danger/comment_generators/github.md.erb +1 -1
  20. data/lib/danger/core_ext/string.rb +1 -1
  21. data/lib/danger/danger_core/dangerfile.rb +12 -12
  22. data/lib/danger/danger_core/dangerfile_dsl.rb +1 -1
  23. data/lib/danger/danger_core/environment_manager.rb +6 -6
  24. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +9 -9
  25. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +9 -9
  26. data/lib/danger/danger_core/plugins/dangerfile_import_plugin.rb +10 -6
  27. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +1 -1
  28. data/lib/danger/plugin_support/plugin.rb +1 -1
  29. data/lib/danger/plugin_support/plugin_file_resolver.rb +23 -23
  30. data/lib/danger/plugin_support/plugin_parser.rb +40 -3
  31. data/lib/danger/request_source/github.rb +14 -14
  32. data/lib/danger/request_source/request_source.rb +4 -4
  33. data/lib/danger/scm_source/git_repo.rb +2 -2
  34. data/lib/danger/version.rb +2 -2
  35. metadata +3 -3
@@ -25,7 +25,7 @@ module Danger
25
25
 
26
26
  class DangerfileImportPlugin < Plugin
27
27
  def self.instance_name
28
- "plugin"
28
+ 'plugin'
29
29
  end
30
30
 
31
31
  # @!group Plugins
@@ -34,11 +34,13 @@ module Danger
34
34
  # @param [String] path
35
35
  # a local path or a https URL to the Ruby file to import
36
36
  # a danger plugin from.
37
+ # @return [void]
38
+
37
39
  def import(path)
38
- raise "`import` requires a string" unless path.kind_of?(String)
39
- path += ".rb" unless path.end_with?(".rb")
40
+ raise '`import` requires a string' unless path.kind_of?(String)
41
+ path += '.rb' unless path.end_with?('.rb')
40
42
 
41
- if path.start_with?("http")
43
+ if path.start_with?('http')
42
44
  import_url(path)
43
45
  else
44
46
  import_local(path)
@@ -52,8 +54,9 @@ module Danger
52
54
  #
53
55
  # @param [String] url
54
56
  # https URL to the Ruby file to use
57
+ # @return [void]
55
58
  def import_url(url)
56
- raise "URL is not https, for security reasons `danger` only supports encrypted requests" unless url.start_with?("https://")
59
+ raise 'URL is not https, for security reasons `danger` only supports encrypted requests' unless url.start_with?('https://')
57
60
 
58
61
  require 'tmpdir'
59
62
  require 'faraday'
@@ -64,7 +67,7 @@ module Danger
64
67
  content = @http_client.get(url)
65
68
 
66
69
  Dir.mktmpdir do |dir|
67
- path = File.join(dir, "temporary_remote_action.rb")
70
+ path = File.join(dir, 'temporary_remote_action.rb')
68
71
  File.write(path, content.body)
69
72
  import_local(path)
70
73
  end
@@ -76,6 +79,7 @@ module Danger
76
79
  # @param [String] path
77
80
  # The path to the file to import
78
81
  # Can also be a pattern (./**/*plugin.rb)
82
+ # @return [void]
79
83
  def import_local(path)
80
84
  Dir[path].each do |file|
81
85
  # Without the expand_path it would fail if the path doesn't start with ./
@@ -54,7 +54,7 @@ module Danger
54
54
  end
55
55
 
56
56
  def self.instance_name
57
- "messaging"
57
+ 'messaging'
58
58
  end
59
59
 
60
60
  # @!group Core
@@ -5,7 +5,7 @@ module Danger
5
5
  end
6
6
 
7
7
  def self.instance_name
8
- to_s.gsub("Danger", "").danger_underscore.split('/').last
8
+ to_s.gsub('Danger', '').danger_underscore.split('/').last
9
9
  end
10
10
 
11
11
  # Both of these methods exist on all objects
@@ -16,32 +16,32 @@ module Danger
16
16
 
17
17
  # When given a list of gems
18
18
  elsif @refs and @refs.kind_of? Array
19
-
20
- Dir.mktmpdir do |dir|
21
- gem_names = @refs
22
- deps = gem_names.map { |name| Bundler::Dependency.new(name, ">= 0") }
23
-
24
- # Use Gems from rubygems.org
25
- source = Bundler::SourceList.new
26
- source.add_rubygems_remote("https://rubygems.org")
27
-
28
- # Create a definition to bundle, make sure it always updates
29
- # and uses the latest version from the server
30
- bundler = Bundler::Definition.new(nil, deps, source, true)
31
- bundler.resolve_remotely!
32
-
33
- # Install the gems into a tmp dir
34
- options = { path: dir }
35
- Bundler::Installer.install(Pathname.new(dir), bundler, options)
36
-
37
- # Get the name'd gems out of bundler, then pull out all their paths
38
- gems = gem_names.flat_map { |name| bundler.specs[name] }
39
- gems.flat_map { |gem| Dir.glob(File.join(gem.gem_dir, "lib/**/**/**.rb")) }
19
+ Bundler.with_clean_env do
20
+ Dir.mktmpdir do |dir|
21
+ gem_names = @refs
22
+ deps = gem_names.map { |name| Bundler::Dependency.new(name, '>= 0') }
23
+
24
+ # Use Gems from rubygems.org
25
+ source = Bundler::SourceList.new
26
+ source.add_rubygems_remote('https://rubygems.org')
27
+
28
+ # Create a definition to bundle, make sure it always updates
29
+ # and uses the latest version from the server
30
+ bundler = Bundler::Definition.new(nil, deps, source, true)
31
+ bundler.resolve_remotely!
32
+
33
+ # Install the gems into a tmp dir
34
+ options = { path: dir }
35
+ Bundler::Installer.install(Pathname.new(dir), bundler, options)
36
+
37
+ # Get the name'd gems out of bundler, then pull out all their paths
38
+ gems = gem_names.flat_map { |name| bundler.specs[name] }
39
+ gems.flat_map { |gem| Dir.glob(File.join(gem.gem_dir, 'lib/**/**/**.rb')) }
40
+ end
40
41
  end
41
-
42
42
  # When empty, imply you want to test the current lib folder as a plugin
43
43
  else
44
- Dir.glob(File.join(".", "lib/*.rb"))
44
+ Dir.glob(File.join('.', 'lib/*.rb')).map { |path| File.expand_path(path) }
45
45
  end
46
46
  end
47
47
  end
@@ -1,5 +1,37 @@
1
1
  require 'json'
2
2
 
3
+ =begin
4
+
5
+ So you want to improve this? Great. Hard thing is getting yourself into a position where you
6
+ have access to all the tokens, so here's something you should run in `bundle exec pry` to dig in:
7
+
8
+ require 'danger'
9
+ require 'yard'
10
+ parser = Danger::PluginParser.new "spec/fixtures/plugins/example_fully_documented.rb"
11
+ parser.parse
12
+ plugins = parser.plugins_from_classes(parser.classes_in_file)
13
+ git = plugins.first
14
+ klass = git
15
+ parser.to_dict(plugins)
16
+
17
+ Then some helpers
18
+
19
+ attribute_meths = klass.attributes[:instance].values.map(&:values).flatten
20
+
21
+ methods = klass.meths - klass.inherited_meths - attribute_meths
22
+ usable_methods = methods.select { |m| m.visibility == :public }.reject { |m| m.name == :initialize }
23
+
24
+
25
+ the alternative, is to add
26
+
27
+ require 'pry'
28
+ binding.pry
29
+
30
+ anywhere inside the source code below.
31
+
32
+ =end
33
+
34
+
3
35
  module Danger
4
36
  class PluginParser
5
37
  attr_accessor :registry
@@ -47,6 +79,7 @@ module Danger
47
79
  {
48
80
  name: meth.name,
49
81
  body_md: meth.docstring,
82
+ params: meth.parameters,
50
83
  tags: meth.tags.map do |t|
51
84
  {
52
85
  name: t.tag_name,
@@ -64,10 +97,14 @@ module Danger
64
97
  end
65
98
 
66
99
  classes.map do |klass|
67
- # Adds the class being parsed into the ruby runtime
100
+ # Adds the class being parsed into the ruby runtime, so that we can access it's instance_name
68
101
  require klass.file
69
102
  real_klass = Danger.const_get klass.name
70
103
  attribute_meths = klass.attributes[:instance].values.map(&:values).flatten
104
+
105
+ methods = klass.meths - klass.inherited_meths - attribute_meths
106
+ usable_methods = methods.select { |m| m.visibility == :public }.reject { |m| m.name == :initialize || m.name == :insance_name }
107
+
71
108
  {
72
109
  name: klass.name.to_s,
73
110
  body_md: klass.docstring,
@@ -76,8 +113,8 @@ module Danger
76
113
  attributes: klass.attributes[:instance].map do |pair|
77
114
  { pair.first => d_attr.call(pair.last) }
78
115
  end,
79
- methods: (klass.meths - klass.inherited_meths - attribute_meths ).select { |m| m.visibility == :public }.map { |m| d_meth.call(m) },
80
- tags: klass.tags.select { |t| t.tag_name == "tags" }.map(&:name).compact,
116
+ methods: usable_methods.map { |m| d_meth.call(m) },
117
+ tags: klass.tags.select { |t| t.tag_name == "tags" }.map(&:text).compact,
81
118
  see: klass.tags.select { |t| t.tag_name == "see" }.map(&:name).map(&:split).flatten.compact,
82
119
  file: klass.file.gsub(File.expand_path("."), "")
83
120
  }
@@ -13,9 +13,9 @@ module Danger
13
13
  self.support_tokenless_auth = false
14
14
 
15
15
  Octokit.auto_paginate = true
16
- @token = @environment["DANGER_GITHUB_API_TOKEN"]
17
- if @environment["DANGER_GITHUB_API_HOST"]
18
- Octokit.api_endpoint = @environment["DANGER_GITHUB_API_HOST"]
16
+ @token = @environment['DANGER_GITHUB_API_TOKEN']
17
+ if @environment['DANGER_GITHUB_API_HOST']
18
+ Octokit.api_endpoint = @environment['DANGER_GITHUB_API_HOST']
19
19
  end
20
20
  end
21
21
 
@@ -24,11 +24,11 @@ module Danger
24
24
  end
25
25
 
26
26
  def host
27
- @host = @environment["DANGER_GITHUB_HOST"] || "github.com"
27
+ @host = @environment['DANGER_GITHUB_HOST'] || 'github.com'
28
28
  end
29
29
 
30
30
  def client
31
- raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN`" if !@token && !support_tokenless_auth
31
+ raise 'No API token given, please provide one using `DANGER_GITHUB_API_TOKEN`' if !@token && !support_tokenless_auth
32
32
  @client ||= Octokit::Client.new(access_token: @token)
33
33
  end
34
34
 
@@ -39,7 +39,7 @@ module Danger
39
39
  def setup_danger_branches
40
40
  # we can use a github specific feature here:
41
41
  base_commit = self.pr_json[:base][:sha]
42
- head_commit = self.scm.head_commit
42
+ head_commit = self.pr_json[:head][:sha]
43
43
 
44
44
  # Next, we want to ensure that we have a version of the current branch at a known location
45
45
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
@@ -119,7 +119,7 @@ module Danger
119
119
  begin
120
120
  client.create_status(ci_source.repo_slug, latest_pr_commit_ref, status, {
121
121
  description: message,
122
- context: "danger/danger",
122
+ context: 'danger/danger',
123
123
  target_url: details_url
124
124
  })
125
125
  rescue
@@ -146,8 +146,8 @@ module Danger
146
146
  end
147
147
 
148
148
  def random_compliment
149
- compliment = ["Well done.", "Congrats.", "Woo!",
150
- "Yay.", "Jolly good show.", "Good on 'ya.", "Nice work."]
149
+ compliment = ['Well done.', 'Congrats.', 'Woo!',
150
+ 'Yay.', 'Jolly good show.', "Good on 'ya.", 'Nice work.']
151
151
  compliment.sample
152
152
  end
153
153
 
@@ -166,19 +166,19 @@ module Danger
166
166
  def generate_comment(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: {}, danger_id: 'danger')
167
167
  require 'erb'
168
168
 
169
- md_template = File.join(Danger.gem_path, "lib/danger/comment_generators/github.md.erb")
169
+ md_template = File.join(Danger.gem_path, 'lib/danger/comment_generators/github.md.erb')
170
170
 
171
171
  # erb: http://www.rrn.dk/rubys-erb-templating-system
172
172
  # for the extra args: http://stackoverflow.com/questions/4632879/erb-template-removing-the-trailing-line
173
173
  @tables = [
174
- table("Error", "no_entry_sign", errors, previous_violations),
175
- table("Warning", "warning", warnings, previous_violations),
176
- table("Message", "book", messages, previous_violations)
174
+ table('Error', 'no_entry_sign', errors, previous_violations),
175
+ table('Warning', 'warning', warnings, previous_violations),
176
+ table('Message', 'book', messages, previous_violations)
177
177
  ]
178
178
  @markdowns = markdowns
179
179
  @danger_id = danger_id
180
180
 
181
- return ERB.new(File.read(md_template), 0, "-").result(binding)
181
+ return ERB.new(File.read(md_template), 0, '-').result(binding)
182
182
  end
183
183
 
184
184
  def table(name, emoji, violations, all_previous_violations)
@@ -13,7 +13,7 @@ module Danger
13
13
  end
14
14
 
15
15
  def initialize(_ci_source, _environment)
16
- raise "Subclass and overwrite initialize"
16
+ raise 'Subclass and overwrite initialize'
17
17
  end
18
18
 
19
19
  def validates?
@@ -33,15 +33,15 @@ module Danger
33
33
  end
34
34
 
35
35
  def update_pull_request!(_warnings: [], _errors: [], _messages: [], _markdowns: [])
36
- raise "Subclass and overwrite update_pull_request!"
36
+ raise 'Subclass and overwrite update_pull_request!'
37
37
  end
38
38
 
39
39
  def setup_danger_branches
40
- raise "Subclass and overwrite setup_danger_branches"
40
+ raise 'Subclass and overwrite setup_danger_branches'
41
41
  end
42
42
 
43
43
  def fetch_details
44
- raise "Subclass and overwrite initialize"
44
+ raise 'Subclass and overwrite initialize'
45
45
  end
46
46
  end
47
47
  end
@@ -6,7 +6,7 @@ module Danger
6
6
  class GitRepo
7
7
  attr_accessor :diff, :log
8
8
 
9
- def diff_for_folder(folder, from: "master", to: 'HEAD')
9
+ def diff_for_folder(folder, from: 'master', to: 'HEAD')
10
10
  repo = Git.open folder
11
11
  self.diff = repo.diff(from, to)
12
12
  self.log = repo.log.between(from, to)
@@ -17,7 +17,7 @@ module Danger
17
17
  end
18
18
 
19
19
  def head_commit
20
- exec "rev-parse HEAD"
20
+ exec 'rev-parse HEAD'
21
21
  end
22
22
 
23
23
  def origins
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "0.8.4".freeze
3
- DESCRIPTION = "Automate your PR etiquette.".freeze
2
+ VERSION = '0.8.5'.freeze
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.8.4
4
+ version: 0.8.5
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-07-02 00:00:00.000000000 Z
12
+ date: 2016-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -352,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
352
352
  version: '0'
353
353
  requirements: []
354
354
  rubyforge_project:
355
- rubygems_version: 2.2.2
355
+ rubygems_version: 2.4.8
356
356
  signing_key:
357
357
  specification_version: 4
358
358
  summary: Automate your PR etiquette.