danger 6.1.0 → 6.2.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
  SHA256:
3
- metadata.gz: 3c67b44470cd2e591a3308ff21397f02ca56c39df0777856bdb124336b8f34d8
4
- data.tar.gz: cb10a0fbe36d92be5346930a12dda0d20f33d093968a8bc60e821894752fe4e2
3
+ metadata.gz: 12728d6688a88a9852c1db80a4538bd610511388749fb76b2f774ea31a9f0517
4
+ data.tar.gz: bc6f5250eb2851de5537c9f9ac0755259a6e249c393617125f09665334ab3587
5
5
  SHA512:
6
- metadata.gz: 636bd57417f223be9410e682d687eb109a93de82c2836884cc30d378261545f8c3ab1da15c278a893ffd2fcbf024bfadb4ad13f57d15c07bfd9386ac6ede8d59
7
- data.tar.gz: 95bd7f1b50c46cb8d62033e72d75c7aab04161590d244ab539c6e96879961f337f165ac9c061514c0c7596812c0d12578d06cb870aac123afc930114cb7e9b38
6
+ metadata.gz: 694c5bae91efcbbc823cf42708533bed4d298ae31af50b4d3dadb3edf50e4acb6aca907eade1e4913fdee370366ad3c1ac3d90e13f2bbb4bcba09a4fb8d14efd
7
+ data.tar.gz: 4c62ee57532ea5ef825fc4b7c6798c7bc2496250d3b7d928e60cf392d1dd95ce4fc936a4b07ca28d337cc618450b3a3f612a37b46531aa1a4feca721e0bddc48
@@ -36,7 +36,7 @@ module Danger
36
36
  end
37
37
 
38
38
  def initialize(env)
39
- self.pull_request_id = env["SYSTEM_PULLREQUEST_PULLREQUESTID"]
39
+ self.pull_request_id = env["SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"] || env["SYSTEM_PULLREQUEST_PULLREQUESTID"]
40
40
  self.repo_url = env["BUILD_REPOSITORY_URI"]
41
41
  self.repo_slug = env["BUILD_REPOSITORY_NAME"]
42
42
  end
@@ -0,0 +1,41 @@
1
+ require "set"
2
+
3
+ module Danger
4
+ # ### CI Setup
5
+ #
6
+ # Add a Run Script task that executes `danger` (or `bundle exec danger` if you're using Bundler
7
+ # to manage your gems) as your as part of your Bamboo plan.
8
+ # The minimum supported version is Bamboo 6.9.
9
+ #
10
+ # ### Token Setup
11
+ #
12
+ # IMPORTANT: All required Bamboo environment variables will be available
13
+ # only if the plan is run as part of a pull request. This can be achieved by selecting:
14
+ # Configure plan -> Branches -> Create plan branch: "When pull request is created".
15
+ # Otherwise, `bamboo_repository_pr_key` and `bamboo_planRepository_repositoryUrl`
16
+ # will not be available.
17
+ #
18
+ class Bamboo < CI
19
+ def supported_request_sources
20
+ @supported_request_sources ||= [
21
+ Danger::RequestSources::BitbucketServer
22
+ ]
23
+ end
24
+
25
+ def self.validates_as_ci?(env)
26
+ env.key? "bamboo_buildKey"
27
+ end
28
+
29
+ def self.validates_as_pr?(env)
30
+ exists = ["bamboo_repository_pr_key", "bamboo_planRepository_repositoryUrl"].all? { |x| env[x] && !env[x].empty? }
31
+ exists && env["bamboo_repository_pr_key"].to_i > 0
32
+ end
33
+
34
+ def initialize(env)
35
+ self.repo_url = env["bamboo_planRepository_repositoryUrl"]
36
+ self.pull_request_id = env["bamboo_repository_pr_key"]
37
+ repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+?)(\.git$|$)})
38
+ self.repo_slug = repo_matches[2] unless repo_matches.nil?
39
+ end
40
+ end
41
+ end
@@ -19,6 +19,14 @@ module Danger
19
19
  #
20
20
  # Add the `DANGER_GITHUB_API_TOKEN` to your workflow's [Secret App Env Vars](https://blog.bitrise.io/anyone-even-prs-can-have-secrets).
21
21
  #
