danger 2.1.2 → 2.1.3

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: 8f0959f195af33185bbbdb41f1056e67a7c9babf
4
- data.tar.gz: 61223153953f39a208c7c9edfa9103b1748d8124
3
+ metadata.gz: 1bf87af94fa6f272c52fff0a149ca15b0328e76d
4
+ data.tar.gz: 5c9e4dffa0eddc1cee08eb7884d8d7729c4c1c1b
5
5
  SHA512:
6
- metadata.gz: abf51e8a4378186c34e869654f0216ff18501ebdc79d304c7a9c8b271c22219226d334fe9e466a4c1d41f476e32385f26c9764de5a6e23bf96b0de9d83ed8aba
7
- data.tar.gz: 8a6bc14ef8e75a917d43a8b65f7366610d784775a54abb411f87ca1146b83b4599161ef96f7f503cdc4c3bfd9fcaa70ac9fe53d5b2003356a7ca47055c411a8e
6
+ metadata.gz: 36721c111dd986918c83e747b8ccebc3325f187289103e7770537533a99173c2f1c14f6f9835d811172ea409b79be0f5ea748ac0c03344c261bac85e0aaf3915
7
+ data.tar.gz: fb5ea6d86915a9628dcc9906a67b265edd4aae7831448c605c3807bc243a9539c1464840926e1c171f5739760f967d7700ed32b5d64e3abae9b1520b0da7b9d8
@@ -23,7 +23,8 @@ module Danger
23
23
  end
24
24
 
25
25
  def self.validates_as_pr?(env)
26
- ["BUILDKITE_PULL_REQUEST_REPO", "BUILDKITE_PULL_REQUEST"].all? { |x| env[x] }
26
+ exists = ["BUILDKITE_PULL_REQUEST_REPO", "BUILDKITE_PULL_REQUEST"].all? { |x| env[x] }
27
+ exists && !env["BUILDKITE_PULL_REQUEST_REPO"].empty?
27
28
  end
28
29
 
29
30
  def initialize(env)
@@ -14,12 +14,21 @@
14
14
  </tr>
15
15
  </thead>
16
16
  <tbody>
17
- <%- table[:content].each do |violation| -%>
17
+ <%- max_num_violations = 700 %>
18
+ <%- table[:content].take(max_num_violations).each do |violation| -%>
18
19
  <tr>
19
20
  <td>:<%= table[:emoji] %>:</td>
20
21
  <td data-sticky="<%= violation.sticky %>"><%= violation.message %></td>
21
22
  </tr>
22
23
  <%- end -%>
24
+ <%- if table[:content].length > max_num_violations -%>
25
+ <tr>
26
+ <td>:warning:</td>
27
+ <td>
28
+ Danger found <%= table[:content].length %> violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to <%= max_num_violations %>.
29
+ </td>
30
+ </tr>
31
+ <%- end -%>
23
32
  <%- table[:resolved].each do |message| -%>
24
33
  <tr>
25
34
  <td>:white_check_mark:</td>
@@ -158,7 +158,7 @@ module Danger
158
158
 
159
159
  # @!group GitHub Misc
160
160
  # The hash that represents the PR's JSON. For an example of what this looks like
161
- # see the [Danger Fixture'd one](https://raw.githubusercontent.com/danger/danger/master/spec/fixtures/pr_response.json).
161
+ # see the [Danger Fixture'd one](https://raw.githubusercontent.com/danger/danger/master/spec/fixtures/github_api/pr_response.json).
162
162
  # @return [Hash]
163
163
  #
164
164
  def pr_json
@@ -22,7 +22,7 @@ module Danger
22
22
  #
23
23
  # fail "This build didn't pass tests"
24
24
  #
25
- # @example Failing a build, but not keeping it's value around on subsequent runs
25
+ # @example Failing a build, but not keeping its value around on subsequent runs
26
26
  #
27
27
  # fail("This build didn't pass tests", sticky: false)
28
28
  #
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
- require 'octokit'
3
- require 'danger/helpers/comments_helper'
2
+ require "octokit"
3
+ require "danger/helpers/comments_helper"
4
4
 
5
5
  module Danger
6
6
  module RequestSources
@@ -15,9 +15,9 @@ module Danger
15
15
  self.support_tokenless_auth = false
16
16
 
17
17
  Octokit.auto_paginate = true
18
- @token = @environment['DANGER_GITHUB_API_TOKEN']
19
- if @environment['DANGER_GITHUB_API_HOST']
20
- Octokit.api_endpoint = @environment['DANGER_GITHUB_API_HOST']
18
+ @token = @environment["DANGER_GITHUB_API_TOKEN"]
19
+ if @environment["DANGER_GITHUB_API_HOST"]
20
+ Octokit.api_endpoint = @environment["DANGER_GITHUB_API_HOST"]
21
21
  end
22
22
  end
23
23
 
@@ -26,16 +26,16 @@ module Danger
26
26
  end
27
27
 
28
28
  def host
29
- @host = @environment['DANGER_GITHUB_HOST'] || 'github.com'
29
+ @host = @environment["DANGER_GITHUB_HOST"] || "github.com"
30
30
  end
31
31
 
32
32
  def client
33
- raise 'No API token given, please provide one using `DANGER_GITHUB_API_TOKEN`' if !@token && !support_tokenless_auth
33
+ raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN`" if !@token && !support_tokenless_auth
34
34
  @client ||= Octokit::Client.new(access_token: @token)
35
35
  end
36
36
 
37
37
  def pr_diff
38
- @pr_diff ||= client.pull_request(ci_source.repo_slug, ci_source.pull_request_id, accept: 'application/vnd.github.v3.diff')
38
+ @pr_diff ||= client.pull_request(ci_source.repo_slug, ci_source.pull_request_id, accept: "application/vnd.github.v3.diff")
39
39
  end
40
40
 
41
41
  def setup_danger_branches
@@ -69,11 +69,11 @@ module Danger
69
69
  end
70
70
 
71
71
  # Sending data to GitHub
72
- def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: 'danger')
72
+ def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger")
73
73
  comment_result = {}
74
74
 
75
75
  issues = client.issue_comments(ci_source.repo_slug, ci_source.pull_request_id)
76
- editable_issues = issues.reject { |issue| issue[:body].include?("generated_by_#{danger_id}") == false }
76
+ editable_issues = issues.select { |issue| danger_issue?(issue, danger_id) }
77
77
 
78
78
  if editable_issues.empty?
79
79
  previous_violations = {}
@@ -92,7 +92,7 @@ module Danger
92
92
  markdowns: markdowns,
93
93
  previous_violations: previous_violations,
94
94
  danger_id: danger_id,
95
- template: 'github')
95
+ template: "github")
96
96
 
97
97
  if editable_issues.empty?
98
98
  comment_result = client.add_comment(ci_source.repo_slug, ci_source.pull_request_id, body)
@@ -106,11 +106,11 @@ module Danger
106
106
  # Note: this can terminate the entire process.
107
107
  submit_pull_request_status!(warnings: warnings,
108
108
  errors: errors,
109
- details_url: comment_result['html_url'])
109
+ details_url: comment_result["html_url"])
110
110
  end
111
111
 
112
112
  def submit_pull_request_status!(warnings: [], errors: [], details_url: [])
113
- status = (errors.count.zero? ? 'success' : 'failure')
113
+ status = (errors.count.zero? ? "success" : "failure")
114
114
  message = generate_description(warnings: warnings, errors: errors)
115
115
 
116
116
  latest_pr_commit_ref = self.pr_json[:head][:sha]
@@ -122,7 +122,7 @@ module Danger
122
122
  begin
123
123
  client.create_status(ci_source.repo_slug, latest_pr_commit_ref, status, {
124
124
  description: message,
125
- context: 'danger/danger',
125
+ context: "danger/danger",
126
126
  target_url: details_url
127
127
  })
128
128
  rescue
@@ -133,7 +133,7 @@ module Danger
133
133
  # We need to fail the actual build here
134
134
  is_private = pr_json[:base][:repo][:private]
135
135
  if is_private
136
- abort("\nDanger has failed this build. \nFound #{'error'.danger_pluralize(errors.count)} and I don't have write access to the PR set a PR status.")
136
+ abort("\nDanger has failed this build. \nFound #{'error'.danger_pluralize(errors.count)} and I don't have write access to the PR to set a PR status.")
137
137
  else
138
138
  abort("\nDanger has failed this build. \nFound #{'error'.danger_pluralize(errors.count)}.")
139
139
  end
@@ -144,10 +144,10 @@ module Danger
144
144
  end
145
145
 
146
146
  # Get rid of the previously posted comment, to only have the latest one
147
- def delete_old_comments!(except: nil, danger_id: 'danger')
147
+ def delete_old_comments!(except: nil, danger_id: "danger")
148
148
  issues = client.issue_comments(ci_source.repo_slug, ci_source.pull_request_id)
149
149
  issues.each do |issue|
150
- next unless issue[:body].include?("generated_by_#{danger_id}")
150
+ next unless danger_issue?(issue, danger_id)
151
151
  next if issue[:id] == except
152
152
  client.delete_comment(ci_source.repo_slug, issue[:id])
153
153
  end
@@ -190,10 +190,16 @@ module Danger
190
190
  end
191
191
 
192
192
  # @return [String] A URL to the specific file, ready to be downloaded
193
- def file_url(organisation: nil, repository: nil, branch: 'master', path: nil)
193
+ def file_url(organisation: nil, repository: nil, branch: "master", path: nil)
194
194
  organisation ||= self.organisation
195
195
  "https://raw.githubusercontent.com/#{organisation}/#{repository}/#{branch}/#{path}"
196
196
  end
197
+
198
+ private
199
+
200
+ def danger_issue?(issue, danger_id)
201
+ issue[:body].include?("generated_by_#{danger_id}")
202
+ end
197
203
  end
198
204
  end
199
205
  end
@@ -8,7 +8,9 @@ module Danger
8
8
 
9
9
  def diff_for_folder(folder, from: "master", to: "HEAD")
10
10
  repo = Git.open folder
11
- self.diff = repo.diff(from, to)
11
+
12
+ merge_base = repo.merge_base(from, to)
13
+ self.diff = repo.diff(merge_base.to_s, to)
12
14
  self.log = repo.log.between(from, to)
13
15
  end
14
16
 
@@ -25,3 +27,28 @@ module Danger
25
27
  end
26
28
  end
27
29
  end
30
+
31
+ # For full context see:
32
+ # https://github.com/danger/danger/issues/160
33
+ # and https://github.com/danger/danger/issues/316
34
+ #
35
+ # for which the fix comes from an unmerged PR from 2012
36
+ # https://github.com/schacon/ruby-git/pull/43
37
+
38
+ module Git
39
+ class Base
40
+ def merge_base(commit1, commit2, *other_commits)
41
+ Git::Object.new self, self.lib.merge_base(commit1, commit2, *other_commits)
42
+ end
43
+ end
44
+
45
+ class Lib
46
+ def merge_base(commit1, commit2, *other_commits)
47
+ arr_opts = []
48
+ arr_opts << commit1
49
+ arr_opts << commit2
50
+ arr_opts += other_commits
51
+ command("merge-base", arr_opts)
52
+ end
53
+ end
54
+ end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "2.1.2".freeze
2
+ VERSION = "2.1.3".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.2
4
+ version: 2.1.3
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-07 00:00:00.000000000 Z
12
+ date: 2016-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide