danger 2.1.1 → 2.1.2

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: 5e22a3c405d78751b1e8ddc02872e1ee3d19de32
4
- data.tar.gz: 24c42b47f0ec7965498a899bb48577c828c4cecb
3
+ metadata.gz: 8f0959f195af33185bbbdb41f1056e67a7c9babf
4
+ data.tar.gz: 61223153953f39a208c7c9edfa9103b1748d8124
5
5
  SHA512:
6
- metadata.gz: d5b263ba25eac823b04822bc74a8b7b1f0e721fe41559fd2195883ff76aef813f4f9be0753de117003c1461550fa5e6c788b54e2f483944a61ee7ee56f33d7c1
7
- data.tar.gz: 1591ad1a26e5f69bae95cdaa3cb288f5b82333c1f67cf1da2af4a104c6d798f1cbb8c6f5baf75a820ecf9700d62bed0c5a3d4de1b239f5d233c27f34f7d1569a
6
+ metadata.gz: abf51e8a4378186c34e869654f0216ff18501ebdc79d304c7a9c8b271c22219226d334fe9e466a4c1d41f476e32385f26c9764de5a6e23bf96b0de9d83ed8aba
7
+ data.tar.gz: 8a6bc14ef8e75a917d43a8b65f7366610d784775a54abb411f87ca1146b83b4599161ef96f7f503cdc4c3bfd9fcaa70ac9fe53d5b2003356a7ca47055c411a8e
@@ -28,8 +28,12 @@ module Danger
28
28
  end
29
29
 
30
30
  def self.validates_as_pr?(env)
31
+ # This will get used if it's available, instead of the API faffing.
31
32
  return true if env["CI_PULL_REQUEST"]
32
33
 
34
+ # Real-world talk, it should be worrying if none of these are in the environment
35
+ return false unless ["CIRCLE_CI_API_TOKEN", "CIRCLE_PROJECT_USERNAME", "CIRCLE_PROJECT_REPONAME", "CIRCLE_BUILD_NUM"].all? { |x| env[x] }
36
+
33
37
  # Uses the Circle API to determine if it's a PR otherwose
34
38
  @circle_token = env["CIRCLE_CI_API_TOKEN"]
35
39
  !pull_request_url(env).nil?
@@ -39,15 +43,6 @@ module Danger
39
43
  @supported_request_sources ||= [Danger::RequestSources::GitHub]
40
44
  end
41
45
 
42
- def client
43
- @client ||= CircleAPI.new(@circle_token)
44
- end
45
-
46
- def fetch_pull_request_url(repo_slug, build_number)
47
- build_json = client.fetch_build(repo_slug, build_number)
48
- build_json[:pull_request_urls].first
49
- end
50
-
51
46
  def pull_request_url(env)
52
47
  url = env["CI_PULL_REQUEST"]
53
48
 
@@ -59,17 +54,31 @@ module Danger
59
54
  url
60
55
  end
61
56
 
57
+ def client
58
+ @client ||= CircleAPI.new(@circle_token)
59
+ end
60
+
61
+ def fetch_pull_request_url(repo_slug, build_number)
62
+ build_json = client.fetch_build(repo_slug, build_number)
63
+ build_json[:pull_request_urls].first
64
+ end
65
+
62
66
  def initialize(env)
63
67
  self.repo_url = GitRepo.new.origins # CircleCI doesn't provide a repo url env variable :/
64
68
 
65
- @circle_token = env["CIRCLE_CI_API_TOKEN"]
66
- url = pull_request_url(env)
69
+ pr_url = env["CI_PULL_REQUEST"]
70
+
71
+ # If it's not a real URL, use the Circle API
72
+ unless pr_url && URI.parse(pr_url).kind_of?(URI::HTTP)
73
+ @circle_token = env["CIRCLE_CI_API_TOKEN"]
74
+ pr_url = pull_request_url(env)
75
+ end
67
76
 
68
- if URI.parse(url).path.split("/").count == 5
69
- paths = URI.parse(url).path.split("/")
77
+ pr_path = URI.parse(pr_url).path.split("/")
78
+ if pr_path.count == 5
70
79
  # The first one is an extra slash, ignore it
