danger 8.2.1 → 8.4.0

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: 3930680bc519ec86948df5375ea6ffad444929619c7faf3190e204eee827767b
4
- data.tar.gz: 6ca8c826a895e9d0ef6bf66343e70110026a8a77fafddc6e72f26b129c37801d
3
+ metadata.gz: ffff51d2ba87391b59163fab3e28e65c45c6bd4bbdcd00055aaebbe00e409937
4
+ data.tar.gz: 03da4383110a4a4342e007da66df17de7fc658a5b0490e669c969f5d92827cb5
5
5
  SHA512:
6
- metadata.gz: '0267983777b8a27f5d90f6221655d18657a0c4ed6276e475631e4984eabbe2f5329ec8df774100052dfd1e6368082b9865fd1bd87956b538fa032042f1e1538d'
7
- data.tar.gz: 700097f2571dd5cb9cac5b9f74d034a53a00e73f747d3aa489cb9cae83b86b85908281a3c910bec25a2299fd828449c9eb82f796d8865f84a0742a46488d2dd3
6
+ metadata.gz: bee965c2c6bd5eebc756894c1eb6cfbb750c2b9a50e4b81f54af83fc2ac8916d4b76c49b98a95153c2f9e6a4447a4943ca195f4d3d555fde098d93cd3fb3899d
7
+ data.tar.gz: dec6c9a3b90fbc27d6389795d1836ea1b4d2c25428dd4b467f18879b550158754195fc068ce90ab400f9e8865033efa175d89629196d8572a405bafedf8ce5b4
@@ -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"
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)
@@ -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 %>" -->
@@ -49,22 +49,26 @@ module Danger
49
49
  # However, as we're using using them in the DSL, they won't
50
50
  # get method_missing called correctly without overriding them.
51
51
 
52
- def warn(*args, &blk)
53
- method_missing(:warn, *args, &blk)
52
+ def warn(*args, **kargs, &blk)
53
+ method_missing(:warn, *args, **kargs, &blk)
54
54
  end
55
55
 
56
- def fail(*args, &blk)
57
- method_missing(:fail, *args, &blk)
56
+ def fail(*args, **kargs, &blk)
57
+ method_missing(:fail, *args, **kargs, &blk)
58
58
  end
59
59
 
60
60
  # When an undefined method is called, we check to see if it's something
61
61
  # that the core DSLs have, then starts looking at plugins support.
62
62
 
63
63
  # rubocop:disable Style/MethodMissing
64
- def method_missing(method_sym, *arguments, &_block)
64
+ def method_missing(method_sym, *arguments, **keyword_arguments, &_block)
65
65
  @core_plugins.each do |plugin|
66
66
  if plugin.public_methods(false).include?(method_sym)
67
- return plugin.send(method_sym, *arguments)
67
+ if keyword_arguments.empty?
68
+ return plugin.send(method_sym, *arguments)
69
+ else
70
+ return plugin.send(method_sym, *arguments, **keyword_arguments)
71
+ end
68
72
  end
69
73
  end
70
74
  super
@@ -90,6 +90,8 @@ module Danger
90
90
  RequestSources::GitLab
91
91
  elsif repo_url =~ /bitbucket\.(org|com)/i
92
92
  RequestSources::BitbucketCloud
93
+ elsif repo_url =~ /dev\.azure\.com/i
94
+ RequestSources::VSTS
93
95
  end
94
96
  end
95
97
 
@@ -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?
@@ -19,8 +19,12 @@ module Danger
19
19
  # We need to redirect the self calls to the Dangerfile
20
20
 
21
21
  # rubocop:disable Style/MethodMissing
22
- def method_missing(method_sym, *arguments, &block)
23
- @dangerfile.send(method_sym, *arguments, &block)
22
+ def method_missing(method_sym, *arguments, **keyword_arguments, &block)
23
+ if keyword_arguments.empty?
24
+ @dangerfile.send(method_sym, *arguments, &block)
25
+ else
26
+ @dangerfile.send(method_sym, *arguments, **keyword_arguments, &block)
27
+ end
24
28
  end
25
29
 
26
30
  def self.all_plugins
@@ -95,12 +95,13 @@ module Danger
95
95
  "#{base_url(2)}/#{pull_request_id}"
96
96
  end
97
97
 
98
- def prs_api_endpoint(branch_name)
99
- "#{base_url(2)}?q=source.branch.name=\"#{branch_name}\""
98
+ def prs_api_url(branch_name)
99
+ encoded_branch_name = URI.encode_www_form_component(branch_name)
100
+ "#{base_url(2)}?q=source.branch.name=\"#{encoded_branch_name}\""
100
101
  end
101
102
 
102
103
  def fetch_pr_from_branch(branch_name)
103
- uri = URI(URI.escape(prs_api_endpoint(branch_name)))
104
+ uri = URI(prs_api_url(branch_name))
104
105
  fetch_json(uri)[:values][0][:id]
105
106
  end
106
107
 
@@ -85,7 +85,7 @@ module Danger
85
85
  if supports_inline_comments
86
86
  @raw_comments = mr_discussions
87
87
  .auto_paginate
88
- .flat_map { |discussion| discussion.notes.map { |note| note.merge({"discussion_id" => discussion.id}) } }
88
+ .flat_map { |discussion| discussion.notes.map { |note| note.to_h.merge({"discussion_id" => discussion.id}) } }
89
89
  @raw_comments
90
90
  .map { |comment| Comment.from_gitlab(comment) }
91
91
  else
@@ -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
@@ -359,7 +365,7 @@ module Danger
359
365
  def submit_inline_comments!(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: [], danger_id: "danger")
360
366
  comments = mr_discussions
361
367
  .auto_paginate
362
- .flat_map { |discussion| discussion.notes.map { |note| note.merge({"discussion_id" => discussion.id}) } }
368
+ .flat_map { |discussion| discussion.notes.map { |note| note.to_h.merge({"discussion_id" => discussion.id}) } }
363
369
  .select { |comment| Comment.from_gitlab(comment).inline? }
364
370
 
365
371
  danger_comments = comments.select { |comment| Comment.from_gitlab(comment).generated_by_danger?(danger_id) }
@@ -410,7 +416,7 @@ module Danger
410
416
  next false unless m.file && m.line
411
417
  # Reject if it's out of range and in dismiss mode
412
418
  next true if dismiss_out_of_range_messages_for(kind) && is_out_of_range(mr_changes.changes, m)
413
-
419
+
414
420
  # Once we know we're gonna submit it, we format it
415
421
  if is_markdown_content
416
422
  body = generate_inline_markdown_body(m, danger_id: danger_id, template: "gitlab")
@@ -531,10 +537,10 @@ module Danger
531
537
  end
532
538
 
533
539
  def is_out_of_range(changes, message)
534
- change = changes.find { |c| c["new_path"] == message.file }
540
+ change = changes.find { |c| c["new_path"] == message.file }
535
541
  # If there is no changes or rename only or deleted, return out of range.
536
542
  return true if change.nil? || change["diff"].empty? || change["deleted_file"]
537
-
543
+
538
544
  # If new file then return in range
539
545
  return false if change["new_file"]
540
546
 
@@ -544,7 +550,7 @@ module Danger
544
550
  return true
545
551
  end
546
552
 
547
- def generate_addition_lines(diff)
553
+ def generate_addition_lines(diff)
548
554
  range_header_regexp = /@@ -(?<old>[0-9]+)(,([0-9]+))? \+(?<new>[0-9]+)(,([0-9]+))? @@.*/
549
555
  addition_lines = []
550
556
  line_number = 0
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "8.2.1".freeze
2
+ VERSION = "8.4.0".freeze
3
3
  DESCRIPTION = "Like Unit Tests, but for your Team Culture.".freeze
4
4
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.2.1
4
+ version: 8.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
8
8
  - Juanito Fatas
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-09 00:00:00.000000000 Z
12
+ date: 2021-09-29 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
@@ -319,7 +327,7 @@ homepage: https://github.com/danger/danger
319
327
  licenses:
320
328
  - MIT
321
329
  metadata: {}
322
- post_install_message:
330
+ post_install_message:
323
331
  rdoc_options: []
324
332
  require_paths:
325
333
  - lib
@@ -334,8 +342,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
334
342
  - !ruby/object:Gem::Version
335
343
  version: '0'
336
344
  requirements: []
337
- rubygems_version: 3.1.2
338
- signing_key:
345
+ rubygems_version: 3.1.4
346
+ signing_key:
339
347
  specification_version: 4
340
348
  summary: Like Unit Tests, but for your Team Culture.
341
349
  test_files: []