Class: Danger::RequestSources::BitbucketServer
Constant Summary
RequestSource::DANGER_REPO_NAME
Instance Attribute Summary collapse
#ci_source, #environment, #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) ⇒ BitbucketServer
constructor
A new instance of BitbucketServer.
-
#inline_violations_group(warnings: [], errors: [], messages: [], markdowns: []) ⇒ Object
-
#main_violations_group(warnings: [], errors: [], messages: [], markdowns: []) ⇒ Object
-
#organisation ⇒ Object
-
#scm ⇒ Object
-
#setup_danger_branches ⇒ Object
-
#update_pr_build_status(status, build_job_link, description) ⇒ 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, source_name, #update_build_status
Constructor Details
#initialize(ci_source, environment) ⇒ BitbucketServer
Returns a new instance of BitbucketServer.
32
33
34
35
36
37
38
39
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 32
def initialize(ci_source, environment)
self.ci_source = ci_source
self.environment = environment
project, slug = ci_source.repo_slug.split("/")
@api = BitbucketServerAPI.new(project, slug, ci_source.pull_request_id, environment)
@code_insights = CodeInsightsAPI.new(project, slug, environment)
end
|
Instance Attribute Details
#pr_json ⇒ Object
Returns the value of attribute pr_json.
12
13
14
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 12
def pr_json
@pr_json
end
|
Class Method Details
.env_vars ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 14
def self.env_vars
[
"DANGER_BITBUCKETSERVER_USERNAME",
"DANGER_BITBUCKETSERVER_PASSWORD",
"DANGER_BITBUCKETSERVER_HOST"
]
end
|
.optional_env_vars ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 22
def self.optional_env_vars
[
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_KEY",
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_TITLE",
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_DESCRIPTION",
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_LOGO_URL",
"DANGER_BITBUCKETSERVER_VERIFY_SSL"
]
end
|
Instance Method Details
131
132
133
134
135
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 131
def (danger_id: "danger")
@api..each do |c|
@api.(c[:id], c[:version]) if c[:text] =~ /generated_by_#{danger_id}/
end
end
|
#fetch_details ⇒ Object
58
59
60
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 58
def fetch_details
self.pr_json = @api.fetch_pr_json
end
|
#host ⇒ Object
54
55
56
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 54
def host
@host ||= @api.host
end
|
#inline_violations_group(warnings: [], errors: [], messages: [], markdowns: []) ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 146
def inline_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
cmp = proc do |a, b|
next -1 unless a.file && a.line
next 1 unless b.file && b.line
next a.line <=> b.line if a.file == b.file
next a.file <=> b.file
end
{
warnings: warnings.select(&:inline?).sort(&cmp),
errors: errors.select(&:inline?).sort(&cmp),
messages: messages.select(&:inline?).sort(&cmp),
markdowns: markdowns.select(&:inline?).sort(&cmp)
}
end
|
#main_violations_group(warnings: [], errors: [], messages: [], markdowns: []) ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 137
def main_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
{
warnings: warnings.reject(&:inline?),
errors: errors.reject(&:inline?),
messages: messages.reject(&:inline?),
markdowns: markdowns.reject(&:inline?)
}
end
|
#organisation ⇒ Object
82
83
84
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 82
def organisation
nil
end
|
#scm ⇒ Object
50
51
52
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 50
def scm
@scm ||= GitRepo.new
end
|
#setup_danger_branches ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 62
def setup_danger_branches
base_branch = self.pr_json[:toRef][:id].sub("refs/heads/", "")
base_commit = self.pr_json[:toRef][:latestCommit]
base_commit = self.pr_json[:toRef][:latestChangeset] if self.pr_json[:fromRef].key? :latestChangeset
head_branch = self.pr_json[:fromRef][:id].sub("refs/heads/", "")
head_commit = self.pr_json[:fromRef][:latestCommit]
head_commit = self.pr_json[:fromRef][:latestChangeset] if self.pr_json[:fromRef].key? :latestChangeset
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
|
#update_pr_build_status(status, build_job_link, description) ⇒ Object
164
165
166
167
168
169
170
171
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 164
def update_pr_build_status(status, build_job_link, description)
changeset = self.pr_json[:fromRef][:latestCommit]
changeset = self.pr_json[:fromRef][:latestChangeset] if self.pr_json[:fromRef].key? :latestChangeset
puts "Changeset: " + changeset
puts self.pr_json.to_json
@api.update_pr_build_status(status, changeset, build_job_link, description)
end
|
#update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger", new_comment: false, remove_previous_comments: false) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
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
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 86
def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger", new_comment: false, remove_previous_comments: false)
(danger_id: danger_id) if ! ||
if @code_insights.ready?
inline_violations = inline_violations_group(warnings: warnings, errors: errors, messages: messages)
inline_warnings = inline_violations[:warnings] || []
inline_errors = inline_violations[:errors] || []
inline_messages = inline_violations[:messages] || []
head_commit = self.pr_json[:fromRef][:latestCommit]
@code_insights.send_report(head_commit,
inline_warnings,
inline_errors,
inline_messages)
end
if @code_insights.ready?
main_violations = main_violations_group(warnings: warnings, errors: errors, messages: messages)
warnings = main_violations[:warnings] || []
errors = main_violations[:errors] || []
messages = main_violations[:messages] || []
markdowns = main_violations[:markdowns] || []
end
= (warnings.count > 0 || errors.count > 0 || messages.count > 0 || markdowns.count > 0)
if
= generate_description(warnings: warnings,
errors: errors)
+= "\n\n"
+= (warnings: warnings,
errors: errors,
messages: messages,
markdowns: markdowns,
previous_violations: {},
danger_id: danger_id,
template: "bitbucket_server")
@api.()
end
end
|
#validates_as_api_source? ⇒ Boolean
46
47
48
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 46
def validates_as_api_source?
@api.credentials_given?
end
|
#validates_as_ci? ⇒ Boolean
41
42
43
44
|
# File 'lib/danger/request_sources/bitbucket_server.rb', line 41
def validates_as_ci?
true
end
|