71
- self.repo_slug = paths[1] + "/" + paths[2]
72
- self.pull_request_id = paths[4]
80
+ self.repo_slug = pr_path[1] + "/" + pr_path[2]
81
+ self.pull_request_id = pr_path[4]
73
82
  end
74
83
  end
75
84
  end
@@ -90,6 +90,15 @@ module Danger
90
90
  ui.say "Here are great resources for creative commons images of robots:"
91
91
  ui.link "https://www.flickr.com/search/?text=robot&license=2%2C3%2C4%2C5%2C6%2C9"
92
92
  ui.link "https://www.google.com/search?q=robot&tbs=sur:fmc&tbm=isch&tbo=u&source=univ&sa=X&ved=0ahUKEwjgy8-f95jLAhWI7hoKHV_UD00QsAQIMQ&biw=1265&bih=1359"
93
+ ui.pause ""
94
+
95
+ if considered_an_oss_repo?
96
+ ui.say "#{@bot_name} does not need privilidged access to your repo or org. This is because Danger will only"
97
+ ui.say "be writing comments, and you do not need special access for that."
98
+ else
99
+ ui.say "#{@bot_name} will need access to your repo. Simply because the code is not available for the public"
100
+ ui.say "to read and comment on."
101
+ end
93
102
 
94
103
  ui.say ""
95
104
  note_about_clicking_links
@@ -113,7 +122,6 @@ module Danger
113
122
  ui.pause 1
114
123
  ui.say "This token limits Danger's abilities to just writing comments on OSS projects. I recommend"
115
124
  ui.say "this because the token can quite easily be extracted from the environment via pull requests."
116
- ui.say "#{@bot_name} does not need admin access to your repo. So its ability to cause chaos is minimalized.\n"
117
125
 
118
126
  ui.say "\nIt is important that you do not store this token in your repository, as GitHub will automatically revoke it when pushed.\n"
119
127
  elsif @is_open_source == "closed"
@@ -170,10 +178,10 @@ module Danger
170
178
  def uses_travis
171
179
  danger = "bundle exec danger".yellow
172
180
  config = YAML.load(File.read(".travis.yml"))
173
- if config["script"]
181
+ if config.kind_of?(Hash) && config["script"]
174
182
  ui.say "Add " + "- ".yellow + danger + " as a new step in the " + "script".yellow + " section of your .travis.yml file."
175
183
  else
176
- ui.say "I'd recommend adding " + "script: ".yellow + danger + " to the script section of your .travis.yml file."
184
+ ui.say "I'd recommend adding " + "before_script: ".yellow + danger + " to the script section of your .travis.yml file."
177
185
  end
178
186
 
179
187
  ui.pause 1
@@ -184,7 +192,7 @@ module Danger
184
192
  danger = "- bundle exec danger".yellow
185
193
  config = YAML.load(File.read("circle.yml"))
186
194
 
187
- if config["test"]
195
+ if config.kind_of?(Hash) && config["test"]
188
196
  if config["test"]["post"]
189
197
  ui.say "Add " + danger + " as a new step in the " + "test:post:".yellow + " section of your circle.yml file."
190
198
  else
@@ -241,6 +249,8 @@ module Danger
241
249
  def unsure_token
242
250
  ui.say "You need to expose a token called " + "DANGER_GITHUB_API_TOKEN".yellow + " and the value is the GitHub Personal Acess Token."
243
251
  ui.say "Depending on the CI system, this may need to be done on the machine ( in the " + "~/.bashprofile".yellow + ") or in a web UI somewhere."
252
+ ui.say "We have a guide for all supported CI systems on danger.systems:"
253
+ ui.link "http://danger.systems/guides/getting_started.html#setting-up-danger-to-run-on-your-ci"
244
254
  end
245
255
 
246
256
  def note_about_clicking_links
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "2.1.1".freeze
2
+ VERSION = "2.1.2".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: 2.1.1
4
+ version: 2.1.2
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-31 00:00:00.000000000 Z
12
+ date: 2016-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide