danger 8.2.2 → 8.4.1

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
  SHA256:
3
- metadata.gz: 251a83485fbb01f15fb71afc1e76bed01879d166f6899407c2bee22416fa5ca7
4
- data.tar.gz: 0fbbc7ce20a833a55e2be4b842e4e89d70a130038c0eec0408396892ceba215c
3
+ metadata.gz: bbecb15ac329fa5977840fe99a41c752b85ecec9669542d0f6002b8f3c374031
4
+ data.tar.gz: aa412e3e48efc2fbcac2302b3ce64c960f939c5dbc86a045c5be3d32dfb9df61
5
5
  SHA512:
6
- metadata.gz: 9780c2dfd1a909732b7571c0141e74d35b92cbdcfbcfad48c2b2bc713dc62e062598301b0bca38a6759ef032ea4318a2d04e5b40d8d7fccb441b2f78f4a59862
7
- data.tar.gz: 5f93607907d82ffc36c6f5074796dfdacfd2c6771390e4bda57405c3c0f1f1545506a7f03b95b536fec763313612f24f27f4c20e9b4e4603570e0ab1b7e6f572
6
+ metadata.gz: adfe653dfe86b47a1ee68b08a69f7b35f0e80979fe4f25725290091aa2fa5ede790331a8bce16f09efd4a1f9690c5df03d17e87516ff6ef6c19514a1d2e00044
7
+ data.tar.gz: 23b29baa8b821356398a8802f914019b3327fe2f68285cd1f8bebcef507d2beb0b2ee5259621337d247b4d3c110bc2cd1891dbaf2e9caa3da8e2737250d39499
@@ -19,7 +19,11 @@ module Danger
19
19
  #
20
20
  class AzurePipelines < CI
21
21
  def self.validates_as_ci?(env)
22
- env.key?("AGENT_ID") && env["BUILD_REPOSITORY_PROVIDER"] != "TfsGit"
22
+ # AGENT_ID is being used by AppCenter as well, so checking here to make sure AppCenter CI doesn't get a false positive for AzurePipelines
23
+ # Anyone working with AzurePipelines could provide a better/truly unique env key to avoid checking for AppCenter
24
+ !Danger::Appcenter::validates_as_ci?(env) &&
25
+ env.key?("AGENT_ID") &&
26
+ env["BUILD_REPOSITORY_PROVIDER"] != "TfsGit"
23
27
  end
24
28
 
25
29
  def self.validates_as_pr?(env)
@@ -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
@@ -0,0 +1,58 @@
1
+ # https://docs.codemagic.io/building/environment-variables/
2
+
3
+ module Danger
4
+ # ### CI Setup
5
+ #
6
+ # Add a script step to your workflow:
7
+ #
8
+ # ```
9
+ # - name: Running Danger
10
+ # script: |
11
+ # bundle install
12
+ # bundle exec danger
13
+ # ```
14
+ #
15
+ # ### Token Setup
16
+ #
17
+ # Add the following environment variables to your workflow's environment configuration.
18
+ # https://docs.codemagic.io/getting-started/yaml/
19
+ #
20
+ # #### GitHub
21
+ # Add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV.
22
+ #
23
+ # #### GitLab
24
+ # Add the `DANGER_GITLAB_API_TOKEN` to your build user's ENV.
25
+ #
26
+ # #### Bitbucket Cloud
27
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
28
+ # to your build user's ENV.
29
+ #
30
+ # #### Bitbucket server
31
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
32
+ # and `DANGER_BITBUCKETSERVER_HOST` to your build user's ENV.
33
+ #
34
+ class Codemagic < CI
35
+ def self.validates_as_ci?(env)
36
+ env.key? "FCI_PROJECT_ID"
37
+ end
38
+
39
+ def self.validates_as_pr?(env)
40
+ return !env["FCI_PULL_REQUEST_NUMBER"].to_s.empty?
41
+ end
42
+
43
+ def supported_request_sources
44
+ @supported_request_sources ||= [
45
+ Danger::RequestSources::GitHub,
46
+ Danger::RequestSources::GitLab,
47
+ Danger::RequestSources::BitbucketServer,
48
+ Danger::RequestSources::BitbucketCloud
49
+ ]
50
+ end
51
+
52
+ def initialize(env)
53
+ self.pull_request_id = env["FCI_PULL_REQUEST_NUMBER"]
54
+ self.repo_slug = env["FCI_REPO_SLUG"]
55
+ self.repo_url = GitRepo.new.origins # Codemagic doesn't provide a repo url env variable for n
56
+ end
57
+ end
58
+ end
@@ -46,10 +46,17 @@ module Danger
46
46
  base_commit = env["CI_COMMIT_SHA"]
47
47
  client = RequestSources::GitLab.new(nil, env).client
48
48
 
49
- if (Gem::Version.new(client.version.version) >= Gem::Version.new("10.7"))
49
+ client_version = Gem::Version.new(client.version.version)
50
+ if (client_version >= Gem::Version.new("10.7"))
50
51
  #Use the 'list merge requests associated with a commit' API, for speeed
51
52
  # (GET /projects/:id/repository/commits/:sha/merge_requests) available for GitLab >= 10.7
52
53
  merge_request = client.commit_merge_requests(project_path, base_commit, state: :opened).first
54
+ if (client_version >= Gem::Version.new("13.8"))
55
+ # Gitlab 13.8.0 started returning merge requests for merge commits and squashed commits
56
+ # By checking for merge_request.state, we can ensure danger only comments on MRs which are open
57
+ return 0 if merge_request.nil?
58
+ return 0 unless merge_request.state == "opened"
59
+ end
53
60
  else
54
61
  merge_requests = client.merge_requests(project_path, state: :opened)
55
62
  merge_request = merge_requests.auto_paginate.find do |mr|
@@ -133,7 +133,7 @@ module Danger
133
133
  matches = change_url.match(%r{(.+)\/pull\/[0-9]+})
134
134
  matches[1] unless matches.nil?
135
135
  when %r{\/merge_requests\/} # GitLab
136
- matches = change_url.match(%r{(.+)\/merge_requests\/[0-9]+})
136
+ matches = change_url.match(%r{(.+?)(\/-)?\/merge_requests\/[0-9]+})
137
137
  matches[1] unless matches.nil?
138
138
  when %r{\/pull-requests\/} # Bitbucket
139
139
  matches = change_url.match(%r{(.+)\/pull-requests\/[0-9]+})
@@ -1,17 +1,19 @@
1
- class Commits
2
- def initialize(base_head)
3
- @base_head = base_head.strip.split(" ".freeze)
4
- end
1
+ module Danger
2
+ class Commits
3
+ def initialize(base_head)
4
+ @base_head = base_head.strip.split(" ".freeze)
5
+ end
5
6
 
6
- def base
7
- base_head.first
8
- end
7
+ def base
8
+ base_head.first
9
+ end
9
10
 
10
- def head
11
- base_head.last
12
- end
11
+ def head
12
+ base_head.last
13
+ end
13
14
 
14
- private
15
+ private
15
16
 
16
- attr_reader :base_head
17
+ attr_reader :base_head
18
+ end
17
19
  end
@@ -0,0 +1,38 @@
1
+ module Danger
2
+ # ### CI Setup
3
+ #
4
+ # In order to work with Xcode Cloud and Danger, you will need to add `bundle exec danger` to
5
+ # the `ci_scripts/ci_post_xcodebuild.sh` (Xcode Cloud's expected filename for a post-action build script).
6
+ # More details and documentation on Xcode Cloud configuration can be found [here](https://developer.apple.com/documentation/xcode/writing-custom-build-scripts).
7
+ #
8
+ # ### Token Setup
9
+ #
10
+ # You will need to add the `DANGER_GITHUB_API_TOKEN` to your build environment.
11
+ # If running on GitHub Enterprise, make sure you also set the expected values for
12
+ # both `DANGER_GITHUB_API_HOST` and `DANGER_GITHUB_HOST`.
13
+ #
14
+ class XcodeCloud < CI
15
+ def self.validates_as_ci?(env)
16
+ env.key? "CI_XCODEBUILD_ACTION"
17
+ end
18
+
19
+ def self.validates_as_pr?(env)
20
+ env.key? "CI_PULL_REQUEST_NUMBER"
21
+ end
22
+
23
+ def supported_request_sources
24
+ @supported_request_sources ||= [
25
+ Danger::RequestSources::GitHub,
26
+ Danger::RequestSources::GitLab,
27
+ Danger::RequestSources::BitbucketCloud,
28
+ Danger::RequestSources::BitbucketServer
29
+ ]
30
+ end
31
+
32
+ def initialize(env)
33
+ self.repo_slug = env["CI_PULL_REQUEST_SOURCE_REPO"]
34
+ self.pull_request_id = env["CI_PULL_REQUEST_NUMBER"]
35
+ self.repo_url = env["CI_PULL_REQUEST_HTML_URL"]
36
+ end
37
+ end
38
+ end
@@ -4,7 +4,7 @@ require "danger/danger_core/dangerfile_generator"
4
4
 
5
5
  module Danger
6
6
  class DangerfileCommand < Runner
7
- self.summary = "Easily create you Dangerfiles."
7
+ self.summary = "Easily create your Dangerfiles."
8
8
  self.command = "dangerfile"
9
9
 
10
10
  self.abstract_command = true
@@ -17,10 +17,5 @@
17
17
  <%= current %>
18
18
  <%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
19
19
  <%- end -%>
