danger 5.3.3 → 5.3.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
  SHA1:
3
- metadata.gz: 3c4f4e43ea259c3203e6be2c3990d24e64b1eb87
4
- data.tar.gz: 8a78dfd71a3b65200988fe21e7fab9ee2a6da163
3
+ metadata.gz: fd328f55fb2fe6ee6a1e0620c24e030dbb6186ca
4
+ data.tar.gz: ce734963c70c59a01bc08d615a01a1e398a484a0
5
5
  SHA512:
6
- metadata.gz: 611c401f519dec25f89a8ea35cb5b21cb48c618690c8595b2788b91b00e1b2c8d5585a191a2cc2551a8c43992116af841767b009c590963926fb4b2edc930fcf
7
- data.tar.gz: 4b8e80af258bd44d48f1cfed63559a0405d1fdda0d0ad5d35eb6e73fe1e46c77d5dee0be3c887276dad1cab498e1660f48a01906800ea6f56299d3822be9611f
6
+ metadata.gz: cb16654b5163a1852a4ef3a371c799398fdd1d84944da4de149ba9ba4b2cdcf492500713ba51558469fe2a23e0324fa5a6f0186037ef3497671b2bd12d67fa1f
7
+ data.tar.gz: 15f2f3a72bce7776860936abd2a2e3dd0b1bc43a3b3d84fc2baf2a0bce40a265f75e79b6fb3ac1ed13dc9865f6662942b09bd1e34713f5a4fbcc6ae77b52bffc
@@ -6,13 +6,15 @@ module Danger
6
6
  # ### CI Setup
7
7
  #
8
8
  # Add a script step to your workflow:
9
- # ``` yml
9
+ #
10
+ # ```yml
10
11
  # - script@1.1.2:
11
12
  # inputs:
12
13
  # - content: |-
13
14
  # bundle install
14
15
  # bundle exec danger
15
16
  # ```
17
+ #
16
18
  # ### Token Setup
17
19
  #
18
20
  # Add the `DANGER_GITHUB_API_TOKEN` to your workflow's App Env Vars.
@@ -1,35 +1,62 @@
1
1
  module Danger
2
2
  # ### CI Setup
3
3
  #
4
- # Buddybuild has an integration for Danger already built-in.
5
- # What you need to do is to upload your `Gemfile` and `Dangerfile` to
6
- # the server and you should be all set-up. However, if you want to use
7
- # different bot for Danger, you can do it with token setup described below.
4
+ # Read how you can setup Danger on the buddybuild blog:
5
+ # https://www.buddybuild.com/blog/using-danger-with-buddybuild/
8
6
  #
9
7
  # ### Token Setup
10
8
  #
11
9
  # Login to buddybuild and select your app. Go to your *App Settings* and
12
10
  # in the *Build Settings* menu on the left, choose *Environment Variables*.
11
+ # http://docs.buddybuild.com/docs/environment-variables
13
12
  #
14
13
  # #### GitHub
15
14
  # Add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV.
16
15
  #
17
16
  # #### GitLab
18
17
  # Add the `DANGER_GITLAB_API_TOKEN` to your build user's ENV.
19
-
18
+ #
19
+ # #### Bitbucket Cloud
20
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
21
+ # to your build user's ENV.
22
+ #
23
+ # #### Bitbucket server
24
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
25
+ # and `DANGER_BITBUCKETSERVER_HOST` to your build user's ENV.
26
+ #
27
+ # ### Running Danger
28
+ #
29
+ # Once the environment variables are all available, create a custom build step
30
+ # to run Danger as part of your build process:
31
+ # http://docs.buddybuild.com/docs/custom-prebuild-and-postbuild-steps
20
32
  class Buddybuild < CI
21
- def self.validates_as_ci?(_)
22
- false
33
+ #######################################################################
34
+ def self.validates_as_ci?(env)
35
+ value = env["BUDDYBUILD_BUILD_ID"]
36
+ return !value.nil? && !env["BUDDYBUILD_BUILD_ID"].empty?
23
37
  end
24
38
 
25
- def self.validates_as_pr?(_)
26
- false
39
+ #######################################################################
40
+ def self.validates_as_pr?(env)
41
+ value = env["BUDDYBUILD_PULL_REQUEST"]
42
+ return !value.nil? && !env["BUDDYBUILD_PULL_REQUEST"].empty?
27
43
  end
28
44
 
29
- def initialize(_) end
30
-
45
+ #######################################################################
31
46
  def supported_request_sources
32
- @supported_request_sources ||= []
47
+ @supported_request_sources ||= [
48
+ Danger::RequestSources::GitHub,
49
+ Danger::RequestSources::GitLab,
50
+ Danger::RequestSources::BitbucketServer,
51
+ Danger::RequestSources::BitbucketCloud
52
+ ]
53
+ end
54
+
55
+ #######################################################################
56
+ def initialize(env)
57
+ self.repo_slug = env["BUDDYBUILD_REPO_SLUG"]
58
+ self.pull_request_id = env["BUDDYBUILD_PULL_REQUEST"]
59
+ self.repo_url = GitRepo.new.origins # Buddybuild doesn't provide a repo url env variable for now
33
60
  end
34
61
  end
35
62
  end
@@ -4,30 +4,54 @@ require "danger/request_sources/gitlab"
4
4
 
5
5
  module Danger
6
6
  # ### CI Setup
7
- # GitLab CI is currently not supported because GitLab's runners don't expose
8
- # the required values in the environment. Namely CI_MERGE_REQUEST_ID does not
9
- # exist as of yet, however there is an
10
- # [MR](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5698) fixing this.
11
- # If that has been merged and you are using either gitlab.com or a release
12
- # with that change this CISource will work.
13
7
  #
8
+ # Install dependencies and add a danger step to your .gitlab-ci.yml:
9
+ # ``` yml
10
+ # before_script:
11
+ # - bundle install
12
+ # danger:
13
+ # script:
14
+ # - bundle exec danger
15
+ # ```
16
+ # ### Token Setup
17
+ #
18
+ # Add the `DANGER_GITHUB_API_TOKEN` to your pipeline env variables.
14
19
  class GitLabCI < CI
15
20
  def self.validates_as_ci?(env)
16
21
  env.key? "GITLAB_CI"
17
22
  end
18
23
 
19
24
  def self.validates_as_pr?(env)
20
- exists = ["CI_MERGE_REQUEST_ID", "CI_PROJECT_ID", "GITLAB_CI"].all? { |x| env[x] }
21
- exists && env["CI_MERGE_REQUEST_ID"].to_i > 0
25
+ exists = [
26
+ "GITLAB_CI", "CI_PROJECT_ID"
27
+ ].all? { |x| env[x] }
28
+
29
+ exists && determine_merge_request_id(env).to_i > 0
22
30
  end
23
31
 
24
- def supported_request_sources
25
- @supported_request_sources ||= [Danger::RequestSources::GitLab]
32
+ def self.determine_merge_request_id(env)
33
+ return env["CI_MERGE_REQUEST_ID"] if env["CI_MERGE_REQUEST_ID"]
34
+ return 0 unless env["CI_COMMIT_SHA"]
35
+
36
+ project_id = env["CI_PROJECT_ID"]
37
+ base_commit = env["CI_COMMIT_SHA"]
38
+ client = RequestSources::GitLab.new(nil, env).client
39
+
40
+ merge_requests = client.merge_requests(project_id, state: :opened)
41
+ merge_request = merge_requests.auto_paginate.bsearch do |mr|
42
+ mr.sha == base_commit
43
+ end
44
+
45
+ merge_request.nil? ? 0 : merge_request.iid
26
46
  end
27
47
 
28
48
  def initialize(env)
29
49
  self.repo_slug = env["CI_PROJECT_ID"]
