danger 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14a93dd351e70737bc4c56de0db56d790c223c5b
4
- data.tar.gz: 2902696f31772f74976816570b4fa5051db637f6
3
+ metadata.gz: 8bf96232696dca35c69a7d338d10bf16af6917a2
4
+ data.tar.gz: e5e7f69f74d8419ce1c0f2c0df2725aa8b1874bf
5
5
  SHA512:
6
- metadata.gz: e0a87671ee98117c019ff2d374830112d4c94c356d66315ab69553e125546d98c54a209b9a7f0bb4cf03830bdb84ddbec3e763656ced085768731f1c00641d29
7
- data.tar.gz: 0b2fcf219ff87f2c959295f0f5884fc444820ae8831daa6452b622171331dafd049bfb08e7f749b66c4d937878eb1935d5c138311c2497f96f3374352237467b
6
+ metadata.gz: c69c8d1096130a36a0749c55a6f1e7e90d2df55ee0048bfdd13d13f83760071e66c7a65ad188b3c12a4d71613f75d982698e3e7776438bc1dc3ec227a94fd445
7
+ data.tar.gz: 16a07e94b369b7da16ab0bab5c4d9935c40442a3284c43985254811f92da77439d81dc8c19dbb6f4a9893f1ea89fcac6155736f9dd07f9b000b1457c1d2d31ad
data/README.md CHANGED
@@ -124,6 +124,14 @@ open to turning useful bits into the official API.
124
124
  Using `danger local` will look for the last merged pull request in your git history, and apply your current
125
125
  `Dangerfile` against that Pull Request. Useful when editing.
126
126
 
127
+ ## Suppress Violations
128
+
129
+ You can tell Danger to ignore a specific warning or error by commenting on the PR body:
130
+
131
+ ```
132
+ > Danger: Ignore "Developer Specific file shouldn't be changed"
133
+ ```
134
+
127
135
  ## Useful bits of knowledge
128
136
 
129
137
  * You can set the base branch in the command line arguments see: `bundle exec danger --help`, if you commonly merge into non-master branches.
@@ -25,14 +25,9 @@ module Danger
25
25
  # get the remote URL
26
26
  remote = run_git "remote show origin -n | grep \"Fetch URL\" | cut -d ':' -f 2-"
27
27
  if remote
28
- url = remote[0].strip
29
- # deal with https://
30
- if url.start_with? "https://github.com/"
31
- self.repo_slug = url.gsub("https://github.com/", "").gsub(".git", '')
32
-
33
- # deal with SSH origin
34
- elsif url.start_with? "git@github.com:"
35
- self.repo_slug = url.gsub("git@github.com:", "").gsub(".git", '')
28
+ remote_url_matches = remote.first.chomp.match(%r{github\.com(:|/)(?<repo_slug>.+/.+?)(?:\.git)?$})
29
+ if !remote_url_matches.nil? and remote_url_matches["repo_slug"]
30
+ self.repo_slug = remote_url_matches["repo_slug"]
36
31
  else
37
32
  puts "Danger local requires a repository hosted on github."
38
33
  end
@@ -14,7 +14,7 @@ module Danger
14
14
 
15
15
  def fetch_build(repo_slug, build_number)
16
16
  url = "project/#{repo_slug}/#{build_number}"
17
- params = { :'circle-token' => circle_token }
17
+ params = { 'circle-token' => circle_token }
18
18
  response = client.get url, params, accept: 'application/json'
19
19
  json = JSON.parse(response.body, symbolize_names: true)
20
20
  json
@@ -75,7 +75,7 @@ module Danger
75
75
  ui.say "that come up in day to day programming. It can be difficult to try and see those from day 1."
76
76
 
77
77
  ui.say "\nIf you'd like to investigate the file, and make some changes - I'll wait here,"
78
- ui.say "press return when you're ready to move on"
78
+ ui.say "press return when you're ready to move on..."
79
79
  ui.wait_for_return
80
80
  end
81
81
 
@@ -96,7 +96,7 @@ module Danger
96
96
  ui.say ""
97
97
  note_about_clicking_links
98
98
  ui.pause 1
99
- ui.say "\nCool, please press return when you have your account ready (and you've verified the email)"
99
+ ui.say "\nCool, please press return when you have your account ready (and you've verified the email...)"
100
100
  ui.wait_for_return
101
101
  end
102
102
 
@@ -111,7 +111,7 @@ module Danger
111
111
 
112
112
  if considered_an_oss_repo?
113
113
  ui.say "For Open Source projects, I'd recommend giving the token the smallest scope possible."
114
- ui.say "This means only providing access to " + "public_info".yellow + " in the token.\n\n"
114
+ ui.say "This means only providing access to " + "public_repo".yellow + " in the token.\n\n"
115
115
  ui.pause 1
