danger 8.4.0 → 8.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffff51d2ba87391b59163fab3e28e65c45c6bd4bbdcd00055aaebbe00e409937
4
- data.tar.gz: 03da4383110a4a4342e007da66df17de7fc658a5b0490e669c969f5d92827cb5
3
+ metadata.gz: bcdadafd7f8d81e366907b31b4c0530258864a6f18aa22e801d4467bc1ab35b0
4
+ data.tar.gz: 1b4e340420a10006b36a55bdbc30570f664c6c88fc2b8ad253f299e1aae30bd5
5
5
  SHA512:
6
- metadata.gz: bee965c2c6bd5eebc756894c1eb6cfbb750c2b9a50e4b81f54af83fc2ac8916d4b76c49b98a95153c2f9e6a4447a4943ca195f4d3d555fde098d93cd3fb3899d
7
- data.tar.gz: dec6c9a3b90fbc27d6389795d1836ea1b4d2c25428dd4b467f18879b550158754195fc068ce90ab400f9e8865033efa175d89629196d8572a405bafedf8ce5b4
6
+ metadata.gz: 8e5f2b3a004f5f205a672ddcef8bc6fc565e3b8d2ef20a14d4f3b9aca06a8d9f069e16e1369a63b14ad226c9f8f1b89b46fe7aa43b02be34d7da574245c7db55
7
+ data.tar.gz: 2e5d5bdf35c5425e2c4012002f191df212d2cbc00a73e63eaa5012ab32340a60b3b39df7c9b1527ef70641c739232a4620545e9c478548f6a628ad993366aebd
data/README.md CHANGED
@@ -76,7 +76,7 @@ I'd strongly recommend using `bundle exec guard` to run your tests as you work.
76
76
 
77
77
  #### Debugging
78
78
 
