danger 7.0.0 → 8.0.3
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 +4 -4
- data/lib/danger/ci_source/gitlab_ci.rb +26 -9
- data/lib/danger/danger_core/executor.rb +6 -1
- data/lib/danger/helpers/comments_helper.rb +3 -3
- data/lib/danger/request_sources/github/github.rb +6 -2
- data/lib/danger/request_sources/gitlab.rb +8 -1
- data/lib/danger/scm_source/git_repo.rb +1 -1
- data/lib/danger/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f89ff08f152cedf23e9fcb48adc8b256ddb1ef8992c682bb6ad6ef1620ba1f5f
|
4
|
+
data.tar.gz: d9f689cd3b403177e3475d364f2aebe5b49a78e72eebfaeab49fad8d6ec3f619
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
20
|
-
|
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 &&
|
35
|
+
exists && determine_pull_or_merge_request_id(env).to_i > 0
|
32
36
|
end
|
33
37
|
|
34
|
-
def self.
|
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
|
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 ||= [
|
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.
|
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}
|
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
|
53
|
-
html = html
|
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
|
data/lib/danger/version.rb
CHANGED
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:
|
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-
|
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.
|
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.
|
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.
|
328
|
+
version: 2.4.0
|
329
329
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
330
330
|
requirements:
|
331
331
|
- - ">="
|