116
116
  ui.say "This token limits Danger's abilities to just to writing comments on OSS projects. I recommend"
117
117
  ui.say "this because the token can quite easily be extracted from the environment via pull requests."
@@ -122,10 +122,10 @@ module Danger
122
122
  ui.say "This means only providing access to " + "repo".yellow + ", and its children in the token.\n\n"
123
123
  ui.pause 1
124
124
  ui.say "It's worth noting that you " + "should not".bold.white + " re-use this token for OSS repos."
125
- ui.say "Make a new one for those repos with just " + "public_info".yellow + "."
125
+ ui.say "Make a new one for those repos with just " + "public_repo".yellow + "."
126
126
  end
127
127
 
128
- ui.say "\n👍, please press return when you have your token set up"
128
+ ui.say "\n👍, please press return when you have your token set up..."
129
129
  ui.wait_for_return
130
130
  end
131
131
 
@@ -145,7 +145,7 @@ module Danger
145
145
  uses_circle if File.exist? "circle.yml"
146
146
  unsure_ci unless File.exist?(".travis.yml") || File.exist?(".circle.yml")
147
147
 
148
- ui.say "\nOK, I'll give you a moment to do this"
148
+ ui.say "\nOK, I'll give you a moment to do this..."
149
149
  ui.wait_for_return
150
150
 
151
151
  ui.say "Final step: exposing the GitHub token as an environment build variable."
@@ -161,7 +161,7 @@ module Danger
161
161
  unsure_token unless File.exist?(".travis.yml") || File.exist?(".circle.yml")
162
162
 
163
163
  ui.pause 0.6
164
- ui.say "This is the last step, I can give you a second"
164
+ ui.say "This is the last step, I can give you a second..."
165
165
  ui.wait_for_return
166
166
  end
167
167
 
@@ -179,7 +179,7 @@ module Danger
179
179
  end
180
180
 
181
181
  def uses_circle
182
- danger = "bundle exec danger".yellow
182
+ danger = "- bundle exec danger".yellow
183
183
  config = YAML.load(File.read("circle.yml"))
184
184
 
185
185
  if config["test"]
@@ -192,7 +192,7 @@ module Danger
192
192
  ui.say "Add this to the bottom of your circle.yml file:"
193
193
  ui.say "test:".green
194
194
  ui.say " post:".green
195
- ui.say " - bundle exec danger".green
195
+ ui.say " #{danger}".green
196
196
  end
197
197
  end
198
198
 
@@ -221,13 +221,13 @@ module Danger
221
221
  ui.say "the ramifications of turning on a setting I'm about to advise.\n"
222
222
  ui.link "https://circleci.com/docs/fork-pr-builds"
223
223
  ui.say "TLDR: If you have anything other than Danger config settings in CircleCI, then you should not turn on the setting."
224
- ui.say "I'll give you a minute to read it"
224
+ ui.say "I'll give you a minute to read it..."
225
225
  ui.wait_for_return
226
226
 
227
227
  ui.say "On Danger/Danger we turn on " + "Permissive building of fork pull requests".yellow + " this exposes the token to Danger"
228
228
  ui.say "You can find this setting at:"
229
229
  ui.link "https://circleci.com/gh/#{current_repo_slug}/edit#experimental\n"
230
- ui.say "I'll hold"
230
+ ui.say "I'll hold..."
231
231
  ui.wait_for_return
232
232
  end
233
233
 
@@ -249,7 +249,7 @@ module Danger
249
249
  ui.header "Useful info"
250
250
  ui.say "- One of the best ways to test out new rules locally is via " + "bundle exec danger local".yellow + "."
251
251
  ui.pause 0.6
252
- ui.say "- You can have Danger output all of its variables to the console via the " + "--verbose".yellow + "option."
252
+ ui.say "- You can have Danger output all of its variables to the console via the " + "--verbose".yellow + " option."
253
253
  ui.pause 0.6
254
254
  ui.say "- You can look at the following Dangerfiles to get some more ideas:"
255
255
  ui.pause 0.6
@@ -27,7 +27,7 @@ module Danger
27
27
  exit 0
28
28
  end
29
29
 
30
- puts "Running your Dangerfile against this PR - https://github.com/#{source.repo_slug}/pulls/#{source.pull_request_id}"
30
+ puts "Running your Dangerfile against this PR - https://github.com/#{source.repo_slug}/pull/#{source.pull_request_id}"
31
31
 
32
32
  if verbose != true
33
33
  puts "Turning on --verbose"
@@ -13,6 +13,17 @@ module Danger
13
13
  self.warnings = []