79
- Ruby is super dynamic. One of the best ways to debug Ruby code is by using [pry](http://pryrepl.org/). We include pry for developers: when you have a problem, copy these two lines just before your problem and follow the instructions from "[I Want To Be A Danger Wizard](https://danger.systems/guides/troubleshooting.html#i-want-to-be-a-danger-wizard)."
79
+ Ruby is super dynamic. One of the best ways to debug Ruby code is by using [pry](https://pry.github.io/). We include pry for developers: when you have a problem, copy these two lines just before your problem and follow the instructions from "[I Want To Be A Danger Wizard](https://danger.systems/guides/troubleshooting.html#i-want-to-be-a-danger-wizard)."
80
80
 
81
81
  ```ruby
82
82
  require 'pry'
@@ -45,7 +45,7 @@ module Danger
45
45
  end
46
46
 
47
47
  def supported_request_sources
48
- @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]
48
+ @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab, Danger::RequestSources::BitbucketServer]
49
49
  end
50
50
  end
51
51
  end
@@ -66,9 +66,17 @@ module Danger
66
66
  merge_request.nil? ? 0 : merge_request.iid
67
67
  end
68
68
 
69
+ def self.slug_from(env)
70
+ if env["DANGER_PROJECT_REPO_URL"]
71
+ env["DANGER_PROJECT_REPO_URL"].split('/').last(2).join('/')
72
+ else
73
+ env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
74
+ end
75
+ end
76
+
69
77
  def initialize(env)
70
- @env = env
71
- @repo_slug = slug_from(env)
78
+ self.repo_slug = self.class.slug_from(env)
79
+ self.pull_request_id = self.class.determine_pull_or_merge_request_id(env)
72
80
  end
73
81
 
74
82
  def supported_request_sources
@@ -77,19 +85,5 @@ module Danger
77
85
  Danger::RequestSources::GitLab
78
86
  ]
79
87
  end
80
-
81
- def pull_request_id
82
- @pull_request_id ||= self.class.determine_pull_or_merge_request_id(@env)
83
- end
84
-
85
- private
86
-
87
- def slug_from(env)
88
- if env["DANGER_PROJECT_REPO_URL"]
89
- env["DANGER_PROJECT_REPO_URL"].split('/').last(2).join('/')
90
- else
91
- env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
92
- end
93
- end
94
88
  end
95
89
  end
@@ -137,7 +137,7 @@ module Danger
137
137
 
138
138
  def client
139
139
  scm_provider = find_scm_provider(remote_url)
140
-
140
+
141
141
  case scm_provider
142
142
  when :bitbucket_cloud
143
143
  require "danger/request_sources/bitbucket_cloud_api"
@@ -151,8 +151,15 @@ module Danger
151
151
 
152
152
  when :github
153
153
  require "octokit"
154
- Octokit::Client.new(access_token: ENV["DANGER_GITHUB_API_TOKEN"], api_endpoint: api_url)
155
-
154
+ access_token = ENV["DANGER_GITHUB_API_TOKEN"]
155
+ bearer_token = ENV["DANGER_GITHUB_BEARER_TOKEN"]
156
+ if bearer_token && !bearer_token.empty?
157
+ Octokit::Client.new(bearer_token: bearer_token, api_endpoint: api_url)
158
+ elsif access_token && !access_token.empty?
159
+ Octokit::Client.new(access_token: access_token, api_endpoint: api_url)
160
+ else
161
+ raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN` or `DANGER_GITHUB_BEARER_TOKEN`"
162
+ end
156
163
  else
157
164
  raise "SCM provider not supported: #{scm_provider}"
158
165
  end
@@ -148,7 +148,7 @@ module Danger
148
148
  # @return [Boolean]
149
149
  #
150
150
  def pr_draft?
151
- pr_json["mergeable_state"] == "draft"
151
+ pr_json["draft"] == true
152
152
  end
153
153
 
154
154
  # @!group PR Commit Metadata
@@ -19,8 +19,8 @@ module Danger
19
19
  respond_to_method(name, *args, &block)
20
20
  end
21
21
 
22
- def respond_to_missing?(name)
23
- __array__.respond_to?(name) || super
22
+ def respond_to_missing?(name, include_all)
23
+ __array__.respond_to?(name, include_all) || super
24
24
  end
25
25
 
26
26
  def to_a
@@ -10,7 +10,7 @@ module Danger
10
10
  "bitbucket_server" => {
11
11
  "no_entry_sign" => ":no_entry_sign:",
12
12
  "warning" => ":warning:",
13
- "book" => ":book:",
13
+ "book" => ":blue_book:",
14
14
  "white_check_mark" => ":white_check_mark:"
15
15
  }
16
16
  }.freeze
@@ -20,10 +20,12 @@ module Danger
20
20
  end
21
21
 
22
22
  def self.optional_env_vars
23
- ["DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_KEY",
24
- "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_TITLE",
25
- "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_DESCRIPTION",
26
- "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_LOGO_URL"
23
+ [
24
+ "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_KEY",
25
+ "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_TITLE",
26
+ "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_DESCRIPTION",
27
+ "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_LOGO_URL",
28
+ "DANGER_BITBUCKETSERVER_VERIFY_SSL"
27
29
  ]
28
30
  end
29
31
 
@@ -110,17 +112,20 @@ module Danger
110
112
  markdowns = main_violations[:markdowns] || []
111
113
  end
112
114
 
113
- comment = generate_description(warnings: warnings,
114
- errors: errors)
115
- comment += "\n\n"
116
- comment += generate_comment(warnings: warnings,
117
- errors: errors,
118
- messages: messages,
119
- markdowns: markdowns,
120
- previous_violations: {},
121
- danger_id: danger_id,
122
- template: "bitbucket_server")
123
- @api.post_comment(comment)
115
+ has_comments = (warnings.count > 0 || errors.count > 0 || messages.count > 0 || markdowns.count > 0)
116
+ if has_comments
117
+ comment = generate_description(warnings: warnings,
118
+ errors: errors)
119
+ comment += "\n\n"
120
+ comment += generate_comment(warnings: warnings,
121
+ errors: errors,
122
+ messages: messages,
123
+ markdowns: markdowns,
124
+ previous_violations: {},
125
+ danger_id: danger_id,
126
+ template: "bitbucket_server")
127
+ @api.post_comment(comment)
128
+ end
124
129
  end
125
130
 
126
131
  def delete_old_comments(danger_id: "danger")
@@ -1,16 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
+ require "openssl"
3
4
  require "danger/helpers/comments_helper"
4
5
 
5
6
  module Danger
6
7
  module RequestSources
7
8
  class BitbucketServerAPI
8
- attr_accessor :host, :pr_api_endpoint, :key, :project
9
+ attr_accessor :host, :verify_ssl, :pr_api_endpoint, :key, :project
9
10
 
10
11
  def initialize(project, slug, pull_request_id, environment)
11
12
  @username = environment["DANGER_BITBUCKETSERVER_USERNAME"]
12
13
  @password = environment["DANGER_BITBUCKETSERVER_PASSWORD"]
13
14
  self.host = environment["DANGER_BITBUCKETSERVER_HOST"]
15
+ self.verify_ssl = environment["DANGER_BITBUCKETSERVER_VERIFY_SSL"] == "false" ? false : true
14
16
  if self.host && !(self.host.include? "http://") && !(self.host.include? "https://")
15
17
  self.host = "https://" + self.host
16
18
  end
@@ -57,7 +59,7 @@ module Danger
57
59
  body = { text: text }.to_json
58
60
  post(uri, body)
59
61
  end
60
-
62
+
61
63
  def update_pr_build_status(status, changeset, build_job_link, description)
62
64
  uri = URI("#{self.host}/rest/build-status/1.0/commits/#{changeset}")
63
65
  body = build_status_body(status, build_job_link, description)
@@ -73,7 +75,7 @@ module Danger
73
75
  def fetch_json(uri)
74
76
  req = Net::HTTP::Get.new(uri.request_uri, { "Content-Type" => "application/json" })
75
77
  req.basic_auth @username, @password
76
- res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
78
+ res = http(uri).start do |http|
77
79
  http.request(req)
78
80
  end
79
81
  JSON.parse(res.body, symbolize_names: true)
@@ -84,7 +86,7 @@ module Danger
84
86
  req.basic_auth @username, @password
85
87
  req.body = body
86
88
 
87
- res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
89
+ res = http(uri).start do |http|
88
90
  http.request(req)
89
91
  end
90
92
 
@@ -99,11 +101,18 @@ module Danger
99
101
  def delete(uri)
100
102
  req = Net::HTTP::Delete.new(uri.request_uri, { "Content-Type" => "application/json" })
101
103
  req.basic_auth @username, @password
102
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
104
+ http(uri).start do |http|
103
105
  http.request(req)
104
106
  end
105
107
  end
106
-
108
+
109
+ def http(uri)
110
+ http = Net::HTTP.new(uri.hostname, uri.port)
111
+ http.use_ssl = use_ssl
112
+ http.verify_mode = verify_ssl ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
113
+ http
114
+ end
115
+
107
116
  def build_status_body(status, build_job_link, description)
108
117
  body = Hash.new
109
118
  body["state"] = status
@@ -17,7 +17,7 @@ module Danger
17
17
  attr_accessor :pr_json, :issue_json, :support_tokenless_auth, :dismiss_out_of_range_messages
18
18
 
19
19
  def self.env_vars
20
- ["DANGER_GITHUB_API_TOKEN"]
20
+ ["DANGER_GITHUB_API_TOKEN", "DANGER_GITHUB_BEARER_TOKEN"]
21
21
  end
22
22
 
23
23
  def self.optional_env_vars
@@ -30,7 +30,8 @@ module Danger
30
30
  self.support_tokenless_auth = false
31
31
  self.dismiss_out_of_range_messages = false
32
32
 
33
- @token = @environment["DANGER_GITHUB_API_TOKEN"]
33
+ @access_token = @environment["DANGER_GITHUB_API_TOKEN"]
34
+ @bearer_token = @environment["DANGER_GITHUB_BEARER_TOKEN"]
34
35
  end
35
36
 
36
37
  def get_pr_from_branch(repo_name, branch_name, owner)
@@ -45,7 +46,7 @@ module Danger
45
46
  end
46
47
 
47
48
  def validates_as_api_source?
48
- (@token && !@token.empty?) || self.environment["DANGER_USE_LOCAL_GIT"]
49
+ valid_bearer_token? || valid_access_token? || self.environment["DANGER_USE_LOCAL_GIT"]
49
50
  end
50
51
 
51
52
  def scm
@@ -72,12 +73,16 @@ module Danger
72
73
  end
73
74
 
74
75
  def client
75
- raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN`" if !@token && !support_tokenless_auth
76
+ 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
76
77
  @client ||= begin
77
78
  Octokit.configure do |config|
78
79
  config.connection_options[:ssl] = { verify: verify_ssl }
79
80
  end
80
- Octokit::Client.new(access_token: @token, auto_paginate: true, api_endpoint: api_url)
81
+ if valid_bearer_token?
82
+ Octokit::Client.new(bearer_token: @bearer_token, auto_paginate: true, api_endpoint: api_url)
83
+ elsif valid_access_token?
84
+ Octokit::Client.new(access_token: @access_token, auto_paginate: true, api_endpoint: api_url)
85
+ end
81
86
  end
82
87
  end
83
88
 
@@ -493,6 +498,14 @@ module Danger
493
498
 
494
499
  private
495
500
 
501
+ def valid_access_token?
502
+ @access_token && !@access_token.empty?
503
+ end
504
+
505
+ def valid_bearer_token?
506
+ @bearer_token && !@bearer_token.empty?
507
+ end
508
+
496
509
  def regular_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
497
510
  {
498
511
  warnings: warnings.reject(&:inline?),
@@ -304,6 +304,10 @@ module Danger
304
304
  end
305
305
  end
306
306
 
307
+ def markdown_link_to_message(message, _)
308
+ "#{message.file}#L#{message.line}: "
309
+ end
310
+
307
311
  # @return [String] The organisation name, is nil if it can't be detected
308
312
  def organisation
309
313
  nil # TODO: Implement this
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "8.4.0".freeze
2
+ VERSION = "8.4.3".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: 8.4.0
4
+ version: 8.4.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: 2021-09-29 00:00:00.000000000 Z
12
+ date: 2022-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide