danger 7.0.0 → 8.0.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: bac82d5de5c00b56576cd95681444543eb4b540f6bb6767ac1d407fb13150fbc
4
- data.tar.gz: 032b2993f97a2c8c56b4d8f69690c7bbd7bbf6738e3631af54a0ea657811939f
3
+ metadata.gz: f89ff08f152cedf23e9fcb48adc8b256ddb1ef8992c682bb6ad6ef1620ba1f5f
4
+ data.tar.gz: d9f689cd3b403177e3475d364f2aebe5b49a78e72eebfaeab49fad8d6ec3f619
5
5
  SHA512:
6
- metadata.gz: 74fa60f6fc40846e32837a0b8234b119f6132ff4a629abd705480a8c4ebee1bbb78ed19ad940fc63d8d08b427e238bea3edb2d67286d23ceef48ac8a7c9e0dd3
7
- data.tar.gz: 7072368e374403c31ea5240b8004942c9e28f00806f4acb1d65fafe850d291b8a893f06a3b1a294a325e374fc594e732c43343cd50c36ea99ee5d52ffe281c0a
6
+ metadata.gz: 9b1db5d7f0ed5106614a967c5bd45cdb8b896327f29512d259f662c0ad994438bb2c9240c122aab93f228eb21bf2f80029d6cf851d7f315f7559e491aa60cb04
7
+ data.tar.gz: 51413afca0478a350693672cb831e67e5ed92ff5a6d026caa805bdb58ff09bf7b8bfbbdd5cfc16c83878d8164af26088036fbc5aa354d57c990c75dcb15f8f6f
@@ -1,5 +1,6 @@
1
1
  # http://docs.gitlab.com/ce/ci/variables/README.html
2
2
  require "uri"
3
+ require "danger/request_sources/github/github"
3
4
  require "danger/request_sources/gitlab"
4
5
 
5
6
  module Danger
@@ -15,10 +16,13 @@ module Danger
15
16
  # ```
16
17
  # ### Token Setup
17
18
  #
18
- # Add the `DANGER_GITLAB_API_TOKEN` to your pipeline env variables.
19
- class GitLabCI < CI
20
- attr_reader :project_url
19
+ # Add the `DANGER_GITLAB_API_TOKEN` to your pipeline env variables if you
20
+ # are hosting your code on GitLab. If you are using GitLab as a mirror
21
+ # for the purpose of CI/CD, while hosting your repo on GitHub, set the
22
+ # `DANGER_GITHUB_API_TOKEN` as well as the project repo URL to
23
+ # `DANGER_PROJECT_REPO_URL`.
21
24
 
25
+ class GitLabCI < CI
22
26
  def self.validates_as_ci?(env)
23
27
  env.key? "GITLAB_CI"
24
28
  end
@@ -28,11 +32,12 @@ module Danger
28
32
  "GITLAB_CI", "CI_PROJECT_PATH"
29
33
  ].all? { |x| env[x] }
30
34
 
31
- exists && determine_merge_request_id(env).to_i > 0
35
+ exists && determine_pull_or_merge_request_id(env).to_i > 0
32
36
  end
33
37
 
34
- def self.determine_merge_request_id(env)
38
+ def self.determine_pull_or_merge_request_id(env)
35
39
  return env["CI_MERGE_REQUEST_IID"] if env["CI_MERGE_REQUEST_IID"]
40
+ return env["CI_EXTERNAL_PULL_REQUEST_IID"] if env["CI_EXTERNAL_PULL_REQUEST_IID"]
36
41
  return 0 unless env["CI_COMMIT_SHA"]
37
42
 
38
43
  project_path = env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
@@ -54,16 +59,28 @@ module Danger
54
59
 
55
60
  def initialize(env)
56
61
  @env = env
57
- @repo_slug = env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
58
- @project_url = env["CI_MERGE_REQUEST_PROJECT_URL"] || env["CI_PROJECT_URL"]
62
+ @repo_slug = slug_from(env)
59
63
  end
60
64
 
61
65
  def supported_request_sources
62
- @supported_request_sources ||= [Danger::RequestSources::GitLab]
66
+ @supported_request_sources ||= [
67
+ Danger::RequestSources::GitHub,
68
+ Danger::RequestSources::GitLab
69
+ ]
63
70
  end
64
71
 
65
72
  def pull_request_id
66
- @pull_request_id ||= self.class.determine_merge_request_id(@env)
73
+ @pull_request_id ||= self.class.determine_pull_or_merge_request_id(@env)
74
+ end
75
+
76
+ private
77
+
78
+ def slug_from(env)
79
+ if env["DANGER_PROJECT_REPO_URL"]
80
+ env["DANGER_PROJECT_REPO_URL"].split('/').last(2).join('/')
81
+ else
82
+ env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
83
+ end
67
84
  end
68
85
  end
69
86
  end
@@ -63,7 +63,7 @@ module Danger
63
63
  unless EnvironmentManager.pr?(system_env)
64
64
  ci_name = EnvironmentManager.local_ci_source(system_env).name.split("::").last
65
65
 
66
- msg = "Not a #{ci_name} Pull Request - skipping `danger` run. "
66
+ msg = "Not a #{ci_name} #{commit_request(ci_name)} - skipping `danger` run. "
67
67
  # circle won't run danger properly if the commit is pushed and build runs before the PR exists
