danger 5.4.3 → 5.5.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: 46b84e6217c921dda10765acbe116a3da6ee00cd
4
- data.tar.gz: 558617a4e1e01d226d08e9f6170641ddcd0cedb8
3
+ metadata.gz: 035ce582ea667e60dfda80d1c6c3292c17d7f384
4
+ data.tar.gz: faa2bacbc0e417f69e21b6fcf3e301f0789c90f5
5
5
  SHA512:
6
- metadata.gz: 3bd2d6c49555450e934aa5ac675b4db0eb658ce7571dda6699564ff479fd1e7e360339a441ad6da45850869c7871d38ebfa8febcd118944381d852f1f302a8c0
7
- data.tar.gz: dc2616251d6a850d51387a6d18111a8ba23e49f7cbdaeec631d5669acde68397cf3a11c97efea57db4ebf3476d73ce5d2b3f307c6330356f5a2637dafd74e2fe
6
+ metadata.gz: e139a3aa585b191a0d2959e4565a56626b5d66c11f03926c5c1ee91625d28a085309b4491aa489a1d9b220de8220af534cfc0f4481d13fa0a68a48f1059f4d30
7
+ data.tar.gz: 945bd0fecf7c392b19ce7928ea76938e862c540121f771accc791ad60fcc8722b3c18d4a287f5bcfb7500d9ec5dd5c9d52b5d7ae9dd91cb32029c9be7dc3df82
@@ -32,7 +32,11 @@ module Danger
32
32
  # #### General
33
33
  #
34
34
  # People occasionally see issues with Danger not classing your CI runs as a PR, to give you visibilty
35
- # the Jenkins side of Danger expects to see one of these env vars: ghprbPullId, CHANGE_ID or gitlabMergeRequestId
35
+ # the Jenkins side of Danger expects to see one of these env vars:
36
+ # - ghprbPullId
37
+ # - CHANGE_ID
38
+ # - gitlabMergeRequestIid
39
+ # - gitlabMergeRequestId
36
40
  #
37
41
  # ### Token Setup
38
42
  #
@@ -81,6 +85,8 @@ module Danger
81
85
  env["ghprbPullId"]
82
86
  elsif env["CHANGE_ID"]
83
87
  env["CHANGE_ID"]
88
+ elsif env["gitlabMergeRequestIid"]
89
+ env["gitlabMergeRequestIid"]
84
90
  else
85
91
  env["gitlabMergeRequestId"]
86
92
  end
@@ -9,7 +9,7 @@ module Danger
9
9
  validate_pry_available
10
10
  FileUtils.cp dangerfile_path, DANGERFILE_COPY
11
11
  File.open(DANGERFILE_COPY, "a") do |f|
12
- f.write("binding.pry; File.delete(\"#{DANGERFILE_COPY}\")")
12
+ f.write("\nbinding.pry; File.delete(\"#{DANGERFILE_COPY}\")")
13
13
  end
14
14
  DANGERFILE_COPY
15
15
  end
@@ -16,7 +16,7 @@ module Danger
16
16
  end
17
17
 
18
18
  def generated_by_danger?(danger_id)
19
- body.include?("generated_by_#{danger_id}")
19
+ body.include?("\"generated_by_#{danger_id}\"")
20
20
  end
21
21
  end
22
22
  end
@@ -46,16 +46,18 @@ module Danger
46
46
  end
47
47
 
48
48
  def setup_danger_branches
49
+ base_branch = self.pr_json[:destination][:branch][:name]
49
50
  base_commit = self.pr_json[:destination][:commit][:hash]
51
+ head_branch = self.pr_json[:source][:branch][:name]
50
52
  head_commit = self.pr_json[:source][:commit][:hash]
51
53
 
52
54
  # Next, we want to ensure that we have a version of the current branch at a known location
53
- scm.ensure_commitish_exists! base_commit
55
+ scm.ensure_commitish_exists_on_branch! base_branch, base_commit
54
56
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
55
57
 
56
58
  # OK, so we want to ensure that we have a known head branch, this will always represent
57
59
  # the head of the PR ( e.g. the most recent commit that will be merged. )
58
- scm.ensure_commitish_exists! head_commit
60
+ scm.ensure_commitish_exists_on_branch! head_branch, head_commit
59
61
  self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
60
62
  end
61
63
 
@@ -47,16 +47,18 @@ module Danger
47
47
  end
48
48
 
49
49
  def setup_danger_branches
50
+ base_branch = self.pr_json[:toRef][:id].sub("refs/heads/", "")
50
51
  base_commit = self.pr_json[:toRef][:latestCommit]
52
+ head_branch = self.pr_json[:fromRef][:id].sub("refs/heads/", "")
51
53
  head_commit = self.pr_json[:fromRef][:latestCommit]
52
54
 
53
55
  # Next, we want to ensure that we have a version of the current branch at a known location
54
- scm.ensure_commitish_exists! base_commit
56
+ scm.ensure_commitish_exists_on_branch! base_branch, base_commit
55
57
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
56
58
 
57
59
  # OK, so we want to ensure that we have a known head branch, this will always represent
58
60
  # the head of the PR ( e.g. the most recent commit that will be merged. )
59
- scm.ensure_commitish_exists! head_commit
61
+ scm.ensure_commitish_exists_on_branch! head_branch, head_commit
60
62
  self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
61
63
  end
62
64
 
@@ -98,16 +98,18 @@ module Danger
98
98
 
99
99
  def setup_danger_branches
100
100
  # we can use a github specific feature here:
101
+ base_branch = self.pr_json["base"]["ref"]
101
102
  base_commit = self.pr_json["base"]["sha"]
103
+ head_branch = self.pr_json["head"]["ref"]
102
104
  head_commit = self.pr_json["head"]["sha"]
103
105
 
104
106
  # Next, we want to ensure that we have a version of the current branch at a known location
105
- scm.ensure_commitish_exists! base_commit
107
+ scm.ensure_commitish_exists_on_branch! base_branch, base_commit
106
108
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
107
109
 
108
110
  # OK, so we want to ensure that we have a known head branch, this will always represent
109
111
  # the head of the PR ( e.g. the most recent commit that will be merged. )
110
- scm.ensure_commitish_exists! head_commit
112
+ scm.ensure_commitish_exists_on_branch! head_branch, head_commit
111
113
  self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
112
114
  end
113
115
 
@@ -78,15 +78,17 @@ module Danger
78
78
  end
79
79
 
80
80
  def setup_danger_branches
81
+ base_branch = self.mr_json.source_branch
82
+ head_branch = self.mr_json.target_branch
81
83
  head_commit = self.scm.head_commit
82
84
 
83
85
  # Next, we want to ensure that we have a version of the current branch at a known location
84
- scm.ensure_commitish_exists! base_commit
86
+ scm.ensure_commitish_exists_on_branch! base_branch, base_commit
85
87
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
86
88
 
87
89
  # OK, so we want to ensure that we have a known head branch, this will always represent
88
90
  # the head of the PR ( e.g. the most recent commit that will be merged. )
89
- scm.ensure_commitish_exists! head_commit
91
+ scm.ensure_commitish_exists_on_branch! head_branch, head_commit
90
92
  self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
91
93
  end
92
94
 
@@ -53,16 +53,18 @@ module Danger
53
53
  end
54
54
 
55
55
  def setup_danger_branches
56
+ base_branch = self.pr_json[:targetRefName].sub("refs/heads/", "")
56
57
  base_commit = self.pr_json[:lastMergeTargetCommit][:commitId]
58
+ head_branch = self.pr_json[:sourceRefName].sub("refs/heads/", "")
57
59
  head_commit = self.pr_json[:lastMergeSourceCommit][:commitId]
58
60
 
59
61
  # Next, we want to ensure that we have a version of the current branch at a known location
60
- scm.ensure_commitish_exists! base_commit
62
+ scm.ensure_commitish_exists_on_branch! base_branch, base_commit
61
63
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
62
64
 
63
65
  # OK, so we want to ensure that we have a known head branch, this will always represent
64
66
  # the head of the PR ( e.g. the most recent commit that will be merged. )
65
- scm.ensure_commitish_exists! head_commit
67
+ scm.ensure_commitish_exists_on_branch! head_branch, head_commit
66
68
  self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
67
69
  end
68
70
 
@@ -64,11 +64,29 @@ module Danger
64
64
  end
65
65
 