30
- self.pull_request_id = env["CI_MERGE_REQUEST_ID"]
50
+ self.pull_request_id = self.class.determine_merge_request_id(env)
51
+ end
52
+
53
+ def supported_request_sources
54
+ @supported_request_sources ||= [Danger::RequestSources::GitLab]
31
55
  end
32
56
  end
33
57
  end
@@ -12,6 +12,14 @@ module Danger
12
12
  # when `true` means that the message will be crossed out instead of being removed.
13
13
  # If it's not called again on subsequent runs.
14
14
  #
15
+ # Each of `message`, `warn`, `fail` and `markdown` support multiple passed arguments
16
+ # @example
17
+ #
18
+ # message 'Hello', 'World', file: "Dangerfile", line: 1
19
+ # warn ['This', 'is', 'warning'], file: "Dangerfile", line: 1
20
+ # fail 'Ooops', 'bad bad error', sticky: false
21
+ # markdown '# And', '# Even', '# Markdown', file: "Dangerfile", line: 1
22
+ #
15
23
  # By default, using `fail` would fail the corresponding build. Either via an API call, or
16
24
  # via the return value for the danger command. If you have linters with errors for this call
17
25
  # you can use `messaging.fail` instead.
@@ -26,6 +34,8 @@ module Danger
26
34
  # @example Failing a build
27
35
  #
28
36
  # fail "This build didn't pass tests"
37
+ # fail "Ooops!", "Something bad happend"
38
+ # fail ["This is example", "with array"]
29
39
  #
30
40
  # @example Failing a build, and note that on subsequent runs
31
41
  #
@@ -34,6 +44,8 @@ module Danger
34
44
  # @example Passing a warning
35
45
  #
36
46
  # warn "This build didn't pass linting"
47
+ # warn "Hm...", "This is not really good"
48
+ # warn ["Multiple warnings", "via array"]
37
49
  #
38
50
  # @example Displaying a markdown table
39
51
  #
@@ -43,6 +55,9 @@ module Danger
43
55
  # message << "20 | No documentation | Error \n"
44
56
  # markdown message
45
57
  #
58
+ # markdown "### First issue", "### Second issue"
59
+ # markdown ["### First issue", "### Second issue"]
60
+ #
46
61
  # @example Adding an inline warning to a file
47
62
  #
48
63
  # warn("You shouldn't use puts in your Dangerfile", file: "Dangerfile", line: 10)
@@ -72,7 +87,7 @@ module Danger
72
87
  # @!group Core
73
88
  # Print markdown to below the table
74
89
  #
75
- # @param [String] message
90
+ # @param [String, Array<String>] message
76
91
  # The markdown based message to be printed below the table
77
92
  # @param [String] file
78
93
  # Optional. Path to the file that the message is for.
@@ -80,14 +95,19 @@ module Danger
80
95
  # Optional. The line in the file to present the message in.
81
96
  # @return [void]
82
97
  #
83
- def markdown(message, file: nil, line: nil)
84
- @markdowns << Markdown.new(message, file, line)
98
+ def markdown(*markdowns, **options)
99
+ file = options.fetch(:file, nil)
100
+ line = options.fetch(:line, nil)
101
+
102
+ markdowns.flatten.each do |markdown|
103
+ @markdowns << Markdown.new(markdown, file, line)
104
+ end
85
105
  end
86
106
 
87
107
  # @!group Core
88
108
  # Print out a generate message on the PR
89
109
  #
90
- # @param [String] message
110
+ # @param [String, Array<String> message
91
111
  # The message to present to the user
92
112
  # @param [Boolean] sticky
93
113
  # Whether the message should be kept after it was fixed,
@@ -98,14 +118,20 @@ module Danger
98
118
  # Optional. The line in the file to present the message in.
99
119
  # @return [void]
100
120
  #
101
- def message(message, sticky: false, file: nil, line: nil)
102
- @messages << Violation.new(message, sticky, file, line)
121
+ def message(*messages, **options)
122
+ sticky = options.fetch(:sticky, false)
123
+ file = options.fetch(:file, nil)
124
+ line = options.fetch(:line, nil)
125
+
126
+ messages.flatten.each do |message|
127
+ @messages << Violation.new(message, sticky, file, line)
128
+ end
103
129
  end
104
130
 
105
131
  # @!group Core
106
132
  # Specifies a problem, but not critical
107
133
  #
108
- # @param [String] message
134
+ # @param [String, Array<String> message
109
135
  # The message to present to the user
110
136
  # @param [Boolean] sticky
111
137
  # Whether the message should be kept after it was fixed,
@@ -116,15 +142,21 @@ module Danger
116
142
  # Optional. The line in the file to present the message in.
117
143
  # @return [void]
118
144
  #
119
- def warn(message, sticky: false, file: nil, line: nil)
120
- return if should_ignore_violation(message)
121
- @warnings << Violation.new(message, sticky, file, line)
145
+ def warn(*warnings, **options)
146
+ sticky = options.fetch(:sticky, false)
147
+ file = options.fetch(:file, nil)
148
+ line = options.fetch(:line, nil)
149
+
150
+ warnings.flatten.each do |warning|
151
+ next if should_ignore_violation(warning)
152
+ @warnings << Violation.new(warning, sticky, file, line)
153
+ end
122
154
  end
123
155
 
124
156
  # @!group Core
125
157
  # Declares a CI blocking error
126
158
  #
127
- # @param [String] message
159
+ # @param [String, Array<String> message
128
160
  # The message to present to the user
129
161
  # @param [Boolean] sticky
130
162
  # Whether the message should be kept after it was fixed,
@@ -135,9 +167,15 @@ module Danger
135
167
  # Optional. The line in the file to present the message in.
136
168
  # @return [void]
137
169
  #
138
- def fail(message, sticky: false, file: nil, line: nil)
139
- return if should_ignore_violation(message)
140
- @errors << Violation.new(message, sticky, file, line)
170
+ def fail(*failures, **options)
171
+ sticky = options.fetch(:sticky, false)
172
+ file = options.fetch(:file, nil)
173
+ line = options.fetch(:line, nil)
174
+
175
+ failures.flatten.each do |failure|
176
+ next if should_ignore_violation(failure)
177
+ @errors << Violation.new(failure, sticky, file, line)
178
+ end
141
179
  end
142
180
 
143
181
  # @!group Reporting
@@ -33,10 +33,7 @@ module Danger
33
33
  # The require happens inline so that it won't cause exceptions when just using the `danger` gem.
34
34
  require "gitlab"
35
35
 
36
- params = { private_token: token }
37
- params[:endpoint] = endpoint
38
-
39
- @client ||= Gitlab.client(params)
36
+ @client ||= Gitlab.client(endpoint: endpoint, private_token: token)
40
37
  rescue LoadError
41
38
  puts "The GitLab gem was not installed, you will need to change your Gem from `danger` to `danger-gitlab`.".red
42
39
  puts "\n - See https://github.com/danger/danger/blob/master/CHANGELOG.md#400"
@@ -52,7 +49,8 @@ module Danger
52
49
  end
53
50
 
54
51
  def endpoint
55
- @endpoint ||= @environment["DANGER_GITLAB_API_BASE_URL"] || "https://gitlab.com/api/v3"
52
+ @endpoint ||= @environment["DANGER_GITLAB_API_BASE_URL"] ||
53
+ "https://gitlab.com/api/v4"
56
54
  end
57
55
 
58
56
  def host
@@ -135,7 +133,10 @@ module Danger
135
133
  else
136
134
  original_id = editable_comments.first.id
137
135
  client.edit_merge_request_comment(
138
- ci_source.repo_slug, ci_source.pull_request_id, original_id, body
136
+ ci_source.repo_slug,
137
+ ci_source.pull_request_id,
138
+ original_id,
139
+ { body: body }
139
140
  )
140
141
  end
141
142
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "5.3.3".freeze
2
+ VERSION = "5.3.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: 5.3.3
4
+ version: 5.3.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: 2017-07-04 00:00:00.000000000 Z
12
+ date: 2017-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide