danger 7.0.1 → 8.0.4

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: 63dbe2ade63bf454f001702c2f0c3f478edd5a8cb060d2f417992da1f989ecdb
4
- data.tar.gz: a2dd9e0b5aacf4e28d03249721ed60f9dd1db93aca597e6eb6aaf087fe9dea0a
3
+ metadata.gz: 24f1ad8fc490aea6b75f155f5acb47d5b126c23b7bab8392080557dca1bee597
4
+ data.tar.gz: 88c387703dcb3efc9fed05f38fa03ec2ba2b46a69cc287a9d368750b48d155ca
5
5
  SHA512:
6
- metadata.gz: d3205f7b0a508ff32fe0fac7b24b3a6b54aac5f272ff80b3594175a79e3eaa0967a05cd697c190883c759a2518e06c745b7e9089453dbb16b7b23848e531906c
7
- data.tar.gz: dc10f9b37711f33c1e92c128796f0da53b5d9f03f0d68e089d00360143fa552d96dbf30cf35285323d93d8c8b1e936d2b9429579d358cb28f5057eef77aeb94c
6
+ metadata.gz: 17bbad4f7cc06de57c08ff9360dd591084959c3f23d40ed58481f8bc5aa82036a04d3376cf5fdc8f50400e0733e18bc85e0db0631a8da0cb3ea27b692697c105
7
+ data.tar.gz: 1da0fe48081c9fa19acc9bb7df3df1ae2efe4b919f38656503e52f52ed6142ea17499a5928bc47ba5fb352370bbb2152e4cf969c44b87dbef0d6250526349ee6
@@ -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
@@ -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>`, 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
@@ -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?
@@ -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.1".freeze
2
+ VERSION = "8.0.4".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.1
4
+ version: 8.0.4
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-30 00:00:00.000000000 Z
12
+ date: 2020-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -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
  - - ">="