66
66
  def ensure_commitish_exists!(commitish)
67
- git_in_depth_fetch if commit_not_exists?(commitish)
67
+ return ensure_commitish_exists_on_branch!(commitish, commitish) if commit_is_ref?(commitish)
68
+ return if commit_exists?(commitish)
68
69
 
69
- if commit_not_exists?(commitish)
70
- raise_if_we_cannot_find_the_commit(commitish)
71
- end
70
+ git_in_depth_fetch
71
+ raise_if_we_cannot_find_the_commit(commitish) if commit_not_exists?(commitish)
72
+ end
73
+
74
+ def ensure_commitish_exists_on_branch!(branch, commitish)
75
+ return if commit_exists?(commitish)
76
+
77
+ depth = 0
78
+ success =
79
+ (3..6).any? do |factor|
80
+ depth += Math.exp(factor).to_i
81
+
82
+ git_fetch_branch_to_depth(branch, depth)
83
+ commit_exists?(commitish)
84
+ end
85
+
86
+ return if success
87
+
88
+ git_in_depth_fetch
89
+ raise_if_we_cannot_find_the_commit(commitish) if commit_not_exists?(commitish)
72
90
  end
73
91
 
74
92
  private
@@ -77,6 +95,10 @@ module Danger
77
95
  exec("fetch --depth 1000000")
78
96
  end
79
97
 
98
+ def git_fetch_branch_to_depth(branch, depth)
99
+ exec("fetch --depth=#{depth} --prune origin +refs/heads/#{branch}:refs/remotes/origin/#{branch}")
100
+ end
101
+
80
102
  def default_env
81
103
  { "LANG" => "en_US.UTF-8" }
82
104
  end
@@ -95,17 +117,35 @@ module Danger
95
117
 
96
118
  def find_merge_base(repo, from, to)
97
119
  possible_merge_base = possible_merge_base(repo, from, to)
120
+ return possible_merge_base if possible_merge_base
98
121
 
99
- unless possible_merge_base
100
- git_in_depth_fetch
101
- possible_merge_base = possible_merge_base(repo, from, to)
102
- end
122
+ possible_merge_base = find_merge_base_with_incremental_fetch(repo, from, to)
123
+ return possible_merge_base if possible_merge_base
124
+
125
+ git_in_depth_fetch
126
+ possible_merge_base = possible_merge_base(repo, from, to)
103
127
 
104
128
  raise "Cannot find a merge base between #{from} and #{to}." unless possible_merge_base
105
129
 
106
130
  possible_merge_base
107
131
  end
108
132
 
133
+ def find_merge_base_with_incremental_fetch(repo, from, to)
134
+ from_is_ref = commit_is_ref?(from)
135
+ to_is_ref = commit_is_ref?(to)
136
+
137
+ return unless from_is_ref || to_is_ref
138
+
139
+ depth = 0
140
+ (3..6).any? do |factor|
141
+ depth += Math.exp(factor).to_i
142
+
143
+ git_fetch_branch_to_depth(from, depth) if from_is_ref
144
+ git_fetch_branch_to_depth(to, depth) if to_is_ref
145
+ possible_merge_base(repo, from, to)
146
+ end
147
+ end
148
+
109
149
  def possible_merge_base(repo, from, to)
110
150
  [repo.merge_base(from, to)].find { |base| commit_exists?(base) }
111
151
  end
@@ -113,6 +153,10 @@ module Danger
113
153
  def commits_in_branch_count(from, to)
114
154
  exec("rev-list #{from}..#{to} --count").to_i
115
155
  end
156
+
157
+ def commit_is_ref?(commit)
158
+ /[a-f0-9]{5,40}/ !~ commit
159
+ end
116
160
  end
117
161
  end
118
162
 
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "5.4.3".freeze
2
+ VERSION = "5.5.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: 5.4.3
4
+ version: 5.5.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: 2017-09-14 00:00:00.000000000 Z
12
+ date: 2017-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -487,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
487
487
  version: '0'
488
488
  requirements: []
489
489
  rubyforge_project:
490
- rubygems_version: 2.6.13
490
+ rubygems_version: 2.2.2
491
491
  signing_key:
492
492
  specification_version: 4
493
493
  summary: Like Unit Tests, but for your Team Culture.