danger 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -1
  3. data/bin/danger +2 -2
  4. data/lib/danger.rb +13 -13
  5. data/lib/danger/ci_source/buildkite.rb +5 -5
  6. data/lib/danger/ci_source/ci_source.rb +3 -3
  7. data/lib/danger/ci_source/circle.rb +13 -13
  8. data/lib/danger/ci_source/circle_api.rb +4 -4
  9. data/lib/danger/ci_source/drone.rb +5 -5
  10. data/lib/danger/ci_source/jenkins.rb +4 -4
  11. data/lib/danger/ci_source/local_git_repo.rb +13 -13
  12. data/lib/danger/ci_source/semaphore.rb +5 -5
  13. data/lib/danger/ci_source/surf.rb +24 -0
  14. data/lib/danger/ci_source/teamcity.rb +4 -4
  15. data/lib/danger/ci_source/travis.rb +6 -6
  16. data/lib/danger/ci_source/xcode_server.rb +2 -2
  17. data/lib/danger/commands/init.rb +93 -82
  18. data/lib/danger/commands/init_helpers/interviewer.rb +15 -15
  19. data/lib/danger/commands/local.rb +13 -13
  20. data/lib/danger/commands/plugins/plugin_lint.rb +11 -8
  21. data/lib/danger/commands/plugins/plugin_readme.rb +15 -11
  22. data/lib/danger/commands/runner.rb +31 -20
  23. data/lib/danger/core_ext/string.rb +3 -3
  24. data/lib/danger/danger_core/dangerfile.rb +31 -31
  25. data/lib/danger/danger_core/dangerfile_dsl.rb +1 -1
  26. data/lib/danger/danger_core/environment_manager.rb +6 -6
  27. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +5 -5
  28. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +2 -2
  29. data/lib/danger/danger_core/plugins/dangerfile_import_plugin.rb +9 -9
  30. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +3 -3
  31. data/lib/danger/danger_core/standard_error.rb +6 -6
  32. data/lib/danger/plugin_support/plugin.rb +1 -1
  33. data/lib/danger/plugin_support/plugin_file_resolver.rb +6 -6
  34. data/lib/danger/plugin_support/plugin_parser.rb +75 -31
  35. data/lib/danger/request_source/request_source.rb +4 -4
  36. data/lib/danger/scm_source/git_repo.rb +3 -3
  37. data/lib/danger/version.rb +2 -2
  38. metadata +17 -4
  39. data/lib/danger/commands/plugins/plugin_abstract.rb +0 -11
  40. data/lib/danger/commands/plugins/plugin_new.rb +0 -34
@@ -20,7 +20,7 @@ module Danger
20
20
  end
21
21
 
22
22
  def load_default_plugins
23
- Dir['./danger_plugins/*.rb'].each do |file|
23
+ Dir["./danger_plugins/*.rb"].each do |file|
24
24
  require File.expand_path(file)
25
25
  end
26
26
  end
@@ -1,5 +1,5 @@
1
- require 'danger/ci_source/ci_source'
2
- require 'danger/request_source/request_source'
1
+ require "danger/ci_source/ci_source"
2
+ require "danger/request_source/request_source"
3
3
 
4
4
  module Danger
5
5
  class EnvironmentManager
@@ -18,7 +18,7 @@ module Danger
18
18
  end
19
19
  end
20
20
 
21
- raise 'Could not find a valid pull request within the known CI sources'.red unless self.ci_source
21
+ raise "Could not find a valid pull request within the known CI sources".red unless self.ci_source
22
22
 
23
23
  RequestSources::RequestSource.available_request_sources.each do |klass|
24
24
  next unless self.ci_source.supports?(klass)
@@ -28,7 +28,7 @@ module Danger
28
28
  self.request_source = request_source
29
29
  end
30
30
 
31
- raise 'Could not find a Request Source'.red unless self.request_source
31
+ raise "Could not find a Request Source".red unless self.request_source
32
32
 
33
33
  self.scm = self.request_source.scm
34
34
  end
@@ -62,11 +62,11 @@ module Danger
62
62
  end
63
63
 
64
64
  def self.danger_head_branch
65
- 'danger_head'
65
+ "danger_head"
66
66
  end
67
67
 
68
68
  def self.danger_base_branch
69
- 'danger_base'
69
+ "danger_base"
70
70
  end
71
71
  end
72
72
  end
@@ -1,5 +1,5 @@
1
- require 'danger/plugin_support/plugin'
2
- require 'danger/core_ext/file_list'
1
+ require "danger/plugin_support/plugin"
2
+ require "danger/core_ext/file_list"
3
3
 
4
4
  module Danger
5
5
  # Handles interacting with git inside a Dangerfile. Providing access to files that have changed, and useful statistics. Also provides
@@ -31,7 +31,7 @@ module Danger
31
31
 
32
32
  class DangerfileGitPlugin < Plugin
33
33
  def self.instance_name
34
- 'git'
34
+ "git"
35
35
  end
36
36
 
37
37
  def initialize(dangerfile)
@@ -46,7 +46,7 @@ module Danger
46
46
  # @return [FileList<String>] an [Array] subclass
47
47
  #
48
48
  def added_files
49
- Danger::FileList.new(@git.diff.select { |diff| diff.type == 'new' }.map(&:path))
49
+ Danger::FileList.new(@git.diff.select { |diff| diff.type == "new" }.map(&:path))
50
50
  end
51
51
 
52
52
  # @!group Git Files
@@ -54,7 +54,7 @@ module Danger
54
54
  # @return [FileList<String>] an [Array] subclass
55
55
  #
56
56
  def deleted_files
57
- Danger::FileList.new(@git.diff.select { |diff| diff.type == 'deleted' }.map(&:path))
57
+ Danger::FileList.new(@git.diff.select { |diff| diff.type == "deleted" }.map(&:path))
58
58
  end
59
59
 
60
60
  # @!group Git Files
@@ -1,4 +1,4 @@
1
- require 'danger/plugin_support/plugin'
1
+ require "danger/plugin_support/plugin"
2
2
 
3
3
  module Danger
4
4
  # Handles interacting with GitHub inside a Dangerfile. Provides a few functions which wrap `pr_json` and also
@@ -34,7 +34,7 @@ module Danger
34
34
  end
35
35
 
36
36
  def self.instance_name
37
- 'github'
37
+ "github"
38
38
  end
39
39
 
40
40
  # @!group PR Metadata
@@ -1,4 +1,4 @@
1
- require 'danger/plugin_support/plugin'
1
+ require "danger/plugin_support/plugin"
2
2
 
3
3
  module Danger
4
4
  # One way to support internal plugins is via `plugin.import` this gives you
@@ -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
@@ -37,10 +37,10 @@ module Danger
37
37
  # @return [void]
38
38
 
39
39
  def import(path)
40
- raise '`import` requires a string' unless path.kind_of?(String)
41
- 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")
42
42
 
43
- if path.start_with?('http')
43
+ if path.start_with?("http")
44
44
  import_url(path)
45
45
  else
46
46
  import_local(path)
@@ -56,10 +56,10 @@ module Danger
56
56
  # https URL to the Ruby file to use
57
57
  # @return [void]
58
58
  def import_url(url)
59
- 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://")
60
60
 
61
- require 'tmpdir'
62
- require 'faraday'
61
+ require "tmpdir"
62
+ require "faraday"
63
63
 
64
64
  @http_client ||= Faraday.new do |b|
65
65
  b.adapter :net_http
@@ -67,7 +67,7 @@ module Danger
67
67
  content = @http_client.get(url)
68
68
 
69
69
  Dir.mktmpdir do |dir|
70
- path = File.join(dir, 'temporary_remote_action.rb')
70
+ path = File.join(dir, "temporary_remote_action.rb")
71
71
  File.write(path, content.body)
72
72
  import_local(path)
73
73
  end
@@ -1,5 +1,5 @@
1
- require 'danger/danger_core/violation'
2
- require 'danger/plugin_support/plugin'
1
+ require "danger/danger_core/violation"
2
+ require "danger/plugin_support/plugin"
3
3
 
4
4
  module Danger
5
5
  # Provides the feedback mechanism for Danger. Danger can keep track of
@@ -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
@@ -1,5 +1,5 @@
1
- require 'claide'
2
- require 'claide/informative_error'
1
+ require "claide"
2
+ require "claide/informative_error"
3
3
 
4
4
  module Danger
5
5
  # From below here - this entire file was taken verbatim for CocoaPods-Core.
@@ -73,12 +73,12 @@ module Danger
73
73
 
74
74
  trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) } || trace_line
75
75
  return m unless trace_line
76
- line_numer = trace_line.split(':')[1].to_i - 1
76
+ line_numer = trace_line.split(":")[1].to_i - 1
77
77
  return m unless line_numer
78
78
 
79
79
  lines = contents.lines
80
- indent = ' # '
81
- indicator = indent.tr('#', '>')
80
+ indent = " # "
81
+ indicator = indent.tr("#", ">")
82
82
  first_line = line_numer.zero?
83
83
  last_line = (line_numer == (lines.count - 1))
84
84
 
@@ -99,7 +99,7 @@ module Danger
99
99
  description = self.description
100
100
  if dsl_path && description =~ /((#{Regexp.quote File.expand_path(dsl_path)}|#{Regexp.quote dsl_path.to_s}):\d+)/
101
101
  trace_line = Regexp.last_match[1]
102
- description = description.sub(/#{Regexp.quote trace_line}:\s*/, '')
102
+ description = description.sub(/#{Regexp.quote trace_line}:\s*/, "")
103
103
  end
104
104
  [trace_line, description]
105
105
  end
@@ -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
@@ -1,5 +1,5 @@
1
- require 'bundler'
2
- require 'pathname'
1
+ require "bundler"
2
+ require "pathname"
3
3
 
4
4
  module Danger
5
5
  class PluginFileResolver
@@ -19,11 +19,11 @@ module Danger
19
19
  Bundler.with_clean_env do
20
20
  Dir.mktmpdir do |dir|
21
21
  gem_names = @refs
22
- deps = gem_names.map { |name| Bundler::Dependency.new(name, '>= 0') }
22
+ deps = gem_names.map { |name| Bundler::Dependency.new(name, ">= 0") }
23
23
 
24
24
  # Use Gems from rubygems.org
25
25
  source = Bundler::SourceList.new
26
- source.add_rubygems_remote('https://rubygems.org')
26
+ source.add_rubygems_remote("https://rubygems.org")
27
27
 
28
28
  # Create a definition to bundle, make sure it always updates
29
29
  # and uses the latest version from the server
@@ -36,12 +36,12 @@ module Danger
36
36
 
37
37
  # Get the name'd gems out of bundler, then pull out all their paths
38
38
  gems = gem_names.flat_map { |name| bundler.specs[name] }
39
- gems.flat_map { |gem| Dir.glob(File.join(gem.gem_dir, 'lib/**/**/**.rb')) }
39
+ gems.flat_map { |gem| Dir.glob(File.join(gem.gem_dir, "lib/**/**/**.rb")) }
40
40
  end
41
41
  end
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')).map { |path| File.expand_path(path) }
44
+ Dir.glob(File.join(".", "lib/*.rb")).map { |path| File.expand_path(path) }
45
45
  end
46
46
  end
47
47
  end
@@ -1,8 +1,8 @@
1
1
  require 'json'
2
2
 
3
- =begin
3
+ =begin
4
4
 
5
- So you want to improve this? Great. Hard thing is getting yourself into a position where you
5
+ So you want to improve this? Great. Hard thing is getting yourself into a position where you
6
6
  have access to all the tokens, so here's something you should run in `bundle exec pry` to dig in:
7
7
 
8
8
  require 'danger'
@@ -15,13 +15,12 @@ require 'json'
15
15
  parser.to_dict(plugins)
16
16
 
17
17
  Then some helpers
18
-
18
+
19
19
  attribute_meths = klass.attributes[:instance].values.map(&:values).flatten
20
20
 
21
21
  methods = klass.meths - klass.inherited_meths - attribute_meths
22
22
  usable_methods = methods.select { |m| m.visibility == :public }.reject { |m| m.name == :initialize }
23
23
 
24
-
25
24
  the alternative, is to add
26
25
 
27
26
  require 'pry'
@@ -31,7 +30,6 @@ require 'json'
31
30
 
32
31
  =end
33
32
 
34
-
35
33
  module Danger
36
34
  class PluginParser
37
35
  attr_accessor :registry
@@ -39,7 +37,7 @@ module Danger
39
37
  def initialize(paths)
40
38
  raise "Path cannot be empty" if paths.empty?
41
39
 
42
- if paths.is_a? String
40
+ if paths.kind_of? String
43
41
  @paths = [File.expand_path(paths)]
44
42
  else
45
43
  @paths = paths
@@ -56,7 +54,7 @@ module Danger
56
54
 
57
55
  # This turns on YARD debugging
58
56
  # $DEBUG = true
59
-
57
+
60
58
  self.registry = YARD::Registry.load(files, true)
61
59
  end
62
60
 
@@ -73,29 +71,76 @@ module Danger
73
71
  to_dict(plugins).to_json
74
72
  end
75
73
 
76
- def to_dict(classes)
77
- d_meth = lambda do |meth|
78
- return nil if meth.nil?
79
- {
80
- name: meth.name,
81
- body_md: meth.docstring,
82
- params: meth.parameters,
83
- tags: meth.tags.map do |t|
84
- {
85
- name: t.tag_name,
86
- types: t.types
87
- }
88
- end
89
- }
74
+ # rubocop:disable Metrics/AbcSize
75
+
76
+ def method_return_string(meth)
77
+ return "" unless meth[:tags]
78
+
79
+ return_value = meth[:tags].find { |t| t[:name] == "return" && t[:types] }
80
+ return "" if return_value.nil?
81
+ return "" if return_value[:types].nil?
82
+ return "" unless return_value[:types].kind_of? Array
83
+
84
+ unless return_value.empty?
85
+ return "" if return_value[:types].first == "void"
86
+ return return_value[:types].first
90
87
  end
88
+ ""
89
+ end
91
90
 
92
- d_attr = lambda do |attribute|
93
- {
94
- read: d_meth.call(attribute[:read]),
95
- write: d_meth.call(attribute[:write])
96
- }
91
+ def method_params(params)
92
+ return {} unless params[:params]
93
+
94
+ params_names = params[:params].compact.flat_map(&:first)
95
+ params_values = params[:tags].find { |t| t[:name] == "param" }
96
+
97
+ return {} if params_values.nil?
98
+ return {} if params_values[:types].nil?
99
+
100
+ return params_names.map.with_index do |name, index|
101
+ { name => params_values[:types][index] }
97
102
  end
103
+ end
98
104
 
105
+ def method_parser(meth)
106
+ return nil if meth.nil?
107
+ method = {
108
+ name: meth.name,
109
+ body_md: meth.docstring,
110
+ params: meth.parameters,
111
+ tags: meth.tags.map { |t| { name: t.tag_name, types: t.types } }
112
+ }
113
+
114
+ return_v = method_return_string(method)
115
+ params_v = method_params(method)
116
+
117
+ # Pull out some derived data
118
+ method[:param_couplets] = params_v
119
+ method[:return] = return_v
120
+
121
+ # Create the center params, `thing: OK, other: Thing`
122
+ string_params = params_v.map do |param|
123
+ name = param.keys.first
124
+ param[name].nil? ? name : name + ": " + param[name]
125
+ end.join ", "
126
+
127
+ # Wrap it in () if there _are_ params
128
+ string_params = "(" + string_params + ")" unless string_params.empty?
129
+ # Append the return type if we have one
130
+ suffix = return_v.empty? ? "" : " -> #{return_v}"
131
+
132
+ method[:one_liner] = meth.name.to_s + string_params + suffix
133
+ method
134
+ end
135
+
136
+ def attribute_parser(attribute)
137
+ {
138
+ read: method_parser(attribute[:read]),
139
+ write: method_parser(attribute[:write])
140
+ }
141
+ end
142
+
143
+ def to_dict(classes)
99
144
  classes.map do |klass|
100
145
  # Adds the class being parsed into the ruby runtime, so that we can access it's instance_name
101
146
  require klass.file
@@ -109,16 +154,15 @@ module Danger
109
154
  name: klass.name.to_s,
110
155
  body_md: klass.docstring,
111
156
  instance_name: real_klass.instance_name,
112
- example_code: klass.tags.select { |t| t.tag_name == "example" }.map { |tag| {:title => tag.name, :text => tag.text} }.compact,
113
- attributes: klass.attributes[:instance].map do |pair|
114
- { pair.first => d_attr.call(pair.last) }
115
- end,
116
- methods: usable_methods.map { |m| d_meth.call(m) },
157
+ example_code: klass.tags.select { |t| t.tag_name == "example" }.map { |tag| { title: tag.name, text: tag.text } }.compact,
158
+ attributes: klass.attributes[:instance].map { |pair| { pair.first => attribute_parser(pair.last) } },
159
+ methods: usable_methods.map { |m| method_parser(m) },
117
160
  tags: klass.tags.select { |t| t.tag_name == "tags" }.map(&:text).compact,
118
161
  see: klass.tags.select { |t| t.tag_name == "see" }.map(&:name).map(&:split).flatten.compact,
119
162
  file: klass.file.gsub(File.expand_path("."), "")
120
163
  }
121
164
  end
122
165
  end
166
+ # rubocop:enable Metrics/AbcSize
123
167
  end
124
168
  end
@@ -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
@@ -1,12 +1,12 @@
1
1
  # For more info see: https://github.com/schacon/ruby-git
2
2
 
3
- require 'git'
3
+ require "git"
4
4
 
5
5
  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