danger 8.6.1 → 9.1.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: 691f7a26ea0a29f107e6f848bdf7450d2043dc15f5c385c136c1a9d818120c3f
4
- data.tar.gz: d5f84a85ec8419dbbfbdcb742ffb15b5fe075d3bf1f676859152a0bb7b466633
3
+ metadata.gz: 8fc4bd35f1d805c6e3ef5b0467cd59281f0251c10b0580ebb138002e3b370e62
4
+ data.tar.gz: 29df2722f598ead34bee294304b60b3f6343c6147cce87054772aac2b40f1f2b
5
5
  SHA512:
6
- metadata.gz: b712f8566113397b952ebd93e33d1d42b38d1b1a9d04e678971c35feb46a5bfb057236b0ccffc250560df6b1da001fe31f848024de318850c93ecb6af6eb0994
7
- data.tar.gz: c89ab31d3afe5d668046629643d65858d6eeeea3d5f67006170af38e9a8c31673789de472501d37ff923c41fb538193cce767ae9567ef4a9a474aca96cf4aad4
6
+ metadata.gz: 304581c49ae31baa62f135883e006536e993a824a6cea8a920a37d58b232ea3118eccf773ffc760281c8a49b70446b51b955c952379e9d41e12e9d9e9842a4d7
7
+ data.tar.gz: d68b392bcb4075b852cc988fdaa3e9e2fd3df080417dd31d1cb314bf9ec1a4f3af5fdf759f7f106e5071b60e48ae4affb78750ae58a43ecadb94d533d9e80d83
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019-present Orta, Felix Krause
3
+ Copyright (c) 2015-present Orta, Felix Krause
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,83 @@
1
+ # https://docs.appcircle.io/environment-variables/managing-variables
2
+ # https://docs.appcircle.io/build/build-profile-configuration#environment-variables-configuration
3
+ require "danger/request_sources/github/github"
4
+ require "danger/request_sources/gitlab"
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # Add a Custom Script step to your workflow and set it as a bash:
9
+ #
10
+ # ```shell
11
+ # cd $AC_REPOSITORY_DIR
12
+ # bundle install
13
+ # bundle exec danger
14
+ # ```
15
+ # ### Token Setup
16
+ #
17
+ # Login to Appcircle and select your build profile. Go to your *Config* and
18
+ # choose *Environment Variables*.
19
+ # https://docs.appcircle.io/environment-variables/managing-variables
20
+ #
21
+ # #### GitHub
22
+ # Add the `DANGER_GITHUB_API_TOKEN` to your profile's ENV.
23
+ #
24
+ # #### GitLab
25
+ # Add the `DANGER_GITLAB_API_TOKEN` to your profile's ENV.
26
+ #
27
+ # #### Bitbucket Cloud
28
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
29
+ # to your profile's ENV.
30
+ #
31
+ # #### Bitbucket server
32
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
33
+ # and `DANGER_BITBUCKETSERVER_HOST` to your profile's ENV.
34
+ #
35
+ class Appcircle < CI
36
+ def self.validates_as_ci?(env)
37
+ env.key? "AC_APPCIRCLE"
38
+ end
39
+
40
+ def self.validates_as_pr?(env)
41
+ return false unless env.key? "AC_PULL_NUMBER"
42
+ env["AC_PULL_NUMBER"].to_i > 0
43
+ end
44
+
45
+ def supported_request_sources
46
+ @supported_request_sources ||= [
47
+ Danger::RequestSources::GitHub,
48
+ Danger::RequestSources::BitbucketCloud,
49
+ Danger::RequestSources::BitbucketServer,
50
+ Danger::RequestSources::GitLab
51
+ ]
52
+ end
53
+
54
+ def initialize(env)
55
+ self.pull_request_id = env["AC_PULL_NUMBER"]
56
+ self.repo_url = env["AC_GIT_URL"]
57
+ self.repo_slug = repo_slug_from(self.repo_url)
58
+ end
59
+
60
+ def repo_slug_from(url)
61
+ if url =~ URI::regexp
62
+ # Try to parse the URL as a valid URI. This should cover the cases of http/https/ssh URLs.
63
+ begin
64
+ uri = URI.parse(url)
65
+ return uri.path.sub(/^(\/)/,'').sub(/(.git)$/,'')
66
+ rescue URI::InvalidURIError
67
+ # In case URL could not be parsed fallback to git URL parsing.
68
+ repo_slug_asgiturl(url)
69
+ end
70
+ else
71
+ # In case URL could not be parsed fallback to git URL parsing. git@github.com:organization/repo.git
72
+ repo_slug_asgiturl(url)
73
+ end
74
+ end
75
+
76
+ def repo_slug_asgiturl(url)
77
+ matcher_url = url
78
+ repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
79
+ return repo_matches unless repo_matches.nil?
80
+ end
81
+ end
82
+ end
83
+
@@ -19,13 +19,13 @@ module Danger
19
19
  #
20
20
  # Add the `DANGER_GITHUB_API_TOKEN` to your workflow's [Secret App Env Vars](https://blog.bitrise.io/anyone-even-prs-can-have-secrets).
21
21
  #
22
- # ### bitbucket server and bitrsie
22
+ # ### bitbucket server and bitrise
23
23
  #
24
- # Danger will read the environment variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
25
- # finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
26
- # comes from the App Settings tab for your Bitrsie App. If you are manually setting a repo URL in the
27
- # Git Clone Repo step, you may need to set adjust this propery in the settings tab, maybe even fake it.
28
- # The patterns used are `(%r{\.com/(.*)})` and `(%r{\.com:(.*)})` and .split(/\.git$|$/) to remove ".git" if the URL contains it.
24
+ # Danger will read the environment variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
25
+ # finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
26
+ # comes from the App Settings tab for your Bitrise App. If you are manually setting a repo URL in the
27
+ # Git Clone Repo step, you may need to set adjust this property in the settings tab, maybe even fake it.
28
+ # The patterns used are `(%r{\.com/(.*)})` and `(%r{\.com:(.*)})` and .split(/\.git$|$/) to remove ".git" if the URL contains it.
29
29
  #
30
30
  class Bitrise < CI
31
31
  def self.validates_as_ci?(env)
@@ -48,7 +48,7 @@ module Danger
48
48
  def initialize(env)
49
49
  self.pull_request_id = env["BITRISE_PULL_REQUEST"]
50
50
  self.repo_url = env["GIT_REPOSITORY_URL"]
51
-
51
+
52
52
  matcher_url = self.repo_url
53
53
  self.repo_slug = repo_slug_from(self.repo_url)
54
54
  end
@@ -31,7 +31,7 @@ module Danger
31
31
  # to retrieve PR metadata, which will require an API token.
32
32
  #
33
33
  # 1. Go to your project > Settings > API Permissions. Create a token with scope "view-builds" and a label like "DANGER_CIRCLE_CI_API_TOKEN".
34
- # 2. Settings > Environement Variables. Add the token as a CircleCI environment variable, which exposes it to the Danger process.
34
+ # 2. Settings > Environment Variables. Add the token as a CircleCI environment variable, which exposes it to the Danger process.
35
35
  #
36
36
  # There is no difference here for OSS vs Closed, both scenarios will need this environment variable.
37
37
  #
@@ -5,6 +5,7 @@ module Danger
5
5
  # ### CI Setup
6
6
  #
7
7
  # In CodeBuild, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_SOURCE_VERSION, CODEBUILD_SOURCE_REPO_URL and DANGER_GITHUB_API_TOKEN.
8
+ # In CodeBuild with batch builds, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_WEBHOOK_TRIGGER, CODEBUILD_SOURCE_REPO_URL, CODEBUILD_BATCH_BUILD_IDENTIFIER and DANGER_GITHUB_API_TOKEN.
8
9
  #
9
10
  # ### Token Setup
10
11
  #
@@ -25,7 +26,11 @@ module Danger
25
26
 
26
27
  def initialize(env)
27
28
  self.repo_slug = self.class.extract_repo_slug(env)
28
- self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
29
+ if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
30
+ self.pull_request_id = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")[1].to_i
31
+ else
32
+ self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
33
+ end
29
34
  self.repo_url = self.class.extract_repo_url(env)
30
35
  end
31
36
 
@@ -44,11 +49,20 @@ module Danger
44
49
  end
45
50
 
46
51
  def self.extract_pr_url(env)
47
- return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
48
- return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
49
- return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
52
+ if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
53
+ return nil unless env.key? "CODEBUILD_WEBHOOK_TRIGGER"
54
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
55
+ return nil unless env["CODEBUILD_WEBHOOK_TRIGGER"].split("/").length == 2
56
+
57
+ event_type, pr_number = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")
58
+ return nil unless event_type == "pr"
59
+ else
60
+ return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
61
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
62
+ return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
50
63
 
51
- _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
64
+ _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
65
+ end
52
66
  github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
53
67
 
54
68
  "#{github_repo_url}/pull/#{pr_number}"
@@ -48,7 +48,7 @@ module Danger
48
48
 
49
49
  client_version = Gem::Version.new(client.version.version)
50
50
  if (client_version >= Gem::Version.new("10.7"))
51
- #Use the 'list merge requests associated with a commit' API, for speeed
51
+ #Use the 'list merge requests associated with a commit' API, for speed
52
52
  # (GET /projects/:id/repository/commits/:sha/merge_requests) available for GitLab >= 10.7
53
53
  merge_request = client.commit_merge_requests(project_path, base_commit, state: :opened).first
54
54
  if (client_version >= Gem::Version.new("13.8"))
@@ -31,7 +31,7 @@ module Danger
31
31
  #
32
32
  # #### General
33
33
  #
34
- # People occasionally see issues with Danger not classing your CI runs as a PR, to give you visibilty
34
+ # People occasionally see issues with Danger not classing your CI runs as a PR, to give you visibility
35
35
  # the Jenkins side of Danger expects to see one of these env vars:
36
36
  # - ghprbPullId
37
37
  # - CHANGE_ID
@@ -17,5 +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
- <%# Add the generated_by_ as a html coment to identify comments from danger. %>
20
+ <%# Add the generated_by_ as a html comment to identify comments from danger. %>
21
21
  <!-- "generated_by_<%= @danger_id %>" -->
@@ -308,7 +308,7 @@ module Danger
308
308
  private
309
309
 
310
310
  def eval_file(contents, path)
311
- eval(contents, nil, path.to_s) # rubocop:disable Eval
311
+ eval(contents, nil, path.to_s) # rubocop:disable Security/Eval
312
312
  end
313
313
 
314
314
  def print_list(title, rows)
@@ -132,7 +132,7 @@ module Danger
132
132
  #
133
133
  def import_dangerfile_from_path(path)
134
134
  raise "`import_dangerfile_from_path` requires a string" unless path.kind_of?(String)
135
- local_path = File.join(path, "Dangerfile")
135
+ local_path = File.file?(path) ? path : File.join(path, "Dangerfile")
136
136
  @dangerfile.parse(Pathname.new(local_path))
137
137
  end
138
138
 
@@ -3,7 +3,7 @@ require "danger/plugin_support/plugin"
3
3
  # Danger
4
4
  module Danger
5
5
  # Handles interacting with local only plugin inside a Dangerfile.
6
- # It is support pluggin for dry_run command and does not expose any methods.
6
+ # It is support plugin for dry_run command and does not expose any methods.
7
7
  # But you can still use other plugins like git
8
8
  #
9
9
  # @example Check that added lines contains agreed form of words
@@ -9,7 +9,7 @@ module Danger
9
9
  module RequestSources
10
10
  class BitbucketServer < RequestSource
11
11
  include Danger::Helpers::CommentsHelper
12
- attr_accessor :pr_json
12
+ attr_accessor :pr_json, :dismiss_out_of_range_messages
13
13
 
14
14
  def self.env_vars
15
15
  [
@@ -25,12 +25,14 @@ module Danger
25
25
  "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_TITLE",
26
26
  "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_DESCRIPTION",
27
27
  "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_LOGO_URL",
28
- "DANGER_BITBUCKETSERVER_VERIFY_SSL"
28
+ "DANGER_BITBUCKETSERVER_VERIFY_SSL",
29
+ "DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"
29
30
  ]
30
31
  end
31
32
 
32
33
  def initialize(ci_source, environment)
33
34
  self.ci_source = ci_source
35
+ self.dismiss_out_of_range_messages = environment["DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"] == 'true'
34
36
 
35
37
  project, slug = ci_source.repo_slug.split("/")
36
38
  @api = BitbucketServerAPI.new(project, slug, ci_source.pull_request_id, environment)
@@ -58,6 +60,10 @@ module Danger
58
60
  self.pr_json = @api.fetch_pr_json
59
61
  end
60
62
 
63
+ def pr_diff
64
+ @pr_diff ||= @api.fetch_pr_diff
65
+ end
66
+
61
67
  def setup_danger_branches
62
68
  base_branch = self.pr_json[:toRef][:id].sub("refs/heads/", "")
63
69
  base_commit = self.pr_json[:toRef][:latestCommit]
@@ -134,12 +140,22 @@ module Danger
134
140
  end
135
141
 
136
142
  def main_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
137
- {
138
- warnings: warnings.reject(&:inline?),
139
- errors: errors.reject(&:inline?),
140
- messages: messages.reject(&:inline?),
141
- markdowns: markdowns.reject(&:inline?)
142
- }
143
+ if dismiss_out_of_range_messages
144
+ {
145
+ warnings: warnings.reject(&:inline?),
146
+ errors: errors.reject(&:inline?),
147
+ messages: messages.reject(&:inline?),
148
+ markdowns: markdowns.reject(&:inline?)
149
+ }
150
+ else
151
+ in_diff = proc { |a| find_position_in_diff?(a.file, a.line) }
152
+ {
153
+ warnings: warnings.reject(&in_diff),
154
+ errors: errors.reject(&in_diff),
155
+ messages: messages.reject(&in_diff),
156
+ markdowns: markdowns.reject(&in_diff)
157
+ }
158
+ end
143
159
  end
144
160
 
145
161
  def inline_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
@@ -168,6 +184,30 @@ module Danger
168
184
  puts self.pr_json.to_json
169
185
  @api.update_pr_build_status(status, changeset, build_job_link, description)
170
186
  end
187
+
188
+ def find_position_in_diff?(file, line)
189
+ return nil if file.nil? || line.nil?
190
+ return nil if file.empty?
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] ||= begin
201
+ file_diff(file)[:hunks].map do |hunk|
202
+ hunk[:segments].select{|segment| segment[:type] == 'ADDED' }.map do |segment|
203
+ segment[:lines].map do |line|
204
+ line[:destination]
205
+ end
206
+ end
207
+ end.flatten
208
+ end
209
+ end
210
+
171
211
  end
172
212
  end
173
213
  end
@@ -43,6 +43,11 @@ module Danger
43
43
  fetch_json(uri)
44
44
  end
45
45
 
46
+ def fetch_pr_diff
47
+ uri = URI("#{pr_api_endpoint}/diff?withComments=false")
48
+ fetch_json(uri)
49
+ end
50
+
46
51
  def fetch_last_comments
47
52
  uri = URI("#{pr_api_endpoint}/activities?limit=1000")
48
53
  fetch_json(uri)[:values].select { |v| v[:action] == "COMMENTED" }.map { |v| v[:comment] }
@@ -195,7 +195,7 @@ module Danger
195
195
  body = generate_inline_markdown_body(m, danger_id: danger_id, template: "vsts")
196
196
  else
197
197
  # Hide the inline link behind a span
198
- m.message.gsub!("\n", "<br />")
198
+ m.message = m.message.gsub("\n", "<br />")
199
199
  m = process_markdown(m, true)
200
200
  body = generate_inline_comment_body(emoji, m, danger_id: danger_id, template: "vsts")
201
201
  # A comment might be in previous_violations because only now it's part of the unified diff
@@ -28,9 +28,9 @@ module Danger
28
28
 
29
29
  def supports_comments?
30
30
  major_version = @api_version.split(".").first.to_i
31
- minimun_version_for_comments = self.min_api_version_for_comments.split(".").first.to_i
31
+ minimum_version_for_comments = self.min_api_version_for_comments.split(".").first.to_i
32
32
 
33
- major_version >= minimun_version_for_comments
33
+ major_version >= minimum_version_for_comments
34
34
  end
35
35
 
36
36
  def inspect
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "8.6.1".freeze
2
+ VERSION = "9.1.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.6.1
4
+ version: 9.1.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: 2022-04-22 00:00:00.000000000 Z
12
+ date: 2022-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -135,14 +135,14 @@ dependencies:
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '4.7'
138
+ version: '5.0'
139
139
  type: :runtime
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '4.7'
145
+ version: '5.0'
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: terminal-table
148
148
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +206,7 @@ files:
206
206
  - lib/assets/DangerfileTemplate
207
207
  - lib/danger.rb
208
208
  - lib/danger/ci_source/appcenter.rb
209
+ - lib/danger/ci_source/appcircle.rb
209
210
  - lib/danger/ci_source/appveyor.rb
210
211
  - lib/danger/ci_source/azure_pipelines.rb
211
212
  - lib/danger/ci_source/bamboo.rb
@@ -328,7 +329,7 @@ homepage: https://github.com/danger/danger
328
329
  licenses:
329
330
  - MIT
330
331
  metadata: {}
331
- post_install_message:
332
+ post_install_message:
332
333
  rdoc_options: []
333
334
  require_paths:
334
335
  - lib
@@ -336,15 +337,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
336
337
  requirements:
337
338
  - - ">="
338
339
  - !ruby/object:Gem::Version
339
- version: 2.4.0
340
+ version: 2.7.0
340
341
  required_rubygems_version: !ruby/object:Gem::Requirement
341
342
  requirements:
342
343
  - - ">="
343
344
  - !ruby/object:Gem::Version
344
345
  version: '0'
345
346
  requirements: []
346
- rubygems_version: 3.1.4
347
- signing_key:
347
+ rubyforge_project:
348
+ rubygems_version: 2.7.6.2
349
+ signing_key:
348
350
  specification_version: 4
349
351
  summary: Like Unit Tests, but for your Team Culture.
350
352
  test_files: []