22
+ # ### bitbucket server and bitrsie
23
+ #
24
+ # Danger will read the environemnt variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
25
+ # finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
26
+ # comes from the App Settings tab for your Bitrsie App. If you are manually setting a repo URL in the
27
+ # Git Clone Repo step, you may need to set adjust this propery in the settings tab, maybe even fake it.
28
+ # The pattern used is `(%r{([\/:])(([^\/]+\/){1,2}[^\/]+?)(\.git$|$)}`.
29
+ #
22
30
  class Bitrise < CI
23
31
  def self.validates_as_ci?(env)
24
32
  env.key? "BITRISE_IO"
@@ -16,8 +16,7 @@ module Danger
16
16
  end
17
17
 
18
18
  def self.validates_as_pr?(env)
19
- return false unless url = self.extract_pr_url(env)
20
- url
19
+ !!self.extract_pr_url(env)
21
20
  end
22
21
 
23
22
  def supported_request_sources
@@ -26,32 +25,33 @@ module Danger
26
25
 
27
26
  def initialize(env)
28
27
  self.repo_slug = self.class.extract_repo_slug(env)
29
- self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1]
28
+ self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
30
29
  self.repo_url = self.class.extract_repo_url(env)
31
30
  end
32
31
 
33
- private
34
- def self.extract_repo_slug(env)
35
- return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
32
+ def self.extract_repo_slug(env)
33
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
36
34
 
37
- env["CODEBUILD_SOURCE_REPO_URL"].gsub(/^.*?github\.com\/(.*?)\.git$/, '\1')
38
- end
35
+ gh_host = env["DANGER_GITHUB_HOST"] || "github.com"
39
36
 
40
- def self.extract_repo_url(env)
41
- return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
37
+ env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}\/(.*?)(\.git)?$}, '\1')
38
+ end
39
+
40
+ def self.extract_repo_url(env)
41
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
42
42
 
43
- env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
44
- end
43
+ env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
44
+ end
45
45
 
46
- def self.extract_pr_url(env)
47
- return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
48
- return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
49
- return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
46
+ def self.extract_pr_url(env)
47
+ return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
48
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
49
+ return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
50
50
 
51
- source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
52
- github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
51
+ _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
52
+ github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
53
53
 
54
- "#{github_repo_url}/pull/#{pr_number}"
55
- end
54
+ "#{github_repo_url}/pull/#{pr_number}"
55
+ end
56
56
  end
57
57
  end
@@ -1,4 +1,4 @@
1
- # https://semaphoreci.com/docs/available-environment-variables.html
1
+ # https://docs.semaphoreci.com/article/12-environment-variables
2
2
  require "danger/request_sources/github/github"
3
3
 
4
4
  module Danger
@@ -18,7 +18,10 @@ module Danger
18
18
  end
19
19
 
20
20
  def self.validates_as_pr?(env)
21
- ["SEMAPHORE_REPO_SLUG", "PULL_REQUEST_NUMBER"].all? { |x| env[x] && !env[x].empty? }
21
+ one = ["SEMAPHORE_REPO_SLUG", "PULL_REQUEST_NUMBER"].all? { |x| env[x] && !env[x].empty? }
22
+ two = ["SEMAPHORE_GIT_REPO_SLUG", "SEMAPHORE_GIT_PR_NUMBER"].all? { |x| env[x] && !env[x].empty? }
23
+
24
+ one || two
22
25
  end
23
26
 
24
27
  def supported_request_sources
@@ -26,9 +29,9 @@ module Danger
26
29
  end
27
30
 
28
31
  def initialize(env)
29
- self.repo_slug = env["SEMAPHORE_REPO_SLUG"]
30
- self.pull_request_id = env["PULL_REQUEST_NUMBER"]
31
- self.repo_url = GitRepo.new.origins # Semaphore doesn't provide a repo url env variable :/
32
+ self.repo_slug = env["SEMAPHORE_GIT_REPO_SLUG"] || env["SEMAPHORE_REPO_SLUG"]
33
+ self.pull_request_id = env["SEMAPHORE_GIT_PR_NUMBER"] || env["PULL_REQUEST_NUMBER"]
34
+ self.repo_url = env["SEMAPHORE_GIT_URL"] || GitRepo.new.origins
32
35
  end
33
36
  end
34
37
  end
@@ -257,7 +257,7 @@ module Danger
257
257
 
258
258
  def setup_for_running(base_branch, head_branch)
259
259
  env.ensure_danger_branches_are_setup
260
- env.scm.diff_for_folder(".".freeze, from: base_branch, to: head_branch)
260
+ env.scm.diff_for_folder(".".freeze, from: base_branch, to: head_branch, lookup_top_level: true)
261
261
  end
262
262
 
263
263
  def run(base_branch, head_branch, dangerfile_path, danger_id, new_comment, remove_previous_comments)
@@ -192,6 +192,17 @@ module Danger
192
192
  @gitlab.client
193
193
  end
194
194
 
195
+ # @!group GitLab Misc
196
+ # Returns the web_url of the source project.
197
+ # @return [String]
198
+ #
199
+ def repository_web_url
200
+ @repository_web_url ||= begin
201
+ project = api.project(mr_json["source_project_id"])
202
+ project.web_url
203
+ end
204
+ end
205
+
195
206
  # @!group GitLab Misc
196
207
  # Returns a list of HTML anchors for a file, or files in the head repository. An example would be:
197
208
  # `<a href='https://gitlab.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/file.txt'>file.txt</a>`. It returns a string of multiple anchors if passed an array.
@@ -209,7 +220,7 @@ module Danger
209
220
  paths = paths.map do |path|
210
221
  url_path = path.start_with?("/") ? path : "/#{path}"
211
222
  text = full_path ? path : File.basename(path)
212
- create_link("#{env.ci_source.project_url}/blob/#{commit}#{url_path}", text)
223
+ create_link("#{repository_web_url}/blob/#{commit}#{url_path}", text)
213
224
  end
214
225
 
215
226
  return paths.first if paths.count < 2
@@ -9,7 +9,7 @@ module Danger
9
9
  # @example Check that added lines contains agreed form of words
10
10
  #
11
11
  # git.diff.each do |chunk|
12
- # chunk.patch.lines.grep(/^+/).each do |added_line|
12
+ # chunk.patch.lines.grep(/^\+/).each do |added_line|
13
13
  # if added_line.gsub!(/(?<cancel>cancel)(?<rest>[^l[[:space:]][[:punct:]]]+)/i, '>>\k<cancel>-l-\k<rest><<')
14
14
  # fail "Single 'L' for cancellation-alike words in '#{added_line}'"
15
15
  # end
@@ -6,9 +6,15 @@ module Danger
6
6
  class GitRepo
7
7
  attr_accessor :diff, :log, :folder
8
8
 
9
- def diff_for_folder(folder, from: "master", to: "HEAD")
9
+ def diff_for_folder(folder, from: "master", to: "HEAD", lookup_top_level: false)
10
10
  self.folder = folder
11
- repo = Git.open self.folder
11
+ git_top_level = folder
12
+ if lookup_top_level
13
+ Dir.chdir(folder) do
14
+ git_top_level = exec("rev-parse --show-toplevel")
15
+ end
16
+ end
17
+ repo = Git.open git_top_level
12
18
 
13
19
  ensure_commitish_exists!(from)
14
20
  ensure_commitish_exists!(to)
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "6.1.0".freeze
2
+ VERSION = "6.2.0".freeze
3
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: 6.1.0
4
+ version: 6.2.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: 2019-09-30 00:00:00.000000000 Z
12
+ date: 2020-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -196,6 +196,7 @@ files:
196
196
  - lib/danger/ci_source/appcenter.rb
197
197
  - lib/danger/ci_source/appveyor.rb
198
198
  - lib/danger/ci_source/azure_pipelines.rb
199
+ - lib/danger/ci_source/bamboo.rb
199
200
  - lib/danger/ci_source/bitbucket_pipelines.rb
200
201
  - lib/danger/ci_source/bitrise.rb
201
202
  - lib/danger/ci_source/buddybuild.rb
@@ -318,7 +319,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
318
319
  - !ruby/object:Gem::Version
319
320
  version: '0'
320
321
  requirements: []
321
- rubygems_version: 3.0.3
322
+ rubyforge_project:
323
+ rubygems_version: 2.7.6.2
322
324
  signing_key:
323
325
  specification_version: 4
324
326
  summary: Like Unit Tests, but for your Team Culture.