danger 8.4.2 → 9.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/bin/danger +1 -1
- data/lib/danger/ci_source/appcircle.rb +83 -0
- data/lib/danger/ci_source/appveyor.rb +1 -0
- data/lib/danger/ci_source/azure_pipelines.rb +20 -5
- data/lib/danger/ci_source/bamboo.rb +1 -1
- data/lib/danger/ci_source/bitbucket_pipelines.rb +1 -2
- data/lib/danger/ci_source/bitrise.rb +10 -10
- data/lib/danger/ci_source/buildkite.rb +1 -1
- data/lib/danger/ci_source/circle.rb +1 -1
- data/lib/danger/ci_source/circle_api.rb +2 -2
- data/lib/danger/ci_source/code_build.rb +20 -6
- data/lib/danger/ci_source/codefresh.rb +7 -13
- data/lib/danger/ci_source/concourse.rb +4 -5
- data/lib/danger/ci_source/dotci.rb +4 -6
- data/lib/danger/ci_source/github_actions.rb +6 -6
- data/lib/danger/ci_source/gitlab_ci.rb +13 -19
- data/lib/danger/ci_source/jenkins.rb +22 -23
- data/lib/danger/ci_source/local_git_repo.rb +36 -38
- data/lib/danger/ci_source/local_only_git_repo.rb +5 -8
- data/lib/danger/ci_source/support/find_repo_info_from_url.rb +11 -10
- data/lib/danger/ci_source/support/pull_request_finder.rb +47 -43
- data/lib/danger/ci_source/teamcity.rb +1 -1
- data/lib/danger/ci_source/xcode_cloud.rb +7 -7
- data/lib/danger/commands/init.rb +1 -1
- data/lib/danger/commands/local.rb +1 -1
- data/lib/danger/commands/local_helpers/http_cache.rb +2 -0
- data/lib/danger/commands/local_helpers/local_setup.rb +2 -0
- data/lib/danger/commands/local_helpers/pry_setup.rb +1 -0
- data/lib/danger/commands/plugins/plugin_json.rb +1 -3
- data/lib/danger/commands/plugins/plugin_lint.rb +0 -2
- data/lib/danger/commands/plugins/plugin_readme.rb +2 -5
- data/lib/danger/commands/pr.rb +2 -1
- data/lib/danger/commands/runner.rb +1 -1
- data/lib/danger/commands/staging.rb +7 -7
- data/lib/danger/commands/systems.rb +4 -6
- data/lib/danger/comment_generators/gitlab_inline.md.erb +1 -1
- data/lib/danger/comment_generators/vsts_inline.md.erb +17 -0
- data/lib/danger/core_ext/file_list.rb +2 -2
- data/lib/danger/danger_core/dangerfile.rb +19 -16
- data/lib/danger/danger_core/environment_manager.rb +2 -1
- data/lib/danger/danger_core/executor.rb +10 -11
- data/lib/danger/danger_core/message_aggregator.rb +1 -0
- data/lib/danger/danger_core/messages/base.rb +1 -0
- data/lib/danger/danger_core/messages/markdown.rb +3 -4
- data/lib/danger/danger_core/messages/violation.rb +1 -2
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +1 -3
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +4 -4
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +9 -3
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +4 -3
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +3 -1
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +3 -1
- data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +4 -3
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +3 -1
- data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +3 -3
- data/lib/danger/danger_core/standard_error.rb +2 -3
- data/lib/danger/helpers/array_subclass.rb +2 -2
- data/lib/danger/helpers/comments_helper.rb +8 -7
- data/lib/danger/helpers/comments_parsing_helper.rb +3 -2
- data/lib/danger/helpers/emoji_mapper.rb +1 -1
- data/lib/danger/plugin_support/plugin.rb +0 -1
- data/lib/danger/plugin_support/plugin_linter.rb +1 -0
- data/lib/danger/request_sources/bitbucket_cloud.rb +3 -6
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +5 -7
- data/lib/danger/request_sources/bitbucket_server.rb +47 -11
- data/lib/danger/request_sources/bitbucket_server_api.rb +17 -14
- data/lib/danger/request_sources/code_insights_api.rb +9 -14
- data/lib/danger/request_sources/github/github.rb +30 -38
- data/lib/danger/request_sources/github/github_review.rb +3 -2
- data/lib/danger/request_sources/github/github_review_resolver.rb +0 -2
- data/lib/danger/request_sources/github/github_review_unsupported.rb +0 -2
- data/lib/danger/request_sources/gitlab.rb +53 -75
- data/lib/danger/request_sources/local_only.rb +1 -4
- data/lib/danger/request_sources/request_source.rb +20 -8
- data/lib/danger/request_sources/support/get_ignored_violation.rb +1 -1
- data/lib/danger/request_sources/vsts.rb +175 -15
- data/lib/danger/request_sources/vsts_api.rb +41 -7
- data/lib/danger/scm_source/git_repo.rb +2 -1
- data/lib/danger/version.rb +1 -1
- data/lib/danger.rb +1 -0
- metadata +39 -37
- data/lib/danger/ci_source/vsts.rb +0 -73
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "danger/helpers/comments_helper"
|
4
4
|
|
@@ -32,9 +32,8 @@ module Danger
|
|
32
32
|
def inspect
|
33
33
|
inspected = super
|
34
34
|
|
35
|
-
if @password
|
36
|
-
|
37
|
-
end
|
35
|
+
inspected.gsub!(@password, "********") if @password
|
36
|
+
inspected.gsub!(@access_token, "********") if @access_token
|
38
37
|
|
39
38
|
inspected
|
40
39
|
end
|
@@ -57,7 +56,7 @@ module Danger
|
|
57
56
|
def fetch_comments
|
58
57
|
values = []
|
59
58
|
# TODO: use a url parts encoder to encode the query
|
60
|
-
corrected_uuid = @my_uuid[1...-1]
|
59
|
+
corrected_uuid = @my_uuid[1...-1] unless @my_uuid.nil? # Endpoint doesnt support curly brackets for this, so remove them for this
|
61
60
|
uri = "#{pr_api_endpoint}/comments?pagelen=100&q=deleted+%7E+false+AND+user.uuid+%7E+%22#{corrected_uuid}%22"
|
62
61
|
|
63
62
|
while uri
|
@@ -114,7 +113,7 @@ module Danger
|
|
114
113
|
uri = URI.parse("https://bitbucket.org/site/oauth2/access_token")
|
115
114
|
req = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
|
116
115
|
req.basic_auth oauth_key, oauth_secret
|
117
|
-
req.set_form_data({
|
116
|
+
req.set_form_data({ "grant_type" => "client_credentials" })
|
118
117
|
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
119
118
|
http.request(req)
|
120
119
|
end
|
@@ -177,7 +176,6 @@ module Danger
|
|
177
176
|
def error_fetching_json(url, status_code)
|
178
177
|
"Error fetching json for: #{url}, status code: #{status_code}"
|
179
178
|
end
|
180
|
-
|
181
179
|
end
|
182
180
|
end
|
183
181
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require "danger/helpers/comments_helper"
|
4
2
|
require "danger/request_sources/bitbucket_server_api"
|
5
3
|
require "danger/request_sources/code_insights_api"
|
@@ -9,7 +7,7 @@ module Danger
|
|
9
7
|
module RequestSources
|
10
8
|
class BitbucketServer < RequestSource
|
11
9
|
include Danger::Helpers::CommentsHelper
|
12
|
-
attr_accessor :pr_json
|
10
|
+
attr_accessor :pr_json, :dismiss_out_of_range_messages
|
13
11
|
|
14
12
|
def self.env_vars
|
15
13
|
[
|
@@ -25,13 +23,14 @@ module Danger
|
|
25
23
|
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_TITLE",
|
26
24
|
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_DESCRIPTION",
|
27
25
|
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_LOGO_URL",
|
28
|
-
"DANGER_BITBUCKETSERVER_VERIFY_SSL"
|
26
|
+
"DANGER_BITBUCKETSERVER_VERIFY_SSL",
|
27
|
+
"DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"
|
29
28
|
]
|
30
29
|
end
|
31
30
|
|
32
31
|
def initialize(ci_source, environment)
|
33
32
|
self.ci_source = ci_source
|
34
|
-
self.
|
33
|
+
self.dismiss_out_of_range_messages = environment["DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"] == "true"
|
35
34
|
|
36
35
|
project, slug = ci_source.repo_slug.split("/")
|
37
36
|
@api = BitbucketServerAPI.new(project, slug, ci_source.pull_request_id, environment)
|
@@ -59,6 +58,10 @@ module Danger
|
|
59
58
|
self.pr_json = @api.fetch_pr_json
|
60
59
|
end
|
61
60
|
|
61
|
+
def pr_diff
|
62
|
+
@pr_diff ||= @api.fetch_pr_diff
|
63
|
+
end
|
64
|
+
|
62
65
|
def setup_danger_branches
|
63
66
|
base_branch = self.pr_json[:toRef][:id].sub("refs/heads/", "")
|
64
67
|
base_commit = self.pr_json[:toRef][:latestCommit]
|
@@ -135,12 +138,22 @@ module Danger
|
|
135
138
|
end
|
136
139
|
|
137
140
|
def main_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
if dismiss_out_of_range_messages
|
142
|
+
{
|
143
|
+
warnings: warnings.reject(&:inline?),
|
144
|
+
errors: errors.reject(&:inline?),
|
145
|
+
messages: messages.reject(&:inline?),
|
146
|
+
markdowns: markdowns.reject(&:inline?)
|
147
|
+
}
|
148
|
+
else
|
149
|
+
in_diff = proc { |a| find_position_in_diff?(a.file, a.line) }
|
150
|
+
{
|
151
|
+
warnings: warnings.reject(&in_diff),
|
152
|
+
errors: errors.reject(&in_diff),
|
153
|
+
messages: messages.reject(&in_diff),
|
154
|
+
markdowns: markdowns.reject(&in_diff)
|
155
|
+
}
|
156
|
+
end
|
144
157
|
end
|
145
158
|
|
146
159
|
def inline_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
|
@@ -149,6 +162,7 @@ module Danger
|
|
149
162
|
next 1 unless b.file && b.line
|
150
163
|
|
151
164
|
next a.line <=> b.line if a.file == b.file
|
165
|
+
|
152
166
|
next a.file <=> b.file
|
153
167
|
end
|
154
168
|
|
@@ -169,6 +183,28 @@ module Danger
|
|
169
183
|
puts self.pr_json.to_json
|
170
184
|
@api.update_pr_build_status(status, changeset, build_job_link, description)
|
171
185
|
end
|
186
|
+
|
187
|
+
def find_position_in_diff?(file, line)
|
188
|
+
return nil if file.nil? || line.nil?
|
189
|
+
return nil if file.empty?
|
190
|
+
|
191
|
+
added_lines(file).include?(line)
|
192
|
+
end
|
193
|
+
|
194
|
+
def file_diff(file)
|
195
|
+
self.pr_diff[:diffs].find { |diff| diff[:destination] && diff[:destination][:toString] == file } || { hunks: [] }
|
196
|
+
end
|
197
|
+
|
198
|
+
def added_lines(file)
|
199
|
+
@added_lines ||= {}
|
200
|
+
@added_lines[file] ||= file_diff(file)[:hunks].map do |hunk|
|
201
|
+
hunk[:segments].select { |segment| segment[:type] == "ADDED" }.map do |segment|
|
202
|
+
segment[:lines].map do |line|
|
203
|
+
line[:destination]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end.flatten
|
207
|
+
end
|
172
208
|
end
|
173
209
|
end
|
174
210
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "openssl"
|
4
4
|
require "danger/helpers/comments_helper"
|
@@ -12,7 +12,7 @@ module Danger
|
|
12
12
|
@username = environment["DANGER_BITBUCKETSERVER_USERNAME"]
|
13
13
|
@password = environment["DANGER_BITBUCKETSERVER_PASSWORD"]
|
14
14
|
self.host = environment["DANGER_BITBUCKETSERVER_HOST"]
|
15
|
-
self.verify_ssl = environment["DANGER_BITBUCKETSERVER_VERIFY_SSL"]
|
15
|
+
self.verify_ssl = environment["DANGER_BITBUCKETSERVER_VERIFY_SSL"] != "false"
|
16
16
|
if self.host && !(self.host.include? "http://") && !(self.host.include? "https://")
|
17
17
|
self.host = "https://" + self.host
|
18
18
|
end
|
@@ -24,9 +24,7 @@ module Danger
|
|
24
24
|
def inspect
|
25
25
|
inspected = super
|
26
26
|
|
27
|
-
if @password
|
28
|
-
inspected = inspected.sub! @password, "********".freeze
|
29
|
-
end
|
27
|
+
inspected.gsub!(@password, "********") if @password
|
30
28
|
|
31
29
|
inspected
|
32
30
|
end
|
@@ -44,6 +42,11 @@ module Danger
|
|
44
42
|
fetch_json(uri)
|
45
43
|
end
|
46
44
|
|
45
|
+
def fetch_pr_diff
|
46
|
+
uri = URI("#{pr_api_endpoint}/diff?withComments=false")
|
47
|
+
fetch_json(uri)
|
48
|
+
end
|
49
|
+
|
47
50
|
def fetch_last_comments
|
48
51
|
uri = URI("#{pr_api_endpoint}/activities?limit=1000")
|
49
52
|
fetch_json(uri)[:values].select { |v| v[:action] == "COMMENTED" }.map { |v| v[:comment] }
|
@@ -61,9 +64,9 @@ module Danger
|
|
61
64
|
end
|
62
65
|
|
63
66
|
def update_pr_build_status(status, changeset, build_job_link, description)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
uri = URI("#{self.host}/rest/build-status/1.0/commits/#{changeset}")
|
68
|
+
body = build_status_body(status, build_job_link, description)
|
69
|
+
post(uri, body)
|
67
70
|
end
|
68
71
|
|
69
72
|
private
|
@@ -114,12 +117,12 @@ module Danger
|
|
114
117
|
end
|
115
118
|
|
116
119
|
def build_status_body(status, build_job_link, description)
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
body = {}
|
121
|
+
body["state"] = status
|
122
|
+
body["key"] = self.key
|
123
|
+
body["url"] = build_job_link
|
124
|
+
body["description"] = description if description
|
125
|
+
return body.to_json
|
123
126
|
end
|
124
127
|
end
|
125
128
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Danger
|
4
4
|
module RequestSources
|
@@ -26,9 +26,7 @@ module Danger
|
|
26
26
|
def inspect
|
27
27
|
inspected = super
|
28
28
|
|
29
|
-
if @password
|
30
|
-
inspected = inspected.sub! @password, "********".freeze
|
31
|
-
end
|
29
|
+
inspected.gsub!(@password, "********") if @password
|
32
30
|
|
33
31
|
inspected
|
34
32
|
end
|
@@ -39,7 +37,7 @@ module Danger
|
|
39
37
|
|
40
38
|
def delete_report(commit)
|
41
39
|
uri = URI(report_endpoint_at_commit(commit))
|
42
|
-
request = Net::HTTP::Delete.new(uri.request_uri, {"Content-Type" => "application/json"})
|
40
|
+
request = Net::HTTP::Delete.new(uri.request_uri, { "Content-Type" => "application/json" })
|
43
41
|
request.basic_auth @username, @password
|
44
42
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
|
45
43
|
http.request(request)
|
@@ -51,7 +49,6 @@ module Danger
|
|
51
49
|
# HTTP 4xx - 5xx
|
52
50
|
abort "\nError deleting report from Code Insights API: #{response.code} (#{response.message}) - #{response.body}\n\n"
|
53
51
|
end
|
54
|
-
|
55
52
|
end
|
56
53
|
|
57
54
|
def send_report(commit, inline_warnings, inline_errors, inline_messages)
|
@@ -65,15 +62,14 @@ module Danger
|
|
65
62
|
|
66
63
|
def put_report(commit, inline_errors_count)
|
67
64
|
uri = URI(report_endpoint_at_commit(commit))
|
68
|
-
request = Net::HTTP::Put.new(uri.request_uri, {"Content-Type" => "application/json"})
|
65
|
+
request = Net::HTTP::Put.new(uri.request_uri, { "Content-Type" => "application/json" })
|
69
66
|
request.basic_auth @username, @password
|
70
|
-
request.body = {"title": @report_title,
|
67
|
+
request.body = { "title": @report_title,
|
71
68
|
"details": @report_description,
|
72
|
-
"result":
|
69
|
+
"result": inline_errors_count > 0 ? "FAIL" : "PASS",
|
73
70
|
"reporter": @username,
|
74
71
|
"link": "https://github.com/danger/danger",
|
75
|
-
"logoURL": @logo_url
|
76
|
-
}.to_json
|
72
|
+
"logoURL": @logo_url }.to_json
|
77
73
|
|
78
74
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
|
79
75
|
http.request(request)
|
@@ -104,8 +100,8 @@ module Danger
|
|
104
100
|
annotations << violation_hash_with_severity(violation, "HIGH")
|
105
101
|
end
|
106
102
|
|
107
|
-
body = {annotations: annotations}.to_json
|
108
|
-
request = Net::HTTP::Post.new(uri.request_uri, {"Content-Type" => "application/json"})
|
103
|
+
body = { annotations: annotations }.to_json
|
104
|
+
request = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
|
109
105
|
request.basic_auth @username, @password
|
110
106
|
request.body = body
|
111
107
|
|
@@ -141,7 +137,6 @@ module Danger
|
|
141
137
|
def use_ssl
|
142
138
|
@host.include? "https://"
|
143
139
|
end
|
144
|
-
|
145
140
|
end
|
146
141
|
end
|
147
142
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
# rubocop:disable Metrics/ClassLength
|
4
2
|
|
5
3
|
require "octokit"
|
@@ -14,7 +12,7 @@ module Danger
|
|
14
12
|
class GitHub < RequestSource
|
15
13
|
include Danger::Helpers::CommentsHelper
|
16
14
|
|
17
|
-
attr_accessor :pr_json, :issue_json, :support_tokenless_auth, :dismiss_out_of_range_messages
|
15
|
+
attr_accessor :pr_json, :issue_json, :use_local_git, :support_tokenless_auth, :dismiss_out_of_range_messages, :host, :api_url, :verify_ssl
|
18
16
|
|
19
17
|
def self.env_vars
|
20
18
|
["DANGER_GITHUB_API_TOKEN", "DANGER_GITHUB_BEARER_TOKEN"]
|
@@ -26,12 +24,22 @@ module Danger
|
|
26
24
|
|
27
25
|
def initialize(ci_source, environment)
|
28
26
|
self.ci_source = ci_source
|
29
|
-
self.
|
27
|
+
self.use_local_git = environment["DANGER_USE_LOCAL_GIT"]
|
30
28
|
self.support_tokenless_auth = false
|
31
29
|
self.dismiss_out_of_range_messages = false
|
30
|
+
self.host = environment.fetch("DANGER_GITHUB_HOST", "github.com")
|
31
|
+
# `DANGER_GITHUB_API_HOST` is the old name kept for legacy reasons and
|
32
|
+
# backwards compatibility. `DANGER_GITHUB_API_BASE_URL` is the new
|
33
|
+
# correctly named variable.
|
34
|
+
self.api_url = environment.fetch("DANGER_GITHUB_API_HOST") do
|
35
|
+
environment.fetch("DANGER_GITHUB_API_BASE_URL") do
|
36
|
+
"https://api.github.com/".freeze
|
37
|
+
end
|
38
|
+
end
|
39
|
+
self.verify_ssl = environment["DANGER_OCTOKIT_VERIFY_SSL"] != "false"
|
32
40
|
|
33
|
-
@access_token =
|
34
|
-
@bearer_token =
|
41
|
+
@access_token = environment["DANGER_GITHUB_API_TOKEN"]
|
42
|
+
@bearer_token = environment["DANGER_GITHUB_BEARER_TOKEN"]
|
35
43
|
end
|
36
44
|
|
37
45
|
def get_pr_from_branch(repo_name, branch_name, owner)
|
@@ -46,34 +54,16 @@ module Danger
|
|
46
54
|
end
|
47
55
|
|
48
56
|
def validates_as_api_source?
|
49
|
-
valid_bearer_token? || valid_access_token? ||
|
57
|
+
valid_bearer_token? || valid_access_token? || use_local_git
|
50
58
|
end
|
51
59
|
|
52
60
|
def scm
|
53
61
|
@scm ||= GitRepo.new
|
54
62
|
end
|
55
63
|
|
56
|
-
def host
|
57
|
-
@host = @environment["DANGER_GITHUB_HOST"] || "github.com"
|
58
|
-
end
|
59
|
-
|
60
|
-
def verify_ssl
|
61
|
-
@environment["DANGER_OCTOKIT_VERIFY_SSL"] == "false" ? false : true
|
62
|
-
end
|
63
|
-
|
64
|
-
# `DANGER_GITHUB_API_HOST` is the old name kept for legacy reasons and
|
65
|
-
# backwards compatibility. `DANGER_GITHUB_API_BASE_URL` is the new
|
66
|
-
# correctly named variable.
|
67
|
-
def api_url
|
68
|
-
@environment.fetch("DANGER_GITHUB_API_HOST") do
|
69
|
-
@environment.fetch("DANGER_GITHUB_API_BASE_URL") do
|
70
|
-
"https://api.github.com/".freeze
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
64
|
def client
|
76
65
|
raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN` or `DANGER_GITHUB_BEARER_TOKEN`" if !valid_access_token? && !valid_bearer_token? && !support_tokenless_auth
|
66
|
+
|
77
67
|
@client ||= begin
|
78
68
|
Octokit.configure do |config|
|
79
69
|
config.connection_options[:ssl] = { verify: verify_ssl }
|
@@ -92,6 +82,7 @@ module Danger
|
|
92
82
|
|
93
83
|
def review
|
94
84
|
return @review unless @review.nil?
|
85
|
+
|
95
86
|
begin
|
96
87
|
@review = client.pull_request_reviews(ci_source.repo_slug, ci_source.pull_request_id)
|
97
88
|
.map { |review_json| Danger::RequestSources::GitHubSource::Review.new(client, ci_source, review_json) }
|
@@ -142,10 +133,8 @@ module Danger
|
|
142
133
|
end
|
143
134
|
|
144
135
|
def issue_comments
|
145
|
-
@comments ||=
|
146
|
-
|
147
|
-
.map { |comment| Comment.from_github(comment) }
|
148
|
-
end
|
136
|
+
@comments ||= client.issue_comments(ci_source.repo_slug, ci_source.pull_request_id)
|
137
|
+
.map { |comment| Comment.from_github(comment) }
|
149
138
|
end
|
150
139
|
|
151
140
|
# Sending data to GitHub
|
@@ -233,7 +222,7 @@ module Danger
|
|
233
222
|
context: "danger/#{danger_id}",
|
234
223
|
target_url: details_url
|
235
224
|
})
|
236
|
-
rescue
|
225
|
+
rescue StandardError
|
237
226
|
# This usually means the user has no commit access to this repo
|
238
227
|
# That's always the case for open source projects where you can only
|
239
228
|
# use a read-only GitHub account
|
@@ -257,6 +246,7 @@ module Danger
|
|
257
246
|
issue_comments.each do |comment|
|
258
247
|
next unless comment.generated_by_danger?(danger_id)
|
259
248
|
next if comment.id == except
|
249
|
+
|
260
250
|
client.delete_comment(ci_source.repo_slug, comment.id)
|
261
251
|
end
|
262
252
|
end
|
@@ -465,9 +455,9 @@ module Danger
|
|
465
455
|
|
466
456
|
# @return [String] The organisation name, is nil if it can't be detected
|
467
457
|
def organisation
|
468
|
-
matched = self.issue_json["repository_url"].match(%r{repos
|
458
|
+
matched = self.issue_json["repository_url"].match(%r{repos/(.*)/})
|
469
459
|
return matched[1] if matched && matched[1]
|
470
|
-
rescue
|
460
|
+
rescue StandardError
|
471
461
|
nil
|
472
462
|
end
|
473
463
|
|
@@ -482,17 +472,18 @@ module Danger
|
|
482
472
|
end
|
483
473
|
|
484
474
|
# @return [String] A URL to the specific file, ready to be downloaded
|
485
|
-
def file_url(organisation: nil, repository: nil, branch: nil, path: nil)
|
475
|
+
def file_url(organisation: nil, repository: nil, ref: nil, branch: nil, path: nil)
|
486
476
|
organisation ||= self.organisation
|
477
|
+
ref ||= branch
|
487
478
|
|
488
479
|
begin
|
489
|
-
# Retrieve the download URL (default
|
490
|
-
contents = client.contents("#{organisation}/#{repository}", path: path, ref:
|
480
|
+
# Retrieve the download URL (default ref on nil param)
|
481
|
+
contents = client.contents("#{organisation}/#{repository}", path: path, ref: ref)
|
491
482
|
@download_url = contents["download_url"]
|
492
483
|
rescue Octokit::ClientError
|
493
484
|
# Fallback to github.com
|
494
|
-
|
495
|
-
@download_url = "https://raw.githubusercontent.com/#{organisation}/#{repository}/#{
|
485
|
+
ref ||= "master"
|
486
|
+
@download_url = "https://raw.githubusercontent.com/#{organisation}/#{repository}/#{ref}/#{path}"
|
496
487
|
end
|
497
488
|
end
|
498
489
|
|
@@ -521,6 +512,7 @@ module Danger
|
|
521
512
|
next 1 unless b.file && b.line
|
522
513
|
|
523
514
|
next a.line <=> b.line if a.file == b.file
|
515
|
+
|
524
516
|
next a.file <=> b.file
|
525
517
|
end
|
526
518
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require "octokit"
|
4
2
|
require "danger/ci_source/ci_source"
|
5
3
|
require "danger/request_sources/github/github_review_resolver"
|
@@ -35,16 +33,19 @@ module Danger
|
|
35
33
|
|
36
34
|
def id
|
37
35
|
return nil unless self.review_json
|
36
|
+
|
38
37
|
self.review_json["id"]
|
39
38
|
end
|
40
39
|
|
41
40
|
def body
|
42
41
|
return "" unless self.review_json
|
42
|
+
|
43
43
|
self.review_json["body"]
|
44
44
|
end
|
45
45
|
|
46
46
|
def status
|
47
47
|
return STATUS_PENDING if self.review_json.nil?
|
48
|
+
|
48
49
|
return self.review_json["state"]
|
49
50
|
end
|
50
51
|
|