68
68
  # https://danger.systems/guides/troubleshooting.html#circle-ci-doesnt-run-my-build-consistently
69
69
  # the best solution is to enable `fail_if_no_pr`, and then re-run the job once the PR is up
@@ -83,5 +83,10 @@ module Danger
83
83
  def head_branch(user_specified_head_branch)
84
84
  user_specified_head_branch || EnvironmentManager.danger_head_branch
85
85
  end
86
+
87
+ def commit_request(ci_name)
88
+ return "Merge Request" if ci_name == 'GitLabCI'
89
+ return "Pull Request"
90
+ end
86
91
  end
87
92
  end
@@ -49,8 +49,8 @@ module Danger
49
49
  message = "#{markdown_link_to_message(violation, hide_link)}#{message}" if violation.file && violation.line
50
50
 
51
51
  html = markdown_parser(message).to_html
52
- # Remove the outer `<p>`, the -5 represents a newline + `</p>`
53
- html = html[3...-5] if html.start_with? "<p>"
52
+ # Remove the outer `<p>` and `</p>`.
53
+ html = html.strip.sub(%r{\A<p>(.*)</p>\z}m, '\1')
54
54
  Violation.new(html, violation.sticky, violation.file, violation.line)
55
55
  end
56
56
 
@@ -128,7 +128,7 @@ module Danger
128
128
  def generate_inline_comment_body(emoji,
129
129
  message,
130
130
  danger_id: "danger",
131
- resolved: [],
131
+ resolved: false,
132
132
  template: "github")
133
133
  apply_template(
134
134
  tables: [{ content: [message], resolved: resolved, emoji: emoji }],
@@ -40,6 +40,10 @@ module Danger
40
40
  end
41
41
  end
42
42
 
43
+ def validates_as_ci?
44
+ true
45
+ end
46
+
43
47
  def validates_as_api_source?
44
48
  (@token && !@token.empty?) || self.environment["DANGER_USE_LOCAL_GIT"]
45
49
  end
@@ -170,7 +174,7 @@ module Danger
170
174
  rest_inline_violations = submit_inline_comments!({
171
175
  danger_id: danger_id,
172
176
  previous_violations: previous_violations
173
- }.merge(inline_violations))
177
+ }.merge(**inline_violations))
174
178
 
175
179
  main_violations = merge_violations(
176
180
  regular_violations, rest_inline_violations
@@ -189,7 +193,7 @@ module Danger
189
193
  template: "github",
190
194
  danger_id: danger_id,
191
195
  previous_violations: previous_violations
192
- }.merge(main_violations))
196
+ }.merge(**main_violations))
193
197
 
194
198
  comment_result =
195
199
  if should_create_new_comment
@@ -50,7 +50,11 @@ module Danger
50
50
  includes_port = self.host.include? ":"
51
51
  raise "Port number included in `DANGER_GITLAB_HOST`, this will fail with GitLab CI Runners" if includes_port
52
52
 
53
- super
53
+ # We don't call super because in some cases the Git remote doesn't match the GitLab instance host.
54
+ # In Danger::EnvironmentManager#initialize we still check that the request source is #validates_as_api_source?
55
+ # so that should be sufficient to validate GitLab as request source.
56
+ # See https://github.com/danger/danger/issues/1231 and https://gitlab.com/gitlab-com/gl-infra/infrastructure/-/issues/10069.
57
+ true
54
58
  end
55
59
 
56
60
  def validates_as_api_source?
@@ -302,6 +306,9 @@ module Danger
302
306
  def file_url(organisation: nil, repository: nil, branch: nil, path: nil)
303
307
  branch ||= 'master'
304
308
  token = @environment["DANGER_GITLAB_API_TOKEN"]
309
+ # According to GitLab Repositories API docs path and id(slug) should be encoded.
310
+ path = URI.encode_www_form_component(path)
311
+ repository = URI.encode_www_form_component(repository)
305
312
  "#{endpoint}/projects/#{repository}/repository/files/#{path}/raw?ref=#{branch}&private_token=#{token}"
306
313
  end
307
314
 
@@ -135,7 +135,7 @@ module Danger
135
135
  git_in_depth_fetch
136
136
  possible_merge_base = possible_merge_base(repo, from, to)
137
137
 
138
- raise "Cannot find a merge base between #{from} and #{to}." unless possible_merge_base
138
+ raise "Cannot find a merge base between #{from} and #{to}. If you are using shallow clone/fetch, try increasing the --depth" unless possible_merge_base
139
139
 
140
140
  possible_merge_base
141
141
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "7.0.0".freeze
2
+ VERSION = "8.0.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: 7.0.0
4
+ version: 8.0.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: 2020-04-16 00:00:00.000000000 Z
12
+ date: 2020-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.6'
48
+ version: '1.7'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.6'
55
+ version: '1.7'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: colored2
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -325,7 +325,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
325
325
  requirements:
326
326
  - - ">="
327
327
  - !ruby/object:Gem::Version
328
- version: 2.3.0
328
+ version: 2.4.0
329
329
  required_rubygems_version: !ruby/object:Gem::Requirement
330
330
  requirements:
331
331
  - - ">="