Class: Danger::RequestSources::BitbucketCloud
Constant Summary
RequestSource::DANGER_REPO_NAME
Instance Attribute Summary collapse
#ci_source, #ignored_violations
Class Method Summary
collapse
Instance Method Summary
collapse
-
#delete_old_comments(danger_id: "danger") ⇒ Object
-
#fetch_details ⇒ Object
-
#host ⇒ Object
-
#initialize(ci_source, environment) ⇒ BitbucketCloud
constructor
A new instance of BitbucketCloud.
-
#organisation ⇒ Object
-
#scm ⇒ Object
-
#setup_danger_branches ⇒ Object
-
#update_inline_comments_for_kind!(kind, messages, danger_id: "danger") ⇒ Object
-
#update_pr_by_line!(message_groups:, danger_id: "danger", new_comment: false, remove_previous_comments: false) ⇒ Object
-
#update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger", new_comment: false, remove_previous_comments: false) ⇒ Object
-
#validates_as_api_source? ⇒ Boolean
-
#validates_as_ci? ⇒ Boolean
#apply_template, #generate_comment, #generate_description, #generate_inline_comment_body, #generate_inline_markdown_body, #generate_message_group_comment, #markdown_link_to_message, #markdown_parser, #messages_are_equivalent, #process_markdown, #random_compliment, #table
#parse_comment, #parse_message_from_row, #parse_tables_from_comment, #table_kind_from_title, #violations_from_table
available_request_sources, available_source_names_and_envs, #file_url, inherited, #inspect, source_name, #update_build_status
Constructor Details
#initialize(ci_source, environment) ⇒ BitbucketCloud
Returns a new instance of BitbucketCloud.
23
24
25
26
27
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 23
def initialize(ci_source, environment)
self.ci_source = ci_source
@api = BitbucketCloudAPI.new(ci_source.repo_slug, ci_source.pull_request_id, nil, environment)
end
|
Instance Attribute Details
#pr_json ⇒ Object
Returns the value of attribute pr_json.
9
10
11
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 9
def pr_json
@pr_json
end
|
Class Method Details
.env_vars ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 11
def self.env_vars
[
"DANGER_BITBUCKETCLOUD_USERNAME",
"DANGER_BITBUCKETCLOUD_UUID",
"DANGER_BITBUCKETCLOUD_PASSWORD"
]
end
|
.optional_env_vars ⇒ Object
19
20
21
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 19
def self.optional_env_vars
["DANGER_BITBUCKETCLOUD_OAUTH_KEY", "DANGER_BITBUCKETCLOUD_OAUTH_SECRET"]
end
|
Instance Method Details
179
180
181
182
183
184
185
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 179
def (danger_id: "danger")
@api..each do |c|
next if c[:user][:uuid] != @api.my_uuid
@api.(c[:id]) if c[:content][:raw] =~ /generated_by_#{danger_id}/
end
end
|
#fetch_details ⇒ Object
46
47
48
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 46
def fetch_details
self.pr_json = @api.fetch_pr_json
end
|
#host ⇒ Object
42
43
44
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 42
def host
@host ||= @api.host
end
|
#organisation ⇒ Object
66
67
68
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 66
def organisation
nil
end
|
#scm ⇒ Object
38
39
40
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 38
def scm
@scm ||= GitRepo.new
end
|
#setup_danger_branches ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 50
def setup_danger_branches
base_branch = self.pr_json[:destination][:branch][:name]
base_commit = self.pr_json[:destination][:commit][:hash]
head_branch = self.pr_json[:source][:branch][:name]
head_commit = self.pr_json[:source][:commit][:hash]
scm.ensure_commitish_exists_on_branch! base_branch, base_commit
self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
scm.ensure_commitish_exists_on_branch! head_branch, head_commit
self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
end
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 153
def (kind, messages, danger_id: "danger")
puts "update_inline_comments_for_kind!"
emoji = { warnings: "warning", errors: "no_entry_sign", messages: "book" }[kind]
messages.reject do |message|
next false unless message.file && message.line
body = ""
if kind == :markdown
body = generate_inline_markdown_body(message,
danger_id: danger_id,
template: "bitbucket_server")
else
body = generate_inline_comment_body(emoji, message,
danger_id: danger_id,
template: "bitbucket_server")
end
@api.(body, file: message.file, line: message.line)
true
end
end
|
#update_pr_by_line!(message_groups:, danger_id: "danger", new_comment: false, remove_previous_comments: false) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 99
def update_pr_by_line!(message_groups:,
danger_id: "danger",
new_comment: false,
remove_previous_comments: false)
puts "update_pr_by_line!(new_comment=#{}, remove_previous_comments=#{})"
if ! ||
puts "delete_old_comments(danger_id=#{danger_id})"
(danger_id: danger_id)
end
summary_body = generate_description(warnings: message_groups.fake_warnings_array,
errors: message_groups.fake_errors_array,
template: "bitbucket_server")
summary_body += "\n\n"
summary_group = message_groups.first
if summary_group && summary_group.file.nil? && summary_group.line.nil?
message_groups.shift
else
summary_group = MessageGroup.new(file: nil, line: nil)
end
summary_body += (
message_group: summary_group,
danger_id: danger_id,
template: "bitbucket_server_message_group"
)
puts "summary_body:"
puts summary_body
@api.(summary_body)
message_groups.each do |message_group|
body = (message_group: message_group,
danger_id: danger_id,
template: "bitbucket_server_message_group")
puts "post_comment to file #{file} line #{line}:"
puts body
@api.(body,
file: message_group.file,
line: message_group.line)
end
end
|
#update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger", new_comment: false, remove_previous_comments: false) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 70
def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger", new_comment: false, remove_previous_comments: false)
puts "update_pull_request(warnings=#{warnings.size}, messages=#{messages.size}, markdowns=#{markdowns.size}, new_comment=#{}, remove_previous_comments=#{})"
(danger_id: danger_id) if ! ||
warnings = (:warnings, warnings, danger_id: danger_id)
errors = (:errors, errors, danger_id: danger_id)
messages = (:messages, messages, danger_id: danger_id)
markdowns = (:markdowns, markdowns, danger_id: danger_id)
= (warnings.count.positive? || errors.count.positive? || messages.count.positive? || markdowns.count.positive?)
puts "has_comments=#{}"
if
= generate_description(warnings: warnings, errors: errors, template: "bitbucket_server")
+= "\n\n"
+= (warnings: warnings,
errors: errors,
messages: messages,
markdowns: markdowns,
previous_violations: {},
danger_id: danger_id,
template: "bitbucket_server")
puts "comment=#{}"
@api.()
end
end
|
#validates_as_api_source? ⇒ Boolean
34
35
36
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 34
def validates_as_api_source?
@api.credentials_given?
end
|
#validates_as_ci? ⇒ Boolean
29
30
31
32
|
# File 'lib/danger/request_sources/bitbucket_cloud.rb', line 29
def validates_as_ci?
true
end
|