danger 5.5.6 → 5.5.7
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/bitrise.rb +5 -1
- data/lib/danger/ci_source/teamcity.rb +63 -3
- data/lib/danger/danger_core/dangerfile.rb +5 -5
- data/lib/danger/danger_core/messages/markdown.rb +12 -0
- data/lib/danger/danger_core/messages/violation.rb +13 -0
- data/lib/danger/request_sources/bitbucket_cloud.rb +1 -2
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +25 -4
- data/lib/danger/request_sources/bitbucket_server.rb +4 -0
- data/lib/danger/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac631daf8aaea436429afb68d8a534b84b03c9a9
|
4
|
+
data.tar.gz: aed843fe3d16f9e09fa1b1b0dbb300e0cb33f958
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d84b21f613d955ebac96ad8561126d53eb6caff28959909d10d9061e4204a470714500e98674375db4a4e405173a788e64113ef31a994429164ec5b00e979a79
|
7
|
+
data.tar.gz: d80f497254260a8d6cc65e61c92b7a9ac0cf7b660cb94e7e4b7d82791a02c010ff78bc36a4c5bf3ecc0c42a587641f49e238af265e672072dd8bba293cfa4e77
|
@@ -29,7 +29,11 @@ module Danger
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def supported_request_sources
|
32
|
-
@supported_request_sources ||= [
|
32
|
+
@supported_request_sources ||= [
|
33
|
+
Danger::RequestSources::GitHub,
|
34
|
+
Danger::RequestSources::GitLab,
|
35
|
+
Danger::RequestSources::BitbucketServer
|
36
|
+
]
|
33
37
|
end
|
34
38
|
|
35
39
|
def initialize(env)
|
@@ -38,6 +38,32 @@ module Danger
|
|
38
38
|
#
|
39
39
|
# We would love some advice on improving this setup.
|
40
40
|
#
|
41
|
+
# #### BitBucket Cloud
|
42
|
+
#
|
43
|
+
# You will need to add the following environment variables as build parameters or by exporting them inside your
|
44
|
+
# Simple Command Runner.
|
45
|
+
# - `DANGER_BITBUCKETCLOUD_USERNAME`
|
46
|
+
# - `DANGER_BITBUCKETCLOUD_PASSWORD`
|
47
|
+
# - `BITBUCKET_REPO_SLUG`
|
48
|
+
# - `BITBUCKET_REPO_URL`
|
49
|
+
#
|
50
|
+
# You will also need to set the `BITBUCKET_BRANCH_NAME` environment variable.
|
51
|
+
# TeamCity provides `%teamcity.build.branch%`, which you can use at the top of your Simple Command Runner:
|
52
|
+
# ```sh
|
53
|
+
# export BITBUCKET_BRANCH_NAME="%teamcity.build.branch%"
|
54
|
+
# ```
|
55
|
+
#
|
56
|
+
# #### BitBucket Server
|
57
|
+
#
|
58
|
+
# You will need to add the following environment variables as build parameters or by exporting them inside your
|
59
|
+
# Simple Command Runner.
|
60
|
+
# - `DANGER_BITBUCKETSERVER_USERNAME`
|
61
|
+
# - `DANGER_BITBUCKETSERVER_PASSWORD`
|
62
|
+
# - `DANGER_BITBUCKETSERVER_HOST`
|
63
|
+
# - `BITBUCKETSERVER_REPO_SLUG`
|
64
|
+
# - `BITBUCKETSERVER_PULL_REQUEST_ID`
|
65
|
+
# - `BITBUCKETSERVER_REPO_URL`
|
66
|
+
#
|
41
67
|
class TeamCity < CI
|
42
68
|
class << self
|
43
69
|
def validates_as_github_pr?(env)
|
@@ -47,6 +73,14 @@ module Danger
|
|
47
73
|
def validates_as_gitlab_pr?(env)
|
48
74
|
["GITLAB_REPO_SLUG", "GITLAB_PULL_REQUEST_ID", "GITLAB_REPO_URL"].all? { |x| env[x] && !env[x].empty? }
|
49
75
|
end
|
76
|
+
|
77
|
+
def validates_as_bitbucket_cloud_pr?(env)
|
78
|
+
["BITBUCKET_REPO_SLUG", "BITBUCKET_BRANCH_NAME", "BITBUCKET_REPO_URL"].all? { |x| env[x] && !env[x].empty? }
|
79
|
+
end
|
80
|
+
|
81
|
+
def validates_as_bitbucket_server_pr?(env)
|
82
|
+
["BITBUCKETSERVER_REPO_SLUG", "BITBUCKETSERVER_PULL_REQUEST_ID", "BITBUCKETSERVER_REPO_URL"].all? { |x| env[x] && !env[x].empty? }
|
83
|
+
end
|
50
84
|
end
|
51
85
|
|
52
86
|
def self.validates_as_ci?(env)
|
@@ -54,22 +88,25 @@ module Danger
|
|
54
88
|
end
|
55
89
|
|
56
90
|
def self.validates_as_pr?(env)
|
57
|
-
validates_as_github_pr?(env) || validates_as_gitlab_pr?(env)
|
91
|
+
validates_as_github_pr?(env) || validates_as_gitlab_pr?(env) || validates_as_bitbucket_cloud_pr?(env) || validates_as_bitbucket_server_pr?(env)
|
58
92
|
end
|
59
93
|
|
60
94
|
def supported_request_sources
|
61
|
-
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]
|
95
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab, Danger::RequestSources::BitbucketCloud, Danger::RequestSources::BitbucketServer]
|
62
96
|
end
|
63
97
|
|
64
98
|
def initialize(env)
|
65
99
|
# NB: Unfortunately TeamCity doesn't provide these variables
|
66
100
|
# automatically so you have to add these variables manually to your
|
67
101
|
# project or build configuration
|
68
|
-
|
69
102
|
if self.class.validates_as_github_pr?(env)
|
70
103
|
extract_github_variables!(env)
|
71
104
|
elsif self.class.validates_as_gitlab_pr?(env)
|
72
105
|
extract_gitlab_variables!(env)
|
106
|
+
elsif self.class.validates_as_bitbucket_cloud_pr?(env)
|
107
|
+
extract_bitbucket_variables!(env)
|
108
|
+
elsif self.class.validates_as_bitbucket_server_pr?(env)
|
109
|
+
extract_bitbucket_server_variables!(env)
|
73
110
|
end
|
74
111
|
end
|
75
112
|
|
@@ -86,5 +123,28 @@ module Danger
|
|
86
123
|
self.pull_request_id = env["GITLAB_PULL_REQUEST_ID"].to_i
|
87
124
|
self.repo_url = env["GITLAB_REPO_URL"]
|
88
125
|
end
|
126
|
+
|
127
|
+
def extract_bitbucket_variables!(env)
|
128
|
+
self.repo_slug = env["BITBUCKET_REPO_SLUG"]
|
129
|
+
self.pull_request_id = bitbucket_pr_from_env(env)
|
130
|
+
self.repo_url = env["BITBUCKET_REPO_URL"]
|
131
|
+
end
|
132
|
+
|
133
|
+
def extract_bitbucket_server_variables!(env)
|
134
|
+
self.repo_slug = env["BITBUCKETSERVER_REPO_SLUG"]
|
135
|
+
self.pull_request_id = env["BITBUCKETSERVER_PULL_REQUEST_ID"].to_i
|
136
|
+
self.repo_url = env["BITBUCKETSERVER_REPO_URL"]
|
137
|
+
end
|
138
|
+
|
139
|
+
# This is a little hacky, because Bitbucket doesn't provide us a PR id
|
140
|
+
def bitbucket_pr_from_env(env)
|
141
|
+
branch_name = env["BITBUCKET_BRANCH_NAME"]
|
142
|
+
repo_slug = env["BITBUCKET_REPO_SLUG"]
|
143
|
+
begin
|
144
|
+
Danger::RequestSources::BitbucketCloudAPI.new(repo_slug, nil, branch_name, env).pull_request_id
|
145
|
+
rescue
|
146
|
+
raise "Failed to find a pull request for branch \"#{branch_name}\" on Bitbucket."
|
147
|
+
end
|
148
|
+
end
|
89
149
|
end
|
90
150
|
end
|
@@ -223,7 +223,7 @@ module Danger
|
|
223
223
|
else
|
224
224
|
formatted
|
225
225
|
end
|
226
|
-
rows = violations[key]
|
226
|
+
rows = violations[key].uniq
|
227
227
|
print_list(title, rows)
|
228
228
|
end
|
229
229
|
|
@@ -246,10 +246,10 @@ module Danger
|
|
246
246
|
violations = violation_report
|
247
247
|
|
248
248
|
env.request_source.update_pull_request!(
|
249
|
-
warnings: violations[:warnings],
|
250
|
-
errors: violations[:errors],
|
251
|
-
messages: violations[:messages],
|
252
|
-
markdowns: status_report[:markdowns],
|
249
|
+
warnings: violations[:warnings].uniq,
|
250
|
+
errors: violations[:errors].uniq,
|
251
|
+
messages: violations[:messages].uniq,
|
252
|
+
markdowns: status_report[:markdowns].uniq,
|
253
253
|
danger_id: danger_id,
|
254
254
|
new_comment: new_comment
|
255
255
|
)
|
@@ -17,6 +17,18 @@ module Danger
|
|
17
17
|
other.line == line
|
18
18
|
end
|
19
19
|
|
20
|
+
def hash
|
21
|
+
h = 1
|
22
|
+
h = h * 31 + message.hash
|
23
|
+
h = h * 17 + file.hash
|
24
|
+
h = h * 17 + line.hash
|
25
|
+
h
|
26
|
+
end
|
27
|
+
|
28
|
+
def eql?(other)
|
29
|
+
return self == other
|
30
|
+
end
|
31
|
+
|
20
32
|
# @return [Boolean] returns true if is a file or line, false otherwise
|
21
33
|
def inline?
|
22
34
|
file || line
|
@@ -19,6 +19,19 @@ module Danger
|
|
19
19
|
other.line == line
|
20
20
|
end
|
21
21
|
|
22
|
+
def hash
|
23
|
+
h = 1
|
24
|
+
h = h * 31 + message.hash
|
25
|
+
h = h * 13 + sticky.hash
|
26
|
+
h = h * 17 + file.hash
|
27
|
+
h = h * 17 + line.hash
|
28
|
+
h
|
29
|
+
end
|
30
|
+
|
31
|
+
def eql?(other)
|
32
|
+
return self == other
|
33
|
+
end
|
34
|
+
|
22
35
|
# @return [Boolean] returns true if is a file or line, false otherwise
|
23
36
|
def inline?
|
24
37
|
file || line
|
@@ -20,8 +20,7 @@ module Danger
|
|
20
20
|
self.ci_source = ci_source
|
21
21
|
self.environment = environment
|
22
22
|
|
23
|
-
|
24
|
-
@api = BitbucketCloudAPI.new(project, slug, ci_source.pull_request_id, environment)
|
23
|
+
@api = BitbucketCloudAPI.new(ci_source.repo_slug, ci_source.pull_request_id, nil, environment)
|
25
24
|
end
|
26
25
|
|
27
26
|
def validates_as_ci?
|
@@ -5,13 +5,13 @@ require "danger/helpers/comments_helper"
|
|
5
5
|
module Danger
|
6
6
|
module RequestSources
|
7
7
|
class BitbucketCloudAPI
|
8
|
-
attr_accessor :
|
8
|
+
attr_accessor :project, :slug, :pull_request_id
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(repo_slug, pull_request_id, branch_name, environment)
|
11
11
|
@username = environment["DANGER_BITBUCKETCLOUD_USERNAME"]
|
12
12
|
@password = environment["DANGER_BITBUCKETCLOUD_PASSWORD"]
|
13
|
-
self.
|
14
|
-
self.
|
13
|
+
self.project, self.slug = repo_slug.split("/")
|
14
|
+
self.pull_request_id = pull_request_id || fetch_pr_from_branch(branch_name)
|
15
15
|
end
|
16
16
|
|
17
17
|
def inspect
|
@@ -51,6 +51,27 @@ module Danger
|
|
51
51
|
|
52
52
|
private
|
53
53
|
|
54
|
+
def base_url(version)
|
55
|
+
"https://api.bitbucket.org/#{version}.0/repositories/#{project}/#{slug}/pullrequests"
|
56
|
+
end
|
57
|
+
|
58
|
+
def pr_api_endpoint
|
59
|
+
"#{base_url(2)}/#{pull_request_id}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def pr_api_endpoint_v1
|
63
|
+
"#{base_url(1)}/#{pull_request_id}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def prs_api_endpoint(branch_name)
|
67
|
+
"#{base_url(2)}?q=source.branch.name=\"#{branch_name}\""
|
68
|
+
end
|
69
|
+
|
70
|
+
def fetch_pr_from_branch(branch_name)
|
71
|
+
uri = URI(URI.escape(prs_api_endpoint(branch_name)))
|
72
|
+
fetch_json(uri)[:values][0][:id]
|
73
|
+
end
|
74
|
+
|
54
75
|
def fetch_json(uri)
|
55
76
|
req = Net::HTTP::Get.new(uri.request_uri, { "Content-Type" => "application/json" })
|
56
77
|
req.basic_auth @username, @password
|
@@ -49,8 +49,12 @@ module Danger
|
|
49
49
|
def setup_danger_branches
|
50
50
|
base_branch = self.pr_json[:toRef][:id].sub("refs/heads/", "")
|
51
51
|
base_commit = self.pr_json[:toRef][:latestCommit]
|
52
|
+
# Support for older versions of Bitbucket Server
|
53
|
+
base_commit = self.pr_json[:toRef][:latestChangeset] if self.pr_json[:fromRef].key? :latestChangeset
|
52
54
|
head_branch = self.pr_json[:fromRef][:id].sub("refs/heads/", "")
|
53
55
|
head_commit = self.pr_json[:fromRef][:latestCommit]
|
56
|
+
# Support for older versions of Bitbucket Server
|
57
|
+
head_commit = self.pr_json[:fromRef][:latestChangeset] if self.pr_json[:fromRef].key? :latestChangeset
|
54
58
|
|
55
59
|
# Next, we want to ensure that we have a version of the current branch at a known location
|
56
60
|
scm.ensure_commitish_exists_on_branch! base_branch, base_commit
|
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: 5.5.
|
4
|
+
version: 5.5.7
|
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:
|
12
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -487,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
487
487
|
version: '0'
|
488
488
|
requirements: []
|
489
489
|
rubyforge_project:
|
490
|
-
rubygems_version: 2.
|
490
|
+
rubygems_version: 2.6.14
|
491
491
|
signing_key:
|
492
492
|
specification_version: 4
|
493
493
|
summary: Like Unit Tests, but for your Team Culture.
|