20
- <%# We need to add the generated_by_ to identify comments from danger. But with inlines %>
21
- <%# it might be a little annoying, so we set on the table, but if we have markdown we add the footer anyway %>
22
- <%- if @markdowns.count > 0 -%>
23
- <p align="right" data-meta="generated_by_<%= @danger_id %>">
24
- Generated by :no_entry_sign: <a href="http://danger.systems/">Danger</a>
25
- </p>
26
- <%- end -%>
20
+ <%# Add the generated_by_ as a html coment to identify comments from danger. %>
21
+ <!-- "generated_by_<%= @danger_id %>" -->
@@ -143,6 +143,14 @@ module Danger
143
143
  @github.issue_json["labels"].map { |l| l[:name] }
144
144
  end
145
145
 
146
+ # @!group PR Metadata
147
+ # Whether the PR is a Draft.
148
+ # @return [Boolean]
149
+ #
150
+ def pr_draft?
151
+ pr_json["mergeable_state"] == "draft"
152
+ end
153
+
146
154
  # @!group PR Commit Metadata
147
155
  # The branch to which the PR is going to be merged into.
148
156
  # @return [String]
@@ -131,6 +131,22 @@ module Danger
131
131
  @gitlab.mr_diff
132
132
  end
133
133
 
134
+ # @!group MR Changes
135
+ # The array of changes
136
+ # @return [Array<Gitlab::ObjectifiedHash>]
137
+ #
138
+ def mr_changes
139
+ @gitlab.mr_changes.changes
140
+ end
141
+
142
+ # @!group MR Closes issues
143
+ # The array of issues that this MR closes
144
+ # @return [Array<Gitlab::ObjectifiedHash>]
145
+ #
146
+ def mr_closes_issues
147
+ @gitlab.mr_closes_issues
148
+ end
149
+
134
150
  # @!group MR Commit Metadata
135
151
  # The branch to which the MR is going to be merged into
136
152
  # @deprecated Please use {#branch_for_base} instead
@@ -148,7 +148,7 @@ module Danger
148
148
  def generate_description(warnings: nil, errors: nil, template: "github")
149
149
  emoji_mapper = EmojiMapper.new(template)
150
150
  if errors.empty? && warnings.empty?
151
- return "All green. #{random_compliment}"
151
+ return ENV['DANGER_SUCCESS_MESSAGE'] || "All green. #{random_compliment}"
152
152
  else
153
153
  message = "#{emoji_mapper.map('warning')} "
154
154
  message += "#{'Error'.danger_pluralize(errors.count)}. " unless errors.empty?
@@ -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
@@ -130,6 +130,12 @@ module Danger
130
130
  end
131
131
  end
132
132
 
133
+ def mr_closes_issues
134
+ @mr_closes_issues ||= begin
135
+ client.merge_request_closes_issues(ci_source.repo_slug, ci_source.pull_request_id)
136
+ end
137
+ end
138
+
133
139
  def setup_danger_branches
134
140
  # we can use a GitLab specific feature here:
135
141
  base_branch = self.mr_json.source_branch
@@ -298,6 +304,10 @@ module Danger
298
304
  end
299
305
  end
300
306
 
307
+ def markdown_link_to_message(message, _)
308
+ "#{message.file}#L#{message.line}: "
309
+ end
310
+
301
311
  # @return [String] The organisation name, is nil if it can't be detected
302
312
  def organisation
303
313
  nil # TODO: Implement this
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "8.2.2".freeze
2
+ VERSION = "8.4.1".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.2.2
4
+ version: 8.4.1
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-01-19 00:00:00.000000000 Z
12
+ date: 2021-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -147,16 +147,22 @@ dependencies:
147
147
  name: terminal-table
148
148
  requirement: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '1'
153
+ - - "<"
154
+ - !ruby/object:Gem::Version
155
+ version: '4'
153
156
  type: :runtime
154
157
  prerelease: false
155
158
  version_requirements: !ruby/object:Gem::Requirement
156
159
  requirements:
157
- - - "~>"
160
+ - - ">="
158
161
  - !ruby/object:Gem::Version
159
162
  version: '1'
163
+ - - "<"
164
+ - !ruby/object:Gem::Version
165
+ version: '4'
160
166
  - !ruby/object:Gem::Dependency
161
167
  name: cork
162
168
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +219,7 @@ files:
213
219
  - lib/danger/ci_source/cirrus.rb
214
220
  - lib/danger/ci_source/code_build.rb
215
221
  - lib/danger/ci_source/codefresh.rb
222
+ - lib/danger/ci_source/codemagic.rb
216
223
  - lib/danger/ci_source/codeship.rb
217
224
  - lib/danger/ci_source/concourse.rb
218
225
  - lib/danger/ci_source/dotci.rb
@@ -237,6 +244,7 @@ files:
237
244
  - lib/danger/ci_source/teamcity.rb
238
245
  - lib/danger/ci_source/travis.rb
239
246
  - lib/danger/ci_source/vsts.rb
247
+ - lib/danger/ci_source/xcode_cloud.rb
240
248
  - lib/danger/ci_source/xcode_server.rb
241
249
  - lib/danger/clients/rubygems_client.rb
242
250
  - lib/danger/commands/dangerfile/gem.rb