danger 3.0.3 → 3.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bdf784866d4e556b6e665ae22edc46048983f26
4
- data.tar.gz: d4e01b88a5b73d250a194cb98ada8f361c4b20ae
3
+ metadata.gz: 04e4dcb2c7122c516f919f4974a599726ff4990f
4
+ data.tar.gz: fc4acfef02e8aec3732fd5a29570697518a81271
5
5
  SHA512:
6
- metadata.gz: 463ee74a57de4fdf20387f988da779668a6adced5c8785ec2723e83cf3cbc88f990e4dea7767f8c4559286be4253718a1bab0fdb61003be0229b64b005e764f0
7
- data.tar.gz: 6c73599cbc71be47bd903336cb5a106b5d8932544188ef30b6d93853ddf0ec515f08fc867c4efeda734acad5b0dd363e0fd4e6fd92ef0dabebc14e1cf72972a4
6
+ metadata.gz: 8c09366fbb3cda48045db4b6436be7363c24e36cb9274c59cf6d29065199c5abd4f5ea8ab7d4d9cb42c2edccdbe1837713985a0aff0a214bc374d00f1e9d1bb9
7
+ data.tar.gz: a52f301b783e08d1f76cc60e9c20214fda799b7ea2d38ffb40bd7eab74016907b9466aff97842c1f13eabab1861210ee6d1deb0fad86ead3b05cd4ebfef5b5de
@@ -0,0 +1,39 @@
1
+ # http://devcenter.bitrise.io/docs/available-environment-variables
2
+
3
+ module Danger
4
+ # ### CI Setup
5
+ #
6
+ # Add a script step to your workflow:
7
+ # ``` yml
8
+ # - script@1.1.2:
9
+ # inputs:
10
+ # - content: |-
11
+ # bundle install
12
+ # bundle exec danger
13
+ # ```
14
+ # ### Token Setup
15
+ #
16
+ # Add the `DANGER_GITHUB_API_TOKEN` to your workflow's Secret Env Vars
17
+ #
18
+ class Bitrise < CI
19
+ def self.validates_as_ci?(env)
20
+ env.key? "BITRISE_IO"
21
+ end
22
+
23
+ def self.validates_as_pr?(env)
24
+ return !env["BITRISE_PULL_REQUEST"].to_s.empty?
25
+ end
26
+
27
+ def supported_request_sources
28
+ @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]
29
+ end
30
+
31
+ def initialize(env)
32
+ self.pull_request_id = env["BITRISE_PULL_REQUEST"]
33
+ self.repo_url = env["GIT_REPOSITORY_URL"]
34
+
35
+ repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
36
+ self.repo_slug = repo_matches[2] unless repo_matches.nil?
37
+ end
38
+ end
39
+ end
@@ -35,7 +35,7 @@ module Danger
35
35
  end
36
36
 
37
37
  def initialize(env)
38
- self.repo_url = env["BUILDKITE_PULL_REQUEST_REPO"]
38
+ self.repo_url = env["BUILDKITE_REPO"]
39
39
  self.pull_request_id = env["BUILDKITE_PULL_REQUEST"]
40
40
 
41
41
  repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
@@ -40,7 +40,7 @@ module Danger
40
40
 
41
41
  def self.validates_as_pr?(env)
42
42
  # This will get used if it's available, instead of the API faffing.
43
- return true unless env["CI_PULL_REQUEST"].empty?
43
+ return true if env["CI_PULL_REQUEST"] && !env["CI_PULL_REQUEST"].empty?
44
44
 
45
45
  # Real-world talk, it should be worrying if none of these are in the environment
46
46
  return false unless ["CIRCLE_CI_API_TOKEN", "CIRCLE_PROJECT_USERNAME", "CIRCLE_PROJECT_REPONAME", "CIRCLE_BUILD_NUM"].all? { |x| env[x] && !env[x].empty? }
@@ -8,7 +8,7 @@ module Danger
8
8
  # exist as of yet, however there is an
9
9
  # [MR](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5698) fixing this.
10
10
  # If that has been merged and you are using either gitlab.com or a release
11
- # with that change this CISource will wokr.
11
+ # with that change this CISource will work.
12
12
  #
13
13
  class GitLabCI < CI
14
14
  def self.validates_as_ci?(env)
