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
@@ -7,19 +7,19 @@ module Danger
7
7
  end
8
8
 
9
9
  def show_prompt
10
- ui.print "> ".bold.green
10
+ ui.print '> '.bold.green
11
11
  end
12
12
 
13
13
  def yellow_bang
14
- "! ".yellow
14
+ '! '.yellow
15
15
  end
16
16
 
17
17
  def green_bang
18
- "! ".green
18
+ '! '.green
19
19
  end
20
20
 
21
21
  def red_bang
22
- "! ".red
22
+ '! '.red
23
23
  end
24
24
 
25
25
  def say(output)
@@ -33,7 +33,7 @@ module Danger
33
33
  end
34
34
 
35
35
  def link(url)
36
- say " -> " + url.underline + "\n"
36
+ say ' -> ' + url.underline + "\n"
37
37
  end
38
38
 
39
39
  def pause(time)
@@ -48,12 +48,12 @@ module Danger
48
48
 
49
49
  def run_command(command, output_command = nil)
50
50
  output_command ||= command
51
- ui.puts " " + output_command.magenta
51
+ ui.puts ' ' + output_command.magenta
52
52
  system command
53
53
  end
54
54
 
55
55
  def ask(question)
56
- answer = ""
56
+ answer = ''
57
57
  loop do
58
58
  ui.puts "\n#{question}?"
59
59
 
@@ -73,26 +73,26 @@ module Danger
73
73
  print_info = proc do
74
74
  possible_answers.each_with_index do |answer, i|
75
75
  the_answer = (i == 0) ? answer.underline : answer
76
- ui.print " " + the_answer
77
- ui.print(" /") if i != possible_answers.length - 1
76
+ ui.print ' ' + the_answer
77
+ ui.print(' /') if i != possible_answers.length - 1
78
78
  end
79
79
  ui.print " ]\n"
80
80
  end
81
81
  print_info.call
82
82
 
83
- answer = ""
83
+ answer = ''
84
84
 
85
85
  loop do
86
86
  show_prompt
87
87
  answer = @no_waiting ? possible_answers[0].downcase : STDIN.gets.downcase.chomp
88
88
 
89
- answer = "yes" if answer == "y"
90
- answer = "no" if answer == "n"
89
+ answer = 'yes' if answer == 'y'
90
+ answer = 'no' if answer == 'n'
91
91
 
92
92
  # default to first answer
93
- if answer == ""
93
+ if answer == ''
94
94
  answer = possible_answers[0].downcase
95
- ui.puts "Using: " + answer.yellow
95
+ ui.puts 'Using: ' + answer.yellow
96
96
  end
97
97
 
98
98
  break if possible_answers.map(&:downcase).include? answer
@@ -4,7 +4,7 @@ module Danger
4
4
  self.command = 'local'
5
5
 
6
6
  def initialize(argv)
7
- @dangerfile_path = "Dangerfile" if File.exist? "Dangerfile"
7
+ @dangerfile_path = 'Dangerfile' if File.exist? 'Dangerfile'
8
8
  @pr_num = argv.option('use-merged-pr')
9
9
  super
10
10
  end
@@ -18,13 +18,13 @@ module Danger
18
18
  def validate!
19
19
  super
20
20
  unless @dangerfile_path
21
- help! "Could not find a Dangerfile."
21
+ help! 'Could not find a Dangerfile.'
22
22
  end
23
23
  end
24
24
 
25
25
  def run
26
- ENV["DANGER_USE_LOCAL_GIT"] = "YES"
27
- ENV["LOCAL_GIT_PR_ID"] = @pr_num if @pr_num
26
+ ENV['DANGER_USE_LOCAL_GIT'] = 'YES'
27
+ ENV['LOCAL_GIT_PR_ID'] = @pr_num if @pr_num
28
28
 
29
29
  env = EnvironmentManager.new(ENV)
30
30
  dm = Dangerfile.new(env, cork)
@@ -32,7 +32,7 @@ module Danger
32
32
 
33
33
  source = dm.env.ci_source
34
34
  if source.nil? or source.repo_slug.empty?
35
- cork.puts "danger local failed because it only works with GitHub projects at the moment. Sorry.".red
35
+ cork.puts 'danger local failed because it only works with GitHub projects at the moment. Sorry.'.red
36
36
  exit 0
37
37
  end
38
38
 
@@ -41,7 +41,7 @@ module Danger
41
41
  cork.puts "Running your Dangerfile against this PR - https://#{gh.host}/#{source.repo_slug}/pull/#{source.pull_request_id}"
42
42
 
43
43
  if verbose != true
44
- cork.puts "Turning on --verbose"
44
+ cork.puts 'Turning on --verbose'
45
45
  dm.verbose = true
46
46
  end
47
47
 
@@ -54,15 +54,16 @@ module Danger
54
54
  begin
55
55
  gh.fetch_details
56
56
  rescue Octokit::NotFound
57
- cork.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."
57
+ cork.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
58
  return
59
59
  end
60
60
 
61
61
  dm.env.request_source = gh
62
62
 
63
63
  begin
64
+ dm.env.fill_environment_vars
64
65
  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.env.scm.diff_for_folder('.', from: Danger::EnvironmentManager.danger_base_branch, to: Danger::EnvironmentManager.danger_head_branch)
66
67
  dm.parse(Pathname.new(@dangerfile_path))
67
68
  dm.print_results
68
69
  ensure
@@ -8,26 +8,26 @@ module Danger
8
8
 
9
9
  cork.puts "Must be lower case, and use a '_' between words. Do not use '.'".green
10
10
  cork.puts "examples: 'number_of_emojis', 'ensure_pr_title_contains_keyword'".green
11
- cork.puts "Name of your new plugin: "
11
+ cork.puts 'Name of your new plugin: '
12
12
  name = STDIN.gets.strip
13
13
 
14
14
  dir = Danger.gem_path
15
- content = File.read(File.join(dir, "lib", "assets", "PluginTemplate.rb.template"))
16
- content.gsub!("[[CLASS_NAME]]", name.danger_class)
15
+ content = File.read(File.join(dir, 'lib', 'assets', 'PluginTemplate.rb.template'))
16
+ content.gsub!('[[CLASS_NAME]]', name.danger_class)
17
17
 
18
- plugins_path = "danger_plugins"
18
+ plugins_path = 'danger_plugins'
19
19
  FileUtils.mkdir_p(plugins_path) unless File.directory?(plugins_path)
20
20
 
21
21
  output_path = File.join(plugins_path, "#{name}.rb")
22
22
  raise "File '#{output_path}' already exists!" if File.exist?(output_path)
23
23
  File.write(output_path, content)
24
24
 
25
- cork.puts ""
25
+ cork.puts ''
26
26
  cork.puts "Successfully created new plugin at path '#{output_path}'".green
27
- cork.puts "Add this to your `Dangerfile` to use it:"
28
- cork.puts ""
27
+ cork.puts 'Add this to your `Dangerfile` to use it:'
28
+ cork.puts ''
29
29
  cork.puts "#{name}(parameter1: 123, parameter2: \"Club Mate\")".blue
30
- cork.puts ""
30
+ cork.puts ''
31
31
  cork.puts "Enjoy ✨"
32
32
  end
33
33
  end
@@ -35,8 +35,8 @@ module Danger
35
35
  self.markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: true)
36
36
  self.json = JSON.parse(parser.to_json)
37
37
 
38
- template = File.join(Danger.gem_path, "lib/danger/plugin_support/templates/readme_table.html.erb")
39
- cork.puts ERB.new(File.read(template), 0, "-").result(binding)
38
+ template = File.join(Danger.gem_path, 'lib/danger/plugin_support/templates/readme_table.html.erb')
39
+ cork.puts ERB.new(File.read(template), 0, '-').result(binding)
40
40
  end
41
41
  end
42
42
  end
@@ -26,7 +26,7 @@ module Danger
26
26
  def validate!
27
27
  super
28
28
  if self.class == Runner && !@dangerfile_path
29
- help! "Could not find a Dangerfile."
29
+ help! 'Could not find a Dangerfile.'
30
30
  end
31
31
  end
32
32
 
@@ -55,7 +55,7 @@ module Danger
55
55
  # Offer the chance for a user to specify a branch through the command line
56
56
  ci_base = @base || EnvironmentManager.danger_base_branch
57
57
  ci_head = @head || EnvironmentManager.danger_head_branch
58
- dm.env.scm.diff_for_folder(".", from: ci_base, to: ci_head)
58
+ dm.env.scm.diff_for_folder('.', from: ci_base, to: ci_head)
59
59
 
60
60
  dm.parse Pathname.new(@dangerfile_path)
61
61
 
@@ -65,7 +65,7 @@ module Danger
65
65
  dm.env.clean_up
66
66
  end
67
67
  else
68
- cork.puts "Not a Pull Request - skipping `danger` run"
68
+ cork.puts 'Not a Pull Request - skipping `danger` run'
69
69
  end
70
70
  end
71
71
 
@@ -36,5 +36,5 @@
36
36
  <%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
37
37
  <%- end -%>
38
38
  <p align="right" data-meta="generated_by_<%= @danger_id %>">
39
- Generated by :no_entry_sign: <a href="https://github.com/danger/danger/">danger</a>
39
+ Generated by :no_entry_sign: <a href="http://danger.systems/">danger</a>
40
40
  </p>
@@ -11,7 +11,7 @@ class String
11
11
  self.gsub(/::/, '/').
12
12
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
13
13
  gsub(/([a-z\d])([A-Z])/, '\1_\2').
14
- tr("-", "_").
14
+ tr('-', '_').
15
15
  downcase
16
16
  end
17
17
  end
@@ -73,7 +73,7 @@ module Danger
73
73
  @env = env_manager
74
74
 
75
75
  # Triggers local plugins from the root of a project
76
- Dir["./danger_plugins/*.rb"].each do |file|
76
+ Dir['./danger_plugins/*.rb'].each do |file|
77
77
  require File.expand_path(file)
78
78
  end
79
79
 
@@ -115,10 +115,10 @@ module Danger
115
115
  methods.map do |method|
116
116
  case method
117
117
  when :api
118
- value = "Octokit::Client"
118
+ value = 'Octokit::Client'
119
119
 
120
120
  when :pr_json
121
- value = "[Skipped]"
121
+ value = '[Skipped]'
122
122
 
123
123
  when :pr_body
124
124
  value = plugin.send(method)
@@ -140,14 +140,14 @@ module Danger
140
140
  def print_known_info
141
141
  rows = []
142
142
  rows += method_values_for_plugin_hashes(core_dsl_attributes)
143
- rows << ["---", "---"]
143
+ rows << ['---', '---']
144
144
  rows += method_values_for_plugin_hashes(external_dsl_attributes)
145
- rows << ["---", "---"]
146
- rows << ["SCM", env.scm.class]
147
- rows << ["Source", env.ci_source.class]
148
- rows << ["Requests", env.request_source.class]
149
- rows << ["Base Commit", env.meta_info_for_base]
150
- rows << ["Head Commit", env.meta_info_for_head]
145
+ rows << ['---', '---']
146
+ rows << ['SCM', env.scm.class]
147
+ rows << ['Source', env.ci_source.class]
148
+ rows << ['Requests', env.request_source.class]
149
+ rows << ['Base Commit', env.meta_info_for_base]
150
+ rows << ['Head Commit', env.meta_info_for_head]
151
151
 
152
152
  params = {}
153
153
  params[:rows] = rows.each { |current| current[0] = current[0].yellow }
@@ -180,8 +180,8 @@ module Danger
180
180
  'you should turn off smart quotes in your editor of choice.'.red
181
181
  end
182
182
 
183
- if contents.include?("puts")
184
- ui.puts "You used `puts` in your Dangerfile. To print out text to GitHub use `message` instead"
183
+ if contents.include?('puts')
184
+ ui.puts 'You used `puts` in your Dangerfile. To print out text to GitHub use `message` instead'
185
185
  end
186
186
 
187
187
  self.defined_in_file = path
@@ -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
@@ -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)
@@ -43,23 +43,23 @@ module Danger
43
43
 
44
44
  # @!group Git Files
45
45
  # Paths for files that were added during the diff
46
- # @return [FileList] an [Array] subclass
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
53
53
  # Paths for files that were removed during the diff
54
- # @return [FileList] an [Array] subclass
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
61
61
  # Paths for files that changed during the diff
62
- # @return [FileList] an [Array] subclass
62
+ # @return [FileList<String>] an [Array] subclass
63
63
  #
64
64
  def modified_files
65
65
  Danger::FileList.new(@git.diff.stats[:files].keys)
@@ -67,7 +67,7 @@ module Danger
67
67
 
68
68
  # @!group Git Metadata
69
69
  # The overall lines of code added/removed in the diff
70
- # @return Int
70
+ # @return [Fixnum]
71
71
  #
72
72
  def lines_of_code
73
73
  @git.diff.lines
@@ -75,7 +75,7 @@ module Danger
75
75
 
76
76
  # @!group Git Metadata
77
77
  # The overall lines of code removed in the diff
78
- # @return Int
78
+ # @return [Fixnum]
79
79
  #
80
80
  def deletions
81
81
  @git.diff.deletions
@@ -83,7 +83,7 @@ module Danger
83
83
 
84
84
  # @!group Git Metadata
85
85
  # The overall lines of code added in the diff
86
- # @return Int
86
+ # @return [Fixnum]
87
87
  #
88
88
  def insertions
89
89
  @git.diff.insertions
@@ -34,12 +34,12 @@ 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
41
41
  # The title of the Pull Request.
42
- # @return String
42
+ # @return [String]
43
43
  #
44
44
  def pr_title
45
45
  @github.pr_json[:title].to_s
@@ -47,7 +47,7 @@ module Danger
47
47
 
48
48
  # @!group PR Metadata
49
49
  # The body text of the Pull Request.
50
- # @return String
50
+ # @return [String]
51
51
  #
52
52
  def pr_body
53
53
  pr_json[:body].to_s
@@ -55,7 +55,7 @@ module Danger
55
55
 
56
56
  # @!group PR Metadata
57
57
  # The username of the author of the Pull Request.
58
- # @return String
58
+ # @return [String]
59
59
  #
60
60
  def pr_author
61
61
  pr_json[:user][:login].to_s
@@ -71,7 +71,7 @@ module Danger
71
71
 
72
72
  # @!group PR Commit Metadata
73
73
  # The branch to which the PR is going to be merged into.
74
- # @return String
74
+ # @return [String]
75
75
  #
76
76
  def branch_for_base
77
77
  pr_json[:base][:ref]
@@ -79,7 +79,7 @@ module Danger
79
79
 
80
80
  # @!group PR Commit Metadata
81
81
  # The branch to which the PR is going to be merged from.
82
- # @return String
82
+ # @return [String]
83
83
  #
84
84
  def branch_for_head
85
85
  pr_json[:head][:ref]
@@ -95,7 +95,7 @@ module Danger
95
95
 
96
96
  # @!group PR Commit Metadata
97
97
  # The head commit to which the PR is requesting to be merged from.
98
- # @return String
98
+ # @return [String]
99
99
  #
100
100
  def head_commit
101
101
  pr_json[:head][:sha]
@@ -104,7 +104,7 @@ module Danger
104
104
  # @!group GitHub Misca
105
105
  # The hash that represents the PR's JSON. For an example of what this looks like
106
106
  # see the [Danger Fixture'd one](https://raw.githubusercontent.com/danger/danger/master/spec/fixtures/pr_response.json).
107
- # @return Hash
107
+ # @return [Hash]
108
108
  #
109
109
  def pr_json
110
110
  @github.pr_json
@@ -113,7 +113,7 @@ module Danger
113
113
  # @!group GitHub Misc
114
114
  # Provides access to the GitHub API client used inside Danger. Making
115
115
  # it easy to use the GitHub API inside a Dangerfile.
116
- # @return Octokit::Client
116
+ # @return [Octokit::Client]
117
117
  def api
118
118
  @github.client
119
119
  end