danger 3.5.4 → 3.5.5

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: 989776d07fb68d675c57bb156dcb3a5e8a42f9c1
4
- data.tar.gz: 8c797383ea005b6c60b1896dcf1acb071dc08de7
3
+ metadata.gz: c92b72cb5561d7e1421f18365fc62b481c9762d8
4
+ data.tar.gz: f8cdf206cb65498b8312019dfc839d70d4360ef2
5
5
  SHA512:
6
- metadata.gz: 3a619a8989461ac9cc409610c71d0b1cd30f445c064e4c9a190a66b88bcd50bfedfce9c48fa3cbc0038257ac6ae18582ec2a52565ebca9ec0197df1c1405df47
7
- data.tar.gz: 4d54581d81ac705ffcd9a700ebb339f61e17bef7bd612a6c99837253e91b6a5b36f91242e9f26313f6d30c099c0a7934b811dd028424c0ee7e92f458321687cb
6
+ metadata.gz: 3dc93f4a46211f5924006f83797e15a02284faf6f515343daf211041a066719916292df8b49f60a360ff828d910686bcdef932676ca91c68c3c9e414ea93034d
7
+ data.tar.gz: 1a615082ce6d120d6732357ce403247da7a607affe8620ea2a2edb55cc9c239b3bdb585c2c39967e6c3d71db493f4b1c4ffd125481009049f54ff12e961c6fdd
@@ -37,8 +37,8 @@ module Danger
37
37
  @base = argv.option("base")
38
38
  @head = argv.option("head")
39
39
  @fail_on_errors = argv.option("fail-on-errors", false)
40
- new_comment = argv.flag?("new-comment")
41
- @danger_id = new_comment ? Time.now.strftime("%v %H:%M:%S") : argv.option("danger_id", "danger")
40
+ @new_comment = argv.flag?("new-comment")
41
+ @danger_id = argv.option("danger_id", "danger")
42
42
  @cork = Cork::Board.new(silent: argv.option("silent", false),
43
43
  verbose: argv.option("verbose", false))
44
44
  super
@@ -58,7 +58,7 @@ module Danger
58
58
  ["--fail-on-errors=<true|false>", "Should always fail the build process, defaults to false"],
59
59
  ["--dangerfile=<path/to/dangerfile>", "The location of your Dangerfile"],
60
60
  ["--danger_id=<id>", "The identifier of this Danger instance"],
61
- ["--new-comment", "Makes the build process ignore other Danger instances, resulting in a new comment. Overrides '--danger_id'."]
61
+ ["--new-comment", "Makes Danger post a new comment instead of editing it's previous one"]
62
62
  ].concat(super)
63
63
  end
64
64
 
@@ -68,6 +68,7 @@ module Danger
68
68
  head: @head,
69
69
  dangerfile_path: @dangerfile_path,
70
70
  danger_id: @danger_id,
71
+ new_comment: @new_comment,
71
72
  fail_on_errors: @fail_on_errors
72
73
  )
73
74
  end
@@ -241,7 +241,7 @@ module Danger
241
241
  violation_report[:errors].count > 0
242
242
  end
243
243
 
244
- def post_results(danger_id)
244
+ def post_results(danger_id, new_comment)
245
245
  violations = violation_report
246
246
 
247
247
  env.request_source.update_pull_request!(
@@ -249,7 +249,8 @@ module Danger
249
249
  errors: violations[:errors],
250
250
  messages: violations[:messages],
251
251
  markdowns: status_report[:markdowns],
252
- danger_id: danger_id
252
+ danger_id: danger_id,
253
+ new_comment: new_comment
253
254
  )
254
255
  end
255
256
 
@@ -258,7 +259,7 @@ module Danger
258
259
  env.scm.diff_for_folder(".".freeze, from: base_branch, to: head_branch)
259
260
  end
260
261
 
261
- def run(base_branch, head_branch, dangerfile_path, danger_id)
262
+ def run(base_branch, head_branch, dangerfile_path, danger_id, new_comment)
262
263
  # Setup internal state
263
264
  init_plugins
264
265
  env.fill_environment_vars
@@ -273,7 +274,7 @@ module Danger
273
274
  # Push results to the API
274
275
  # Pass along the details of the run to the request source
275
276
  # to send back to the code review site.
276
- post_results(danger_id)
277
+ post_results(danger_id, new_comment)
277
278
 
278
279
  # Print results in the terminal
279
280
  print_results
@@ -11,6 +11,7 @@ module Danger
11
11
  head: nil,
12
12
  dangerfile_path: nil,
13
13
  danger_id: nil,
14
+ new_comment: nil,
14
15
  fail_on_errors: nil)
15
16
  # Create a silent Cork instance if cork is nil, as it's likely a test
16
17
  cork ||= Cork::Board.new(silent: false, verbose: false)
@@ -27,7 +28,8 @@ module Danger
27
28
  base_branch(base),
28
29
  head_branch(head),
29
30
  dangerfile_path,
30
- danger_id
31
+ danger_id,
32
+ new_comment
31
33
  )
32
34
  end
33
35
 
@@ -105,15 +105,16 @@ module Danger
105
105
  end
106
106
 
107
107
  # Sending data to GitHub
108
- def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger")
108
+ def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger", new_comment: false)
109
109
  comment_result = {}
110
110
  editable_comments = issue_comments.select { |comment| comment.generated_by_danger?(danger_id) }
111
+ last_comment = editable_comments.last
112
+ should_create_new_comment = new_comment || last_comment.nil?
111
113
 
112
- if editable_comments.empty?
114
+ if should_create_new_comment
113
115
  previous_violations = {}
114
116
  else
115
- comment = editable_comments.first.body
116
- previous_violations = parse_comment(comment)
117
+ previous_violations = parse_comment(last_comment.body)
117
118
  end
118
119
 
119
120
  main_violations = (warnings + errors + messages + markdowns).reject(&:inline?)
@@ -154,11 +155,10 @@ module Danger
154
155
  danger_id: danger_id,
155
156
  template: "github")
156
157
 
157
- if editable_comments.empty?
158
+ if should_create_new_comment
158
159
  comment_result = client.add_comment(ci_source.repo_slug, ci_source.pull_request_id, body)
159
160
  else
160
- original_id = editable_comments.first.id
161
- comment_result = client.update_comment(ci_source.repo_slug, original_id, body)
161
+ comment_result = client.update_comment(ci_source.repo_slug, last_comment.id, body)
162
162
  end
163
163
  end
164
164
 
@@ -199,6 +199,7 @@ module Danger
199
199
  end
200
200
  else
201
201
  puts message
202
+ puts "\nDanger does not have write access to the PR to set a PR status.".yellow
202
203
  end
203
204
  end
204
205
  end
@@ -12,10 +12,10 @@ module Danger
12
12
 
13
13
  ensure_commitish_exists!(from)
14
14
  ensure_commitish_exists!(to)
15
- merge_base = repo.merge_base(from, to)
16
15
 
17
- ensure_commitish_exists!(merge_base)
18
- self.diff = repo.diff(merge_base.to_s, to)
16
+ merge_base = find_merge_base(repo, from, to)
17
+
18
+ self.diff = repo.diff(merge_base, to)
19
19
  self.log = repo.log.between(from, to)
20
20
  end
21
21
 
@@ -29,7 +29,7 @@ module Danger
29
29
  end
30
30
 
31
31
  def head_commit
32
- exec "rev-parse HEAD"
32
+ exec("rev-parse HEAD")
33
33
  end
34
34
 
35
35
  def origins
@@ -37,46 +37,60 @@ module Danger
37
37
  end
38
38
 
39
39
  def ensure_commitish_exists!(commitish)
40
- exec("fetch") if exec("rev-parse --quiet --verify \"#{commitish}^{commit}\"").empty?
40
+ git_shallow_fetch if commit_not_exists?(commitish)
41
41
 
42
- if exec("rev-parse --quiet --verify \"#{commitish}^{commit}\"").empty?
42
+ if commit_not_exists?(commitish)
43
43
  raise_if_we_cannot_find_the_commit(commitish)
44
44
  end
45
45
  end
46
46
 
47
47
  private
48
48
 
49
+ def git_shallow_fetch
50
+ exec("fetch --unshallow")
51
+ end
52
+
49
53
  def default_env
50
54
  { "LANG" => "en_US.UTF-8" }
51
55
  end
52
56
 
53
- def raise_if_we_cannot_find_the_commit(commit)
54
- raise "Commit #{commit[0..7]} doesn't exist. Are you running `danger local/pr` against the correct repository? Also this usually happens when you rebase/reset and force-pushed."
57
+ def raise_if_we_cannot_find_the_commit(commitish)
58
+ raise "Commit #{commitish[0..7]} doesn't exist. Are you running `danger local/pr` against the correct repository? Also this usually happens when you rebase/reset and force-pushed."
55
59
  end
56
- end
57
- end
58
60
 
59
- # For full context see:
60
- # https://github.com/danger/danger/issues/160
61
- # and https://github.com/danger/danger/issues/316
62
- #
63
- # for which the fix comes from an unmerged PR from 2012
64
- # https://github.com/schacon/ruby-git/pull/43
61
+ def commit_exists?(sha1)
62
+ !commit_not_exists?(sha1)
63
+ end
65
64
 
66
- module Git
67
- class Base
68
- def merge_base(commit1, commit2, *other_commits)
69
- Git::Object.new self, self.lib.merge_base(commit1, commit2, *other_commits)
65
+ def commit_not_exists?(sha1)
66
+ exec("rev-parse --quiet --verify #{sha1}^{commit}").empty?
67
+ end
68
+
69
+ def find_merge_base(repo, from, to)
70
+ possible_merge_base = possible_merge_base(repo, from, to)
71
+
72
+ unless possible_merge_base
73
+ git_shallow_fetch
74
+ possible_merge_base = possible_merge_base(repo, from, to)
75
+ end
76
+
77
+ raise "Cannot find a merge base between #{from} and #{to}." unless possible_merge_base
78
+
79
+ possible_merge_base
80
+ end
81
+
82
+ def possible_merge_base(repo, from, to)
83
+ [repo.merge_base(from, to)].find { |base| commit_exists?(base) }
70
84
  end
71
85
  end
86
+ end
72
87
 
73
- class Lib
88
+ module Git
89
+ class Base
90
+ # Use git-merge-base https://git-scm.com/docs/git-merge-base to
91
+ # find as good common ancestors as possible for a merge
74
92
  def merge_base(commit1, commit2, *other_commits)
75
- arr_opts = []
76
- arr_opts << commit1
77
- arr_opts << commit2
78
- arr_opts += other_commits
79
- command("merge-base", arr_opts)
93
+ Open3.popen2("git", "merge-base", "--all", commit1, commit2, *other_commits) { |_stdin, stdout, _wait_thr| stdout.read.rstrip }
80
94
  end
81
95
  end
82
96
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "3.5.4".freeze
2
+ VERSION = "3.5.5".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: 3.5.4
4
+ version: 3.5.5
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-10-12 00:00:00.000000000 Z
12
+ date: 2016-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -269,14 +269,14 @@ dependencies:
269
269
  requirements:
270
270
  - - "~>"
271
271
  - !ruby/object:Gem::Version
272
- version: '0.38'
272
+ version: '0.44'
273
273
  type: :development
274
274
  prerelease: false
275
275
  version_requirements: !ruby/object:Gem::Requirement
276
276
  requirements:
277
277
  - - "~>"
278
278
  - !ruby/object:Gem::Version
279
- version: '0.38'
279
+ version: '0.44'
280
280
  - !ruby/object:Gem::Dependency
281
281
  name: yard
282
282
  requirement: !ruby/object:Gem::Requirement