@@ -52,7 +52,6 @@ module Danger
52
52
  raise "No recent pull requests found for this repo, danger requires at least one PR for the local mode."
53
53
  end
54
54
  end
55
-
56
55
  self.pull_request_id = pr_merge.match("#([0-9]+)")[1]
57
56
  sha = pr_merge.split(" ")[0]
58
57
  parents = run_git("rev-list --parents -n 1 #{sha}").strip.split(" ")
@@ -4,7 +4,8 @@ module Danger
4
4
  # ### CI Setup
5
5
  #
6
6
  # For Semaphor you will want to go to the settings page of the project. Inside "Build Settings"
7
- # you should add `bundle exec danger` to the Setup thread.
7
+ # you should add `bundle exec danger` to the Setup thread. Note that Semaphore only provides
8
+ # the build environment variables necessary for Danger on PRs across forks.
8
9
  #
9
10
  # ### Token Setup
10
11
  #
@@ -16,7 +17,7 @@ module Danger
16
17
  end
17
18
 
18
19
  def self.validates_as_pr?(env)
19
- ["SEMAPHORE_REPO_SLUG", "PULL_REQUEST_NUMBER"].all? { |x| env[x] }
20
+ ["SEMAPHORE_REPO_SLUG", "PULL_REQUEST_NUMBER"].all? { |x| env[x] && !env[x].empty? }
20
21
  end
21
22
 
22
23
  def supported_request_sources
@@ -13,11 +13,11 @@ module Danger
13
13
  #
14
14
  class Surf < CI
15
15
  def self.validates_as_ci?(env)
16
- return ["SURF_REPO", "SURF_NWO"].all? { |x| env[x] }
16
+ return ["SURF_REPO", "SURF_NWO"].all? { |x| env[x] && !env[x].empty? }
17
17
  end
18
18
 
19
- def self.validates_as_pr?(_)
20
- true
19
+ def self.validates_as_pr?(env)
20
+ validates_as_ci?(env)
21
21
  end
22
22
 
23
23
  def supported_request_sources
@@ -31,7 +31,7 @@ module Danger
31
31
  end
32
32
 
33
33
  def self.validates_as_pr?(env)
34
- exists = ["TRAVIS_PULL_REQUEST", "TRAVIS_REPO_SLUG"].all? { |x| env[x] }
34
+ exists = ["TRAVIS_PULL_REQUEST", "TRAVIS_REPO_SLUG"].all? { |x| env[x] && !env[x].empty? }
35
35
  exists && env["TRAVIS_PULL_REQUEST"].to_i > 0
36
36
  end
37
37
 
@@ -21,7 +21,8 @@ module Danger
21
21
  end
22
22
 
23
23
  def self.validates_as_pr?(env)
24
- env["XCS_BOT_NAME"].include? "BuildaBot"
24
+ value = env["XCS_BOT_NAME"]
25
+ !value.nil? && value.include?("BuildaBot")
25
26
  end
26
27
 
27
28
  def supported_request_sources
@@ -145,7 +145,7 @@ module Danger
145
145
  def current_repo_slug
146
146
  @git = GitRepo.new
147
147
  repo_matches = @git.origins.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
148
- repo_matches[2] || "[Your/Repo]"
148
+ (repo_matches[2] || "[Your/Repo]").strip
149
149
  end
150
150
 
151
151
  def setup_danger_ci
@@ -234,7 +234,7 @@ module Danger
234
234
  ui.say "I'll give you a minute to read it..."
235
235
  ui.wait_for_return
236
236
 
237
- ui.say "On Danger/Danger we turn on " + "Permissive building of fork pull requests".yellow + " this exposes the token to Danger"
237
+ ui.say "On danger/danger we turn on " + "Permissive building of fork pull requests".yellow + " this exposes the token to Danger"
238
238
  ui.say "You can find this setting at:"
239
239
  ui.link "https://circleci.com/gh/#{current_repo_slug}/edit#advanced-settings\n"
240
240
  ui.say "I'll hold..."
@@ -19,8 +19,6 @@ module Danger
19
19
 
20
20
  self.description = <<-DESC
21
21
  Converts a collection of file paths of Danger plugins into a JSON format.
22
- Note: Before 1.0, it will also parse the represented JSON to validate whether http://danger.systems would
23
- show the plugin on the website.
24
22
  DESC
25
23
 
26
24
  self.arguments = [
@@ -29,12 +27,20 @@ module Danger
29
27
 
30
28
  def run
31
29
  file_resolver = PluginFileResolver.new(@refs)
32
- paths = file_resolver.resolve_to_paths
30
+ data = file_resolver.resolve
33
31
 
34
- parser = PluginParser.new(paths)
32
+ parser = PluginParser.new(data[:paths])
35
33
  parser.parse
36
- json = parser.to_json_string
37
- cork.puts json
34
+ json = parser.to_json
35
+
36
+ # Append gem metadata into every plugin
37
+ data[:gems].each do |gem_data|
38
+ json.each do |plugin|
39
+ plugin[:gem_metadata] = gem_data if plugin[:gem] == gem_data[:gem]
40
+ end
41
+ end
42
+
43
+ cork.puts json.to_json
38
44
  end
39
45
  end
40
46
  end
@@ -37,9 +37,9 @@ module Danger
37
37
 
38
38
  def run
39
39
  file_resolver = PluginFileResolver.new(@refs)
40
- paths = file_resolver.resolve_to_paths
40
+ data = file_resolver.resolve
41
41
 
42
- parser = PluginParser.new(paths, verbose: true)
42
+ parser = PluginParser.new(data[:paths], verbose: true)
43
43
  parser.parse
44
44
  json = parser.to_json
45
45
 
@@ -31,9 +31,9 @@ module Danger
31
31
  attr_accessor :json, :markdown
32
32
  def run
33
33
  file_resolver = PluginFileResolver.new(@refs)
34
- paths = file_resolver.resolve_to_paths
34
+ data = file_resolver.resolve
35
35
 
36
- parser = PluginParser.new(paths)
36
+ parser = PluginParser.new(data[:paths])
37
37
  parser.parse
38
38
 
39
39
  self.json = JSON.parse(parser.to_json_string)
@@ -53,7 +53,7 @@ module Danger
53
53
  end
54
54
 
55
55
  def run
56
- Executor.new.run(base: @base,
56
+ Executor.new(ENV).run(base: @base,
57
57
  head: @head,
58
58
  dangerfile_path: @dangerfile_path,
59
59
  danger_id: @danger_id)
@@ -1,5 +1,9 @@
1
1
  module Danger
2
2
  class Executor
3
+ def initialize(system_env)
4
+ @system_env = system_env
5
+ end
6
+
3
7
  def run(env: nil,
4
8
  dm: nil,
5
9
  cork: nil,
@@ -12,18 +16,18 @@ module Danger
12
16
  verbose: false)
13
17
 
14
18
  # Could we find a CI source at all?
15
- unless EnvironmentManager.local_ci_source(ENV)
16
- abort("Could not find the type of CI for Danger to run on.".red) unless ci_klass
19
+ unless EnvironmentManager.local_ci_source(@system_env)
20
+ abort("Could not find the type of CI for Danger to run on.".red)
17
21
  end
18
22
 
19
23
  # Could we determine that the CI source is inside a PR?
20
- unless EnvironmentManager.pr?(ENV)
24
+ unless EnvironmentManager.pr?(@system_env)
21
25
  cork.puts "Not a Pull Request - skipping `danger` run".yellow
22
26
  return
23
27
  end
24
28
 
25
29
  # OK, then we can have some
26
- env ||= EnvironmentManager.new(ENV)
30
+ env ||= EnvironmentManager.new(@system_env)
27
31
  dm ||= Dangerfile.new(env, cork)
28
32
 
29
33
  dm.init_plugins
@@ -26,7 +26,7 @@ module Danger
26
26
  #
27
27
  # @example Only accept MRs to the develop branch
28
28
  #
29
- # fail "Please re-submit this MR to develop, we may have already fixed your issue." if gitlab.branch_for_base != "develop"
29
+ # fail "Please re-submit this MR to develop, we may have already fixed your issue." if gitlab.branch_for_merge != "develop"
30
30
  #
31
31
  # @example Note when MRs don't reference a milestone, which goes away when it does
32
32
  #
@@ -10,10 +10,11 @@ module Danger
10
10
  @refs = references
11
11
  end
12
12
 
13
- def resolve_to_paths
13
+ def resolve
14
14
  # When given existing paths, map to absolute & existing paths
15
15
  if !@refs.nil? and @refs.select { |ref| File.file? ref }.any?
16
- @refs.select { |ref| File.file? ref }.map { |path| File.expand_path(path) }
16
+ paths = @refs.select { |ref| File.file? ref }.map { |path| File.expand_path(path) }
17
+ { paths: paths, gems: [] }
17
18
 
18
19
  # When given a list of gems
19
20
  elsif @refs and @refs.kind_of? Array
@@ -36,12 +37,29 @@ module Danger
36
37
 
37
38
  # the paths are relative to our current Chdir
38
39
  relative_paths = gem_names.flat_map { |plugin| Dir.glob("vendor/gems/ruby/*/gems/#{plugin}*/lib/**/**/**/**.rb") }
39
- relative_paths.map { |path| File.join(dir, path) }
40
+ paths = relative_paths.map { |path| File.join(dir, path) }
41
+
42
+ spec_paths = gem_names.flat_map { |plugin| Dir.glob("vendor/gems/ruby/*/specifications/#{plugin}*.gemspec").first }
43
+ real_gems = spec_paths.map { |path| Gem::Specification.load path }
44
+
45
+ plugin_metadata = real_gems.map do |gem|
46
+ {
47
+ name: gem.name,
48
+ gem: gem.name,
49
+ author: gem.authors,
50
+ url: gem.homepage,
51
+ description: gem.summary,
52
+ license: gem.license || "Unknown",
53
+ version: gem.version.to_s
54
+ }
55
+ end
56
+ { paths: paths, gems: plugin_metadata }
40
57
  end
41
58
  end
42
59
  # When empty, imply you want to test the current lib folder as a plugin
43
60
  else
44
- Dir.glob(File.join(".", "lib/**/*.rb")).map { |path| File.expand_path(path) }
61
+ paths = Dir.glob(File.join(".", "lib/**/*.rb")).map { |path| File.expand_path(path) }
62
+ { paths: paths, gems: [] }
45
63
  end
46
64
  end
47
65
  end
@@ -64,6 +64,10 @@ module Danger
64
64
 
65
65
  def fetch_details
66
66
  self.pr_json = client.pull_request(ci_source.repo_slug, ci_source.pull_request_id)
67
+ if self.pr_json[:message] == "Moved Permanently"
68
+ raise "Repo moved or renamed, make sure to update the git remote".red
69
+ end
70
+
67
71
  fetch_issue_details(self.pr_json)
68
72
  self.ignored_violations = ignored_violations_from_pr(self.pr_json)
69
73
  end
@@ -23,7 +23,7 @@ module Danger
23
23
  end
24
24
 
25
25
  def origins
26
- exec("remote show origin -n").lines.grep(/Fetch URL/)[0].split(": ", 2)[1]
26
+ exec("remote show origin -n").lines.grep(/Fetch URL/)[0].split(": ", 2)[1].chomp
27
27
  end
28
28
  end
29
29
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "3.0.3".freeze
3
- DESCRIPTION = "Automate your PR etiquette.".freeze
2
+ VERSION = "3.1.0".freeze
3
+ DESCRIPTION = "Like Unit Tests, but for your Team Culture.".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: 3.0.3
4
+ version: 3.1.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-08-23 00:00:00.000000000 Z
12
+ date: 2016-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -362,6 +362,7 @@ files:
362
362
  - lib/assets/DangerfileTemplate
363
363
  - lib/assets/PluginTemplate.rb.template
364
364
  - lib/danger.rb
365
+ - lib/danger/ci_source/bitrise.rb
365
366
  - lib/danger/ci_source/buildkite.rb
366
367
  - lib/danger/ci_source/ci_source.rb
367
368
  - lib/danger/ci_source/circle.rb
@@ -430,9 +431,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
430
431
  version: '0'
431
432
  requirements: []
432
433
  rubyforge_project:
433
- rubygems_version: 2.4.8
434
+ rubygems_version: 2.2.2
434
435
  signing_key:
435
436
  specification_version: 4
436
- summary: Automate your PR etiquette.
437
+ summary: Like Unit Tests, but for your Team Culture.
437
438
  test_files: []
438
- has_rdoc: