danger 8.0.0 → 8.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/danger/ci_source/bitrise.rb +19 -6
- data/lib/danger/ci_source/gitlab_ci.rb +26 -9
- data/lib/danger/ci_source/teamcity.rb +2 -0
- data/lib/danger/helpers/comments_helper.rb +2 -2
- data/lib/danger/request_sources/github/github.rb +4 -0
- data/lib/danger/request_sources/gitlab.rb +7 -3
- data/lib/danger/scm_source/git_repo.rb +1 -1
- data/lib/danger/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6ea9c4a38578c0c9cd6e762b689010bce9de3bc6479134cce2f6c45afdce925
|
4
|
+
data.tar.gz: 4f131339c436c4ee163660341e0471c0c456b0251da17c6a5f5511f2fc3ac708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93226e7a7fe9b4300efb93ac07e59932eda1b25cae739f1f48d132f0d77f9d5f6a861d226785981f6580587cfd11380db5ec4e0935adea7c3707f35a5dc2af3d
|
7
|
+
data.tar.gz: 7cca48807d7cb110180f88b62d1af13591ba83791f0f1528384dcd2c4c3247394fec2abfb9c1bc592e496659d3d14f6f46e1813af125570c967713b9d602251c
|
@@ -50,16 +50,29 @@ module Danger
|
|
50
50
|
self.repo_url = env["GIT_REPOSITORY_URL"]
|
51
51
|
|
52
52
|
matcher_url = self.repo_url
|
53
|
+
self.repo_slug = repo_slug_from(self.repo_url)
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
if
|
56
|
-
|
56
|
+
def repo_slug_from(url)
|
57
|
+
if url =~ URI::regexp
|
58
|
+
# Try to parse the URL as a valid URI. This should cover the cases of http/https/ssh URLs.
|
59
|
+
begin
|
60
|
+
uri = URI.parse(url)
|
61
|
+
return uri.path.sub(/^(\/)/,'').sub(/(.git)$/,'')
|
62
|
+
rescue URI::InvalidURIError
|
63
|
+
# In case URL could not be parsed fallback to git URL parsing.
|
64
|
+
repo_slug_asgiturl(url)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
# In case URL could not be parsed fallback to git URL parsing. git@github.com:organization/repo.git
|
68
|
+
repo_slug_asgiturl(url)
|
57
69
|
end
|
70
|
+
end
|
58
71
|
|
72
|
+
def repo_slug_asgiturl(url)
|
73
|
+
matcher_url = url
|
59
74
|
repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
|
60
|
-
|
61
|
-
self.repo_slug = repo_matches unless repo_matches.nil?
|
62
|
-
|
75
|
+
return repo_matches unless repo_matches.nil?
|
63
76
|
end
|
64
77
|
end
|
65
78
|
end
|
@@ -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
|
@@ -27,6 +27,8 @@ module Danger
|
|
27
27
|
# branch="%teamcity.build.branch%"
|
28
28
|
# export GITHUB_PULL_REQUEST_ID=(${branch//\// })
|
29
29
|
# ```
|
30
|
+
# Or if you are using the pull request feature you can set an environment parameter called `GITHUB_PULL_REQUEST_ID`
|
31
|
+
# to the value of: `%teamcity.pullRequest.number`
|
30
32
|
#
|
31
33
|
# #### GitLab
|
32
34
|
#
|
@@ -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
|
|
@@ -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?
|
@@ -204,7 +208,7 @@ module Danger
|
|
204
208
|
rest_inline_violations = submit_inline_comments!({
|
205
209
|
danger_id: danger_id,
|
206
210
|
previous_violations: previous_violations
|
207
|
-
}.merge(inline_violations))
|
211
|
+
}.merge(**inline_violations))
|
208
212
|
|
209
213
|
main_violations = merge_violations(
|
210
214
|
regular_violations, rest_inline_violations
|
@@ -223,7 +227,7 @@ module Danger
|
|
223
227
|
template: "gitlab",
|
224
228
|
danger_id: danger_id,
|
225
229
|
previous_violations: previous_violations
|
226
|
-
}.merge(main_violations))
|
230
|
+
}.merge(**main_violations))
|
227
231
|
|
228
232
|
comment_result =
|
229
233
|
if should_create_new_comment
|
@@ -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: 8.0.
|
4
|
+
version: 8.0.5
|
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-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -107,14 +107,14 @@ dependencies:
|
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2.
|
110
|
+
version: '2.3'
|
111
111
|
type: :runtime
|
112
112
|
prerelease: false
|
113
113
|
version_requirements: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '2.
|
117
|
+
version: '2.3'
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: kramdown-parser-gfm
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|