14
14
  self.errors = []
15
15
  self.messages = []
16
+ load_plugins
17
+ end
18
+
19
+ def load_plugins
20
+ Dir['./lib/danger/plugins/*.rb'].each do |file|
21
+ require file
22
+ end
23
+ end
24
+
25
+ def should_ignore_violation(message)
26
+ env.request_source.ignored_violations.include? message
16
27
  end
17
28
 
18
29
  # Declares a CI blocking error
@@ -20,6 +31,7 @@ module Danger
20
31
  # @param [String] message
21
32
  # The message to present to the user
22
33
  def fail(message)
34
+ return if should_ignore_violation(message)
23
35
  self.errors << message
24
36
  puts "Raising error '#{message}'"
25
37
  end
@@ -29,6 +41,7 @@ module Danger
29
41
  # @param [String] message
30
42
  # The message to present to the user
31
43
  def warn(message)
44
+ return if should_ignore_violation(message)
32
45
  self.warnings << message
33
46
  puts "Printing warning '#{message}'"
34
47
  end
@@ -46,10 +59,6 @@ module Danger
46
59
  # that either the `scm` or the `request_source` can handle.
47
60
  # This opens us up to letting those object extend themselves naturally.
48
61
  def method_missing(method_sym, *_arguments, &_block)
49
- unless AvailableValues.all.include?(method_sym)
50
- raise "Unknown method '#{method_sym}', please check out the documentation for available variables".red
51
- end
52
-
53
62
  if AvailableValues.scm.include?(method_sym)
54
63
  # SCM Source
55
64
  return env.scm.send(method_sym)
@@ -59,6 +68,8 @@ module Danger
59
68
  # Request Source
60
69
  return env.request_source.send(method_sym)
61
70
  end
71
+
72
+ raise "Unknown method '#{method_sym}', please check out the documentation for available variables".red
62
73
  end
63
74
  end
64
75
  end
@@ -0,0 +1,23 @@
1
+ module Danger
2
+ class Dangerfile
3
+ module DSL
4
+ # Protect a file from being changed. This can
5
+ # be used in combination with some kind of
6
+ # permission check if a user is inside the org
7
+ def protect_files(path: nil, message: nil, fail_build: true)
8
+ broken_rule = false
9
+ Dir.glob(path) do |current|
10
+ broken_rule = true if self.env.scm.files_modified.include?(current)
11
+ end
12
+
13
+ return unless broken_rule
14
+
15
+ if fail_build
16
+ self.errors << message
17
+ else
18
+ self.messages << message
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -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
7
+ attr_accessor :ci_source, :pr_json, :issue_json, :environment, :base_commit, :head_commit, :support_tokenless_auth, :ignored_violations
8
8
 
9
9
  def initialize(ci_source, environment)
10
10
  self.ci_source = ci_source
@@ -30,6 +30,13 @@ module Danger
30
30
  def fetch_details
31
31
  self.pr_json = client.pull_request(ci_source.repo_slug, ci_source.pull_request_id)
32
32
  fetch_issue_details(self.pr_json)
33
+ self.ignored_violations = ignored_violations_from_pr(self.pr_json)
34
+ end
35
+
36
+ def ignored_violations_from_pr(pr_json)
37
+ pr_body = pr_json[:body]
38
+ return [] if pr_body.nil?
39
+ pr_body.chomp.scan(/>\s*danger\s*:\s*ignore\s*"(.*)"/i).flatten
33
40
  end
34
41
 
35
42
  def fetch_issue_details(pr_json)
@@ -46,15 +53,15 @@ module Danger
46
53
  end
47
54
 
48
55
  def pr_title
49
- self.pr_json[:title]
56
+ self.pr_json[:title].to_s
50
57
  end
51
58
 
52
59
  def pr_body
53
- self.pr_json[:body]
60
+ self.pr_json[:body].to_s
54
61
  end
55
62
 
56
63
  def pr_author
57
- self.pr_json[:user][:login]
64
+ self.pr_json[:user][:login].to_s
58
65
  end
59
66
 
60
67
  def pr_labels
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  DESCRIPTION = "Automate your PR etiquette."
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.5.2
4
+ version: 0.6.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-02-29 00:00:00.000000000 Z
12
+ date: 2016-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -224,6 +224,7 @@ files:
224
224
  - lib/danger/dangerfile.rb
225
225
  - lib/danger/dangerfile_dsl.rb
226
226
  - lib/danger/environment_manager.rb
227
+ - lib/danger/plugins/protect_files.rb
227
228
  - lib/danger/request_sources/github.rb
228
229
  - lib/danger/scm_source/git_repo.rb
229
230
  - lib/danger/standard_error.rb