danger-additional-logging 0.0.1
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 +7 -0
- data/LICENSE +22 -0
- data/README.md +93 -0
- data/bin/danger +5 -0
- data/lib/assets/DangerfileTemplate +13 -0
- data/lib/danger/ci_source/appcenter.rb +55 -0
- data/lib/danger/ci_source/appcircle.rb +83 -0
- data/lib/danger/ci_source/appveyor.rb +64 -0
- data/lib/danger/ci_source/azure_pipelines.rb +61 -0
- data/lib/danger/ci_source/bamboo.rb +41 -0
- data/lib/danger/ci_source/bitbucket_pipelines.rb +37 -0
- data/lib/danger/ci_source/bitrise.rb +78 -0
- data/lib/danger/ci_source/buddybuild.rb +62 -0
- data/lib/danger/ci_source/buildkite.rb +51 -0
- data/lib/danger/ci_source/ci_source.rb +37 -0
- data/lib/danger/ci_source/circle.rb +94 -0
- data/lib/danger/ci_source/circle_api.rb +51 -0
- data/lib/danger/ci_source/cirrus.rb +31 -0
- data/lib/danger/ci_source/code_build.rb +71 -0
- data/lib/danger/ci_source/codefresh.rb +47 -0
- data/lib/danger/ci_source/codemagic.rb +58 -0
- data/lib/danger/ci_source/codeship.rb +44 -0
- data/lib/danger/ci_source/concourse.rb +60 -0
- data/lib/danger/ci_source/custom_ci_with_github.rb +49 -0
- data/lib/danger/ci_source/dotci.rb +50 -0
- data/lib/danger/ci_source/drone.rb +71 -0
- data/lib/danger/ci_source/github_actions.rb +44 -0
- data/lib/danger/ci_source/gitlab_ci.rb +89 -0
- data/lib/danger/ci_source/jenkins.rb +148 -0
- data/lib/danger/ci_source/local_git_repo.rb +117 -0
- data/lib/danger/ci_source/local_only_git_repo.rb +44 -0
- data/lib/danger/ci_source/screwdriver.rb +48 -0
- data/lib/danger/ci_source/semaphore.rb +37 -0
- data/lib/danger/ci_source/support/commits.rb +19 -0
- data/lib/danger/ci_source/support/find_repo_info_from_logs.rb +35 -0
- data/lib/danger/ci_source/support/find_repo_info_from_url.rb +43 -0
- data/lib/danger/ci_source/support/local_pull_request.rb +14 -0
- data/lib/danger/ci_source/support/no_pull_request.rb +7 -0
- data/lib/danger/ci_source/support/no_repo_info.rb +5 -0
- data/lib/danger/ci_source/support/pull_request_finder.rb +190 -0
- data/lib/danger/ci_source/support/remote_pull_request.rb +15 -0
- data/lib/danger/ci_source/support/repo_info.rb +10 -0
- data/lib/danger/ci_source/surf.rb +37 -0
- data/lib/danger/ci_source/teamcity.rb +163 -0
- data/lib/danger/ci_source/travis.rb +51 -0
- data/lib/danger/ci_source/xcode_cloud.rb +38 -0
- data/lib/danger/ci_source/xcode_server.rb +48 -0
- data/lib/danger/clients/rubygems_client.rb +14 -0
- data/lib/danger/commands/dangerfile/gem.rb +43 -0
- data/lib/danger/commands/dangerfile/init.rb +30 -0
- data/lib/danger/commands/dry_run.rb +54 -0
- data/lib/danger/commands/init.rb +297 -0
- data/lib/danger/commands/init_helpers/interviewer.rb +92 -0
- data/lib/danger/commands/local.rb +83 -0
- data/lib/danger/commands/local_helpers/http_cache.rb +38 -0
- data/lib/danger/commands/local_helpers/local_setup.rb +48 -0
- data/lib/danger/commands/local_helpers/pry_setup.rb +32 -0
- data/lib/danger/commands/plugins/plugin_json.rb +44 -0
- data/lib/danger/commands/plugins/plugin_lint.rb +52 -0
- data/lib/danger/commands/plugins/plugin_readme.rb +42 -0
- data/lib/danger/commands/pr.rb +93 -0
- data/lib/danger/commands/runner.rb +94 -0
- data/lib/danger/commands/staging.rb +53 -0
- data/lib/danger/commands/systems.rb +41 -0
- data/lib/danger/comment_generators/bitbucket_server.md.erb +20 -0
- data/lib/danger/comment_generators/bitbucket_server_inline.md.erb +15 -0
- data/lib/danger/comment_generators/bitbucket_server_message_group.md.erb +12 -0
- data/lib/danger/comment_generators/github.md.erb +55 -0
- data/lib/danger/comment_generators/github_inline.md.erb +26 -0
- data/lib/danger/comment_generators/gitlab.md.erb +40 -0
- data/lib/danger/comment_generators/gitlab_inline.md.erb +21 -0
- data/lib/danger/comment_generators/vsts.md.erb +20 -0
- data/lib/danger/comment_generators/vsts_inline.md.erb +17 -0
- data/lib/danger/core_ext/file_list.rb +18 -0
- data/lib/danger/core_ext/string.rb +20 -0
- data/lib/danger/danger_core/dangerfile.rb +348 -0
- data/lib/danger/danger_core/dangerfile_dsl.rb +29 -0
- data/lib/danger/danger_core/dangerfile_generator.rb +11 -0
- data/lib/danger/danger_core/environment_manager.rb +126 -0
- data/lib/danger/danger_core/executor.rb +91 -0
- data/lib/danger/danger_core/message_aggregator.rb +50 -0
- data/lib/danger/danger_core/message_group.rb +68 -0
- data/lib/danger/danger_core/messages/base.rb +57 -0
- data/lib/danger/danger_core/messages/markdown.rb +41 -0
- data/lib/danger/danger_core/messages/violation.rb +53 -0
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +142 -0
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +211 -0
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +274 -0
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +159 -0
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +264 -0
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +275 -0
- data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +43 -0
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +220 -0
- data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +191 -0
- data/lib/danger/danger_core/standard_error.rb +142 -0
- data/lib/danger/helpers/array_subclass.rb +61 -0
- data/lib/danger/helpers/comment.rb +32 -0
- data/lib/danger/helpers/comments_helper.rb +179 -0
- data/lib/danger/helpers/comments_parsing_helper.rb +71 -0
- data/lib/danger/helpers/emoji_mapper.rb +41 -0
- data/lib/danger/helpers/find_max_num_violations.rb +31 -0
- data/lib/danger/helpers/message_groups_array_helper.rb +31 -0
- data/lib/danger/plugin_support/gems_resolver.rb +77 -0
- data/lib/danger/plugin_support/plugin.rb +52 -0
- data/lib/danger/plugin_support/plugin_file_resolver.rb +30 -0
- data/lib/danger/plugin_support/plugin_linter.rb +162 -0
- data/lib/danger/plugin_support/plugin_parser.rb +199 -0
- data/lib/danger/plugin_support/templates/readme_table.html.erb +26 -0
- data/lib/danger/request_sources/bitbucket_cloud.rb +169 -0
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +181 -0
- data/lib/danger/request_sources/bitbucket_server.rb +210 -0
- data/lib/danger/request_sources/bitbucket_server_api.rb +129 -0
- data/lib/danger/request_sources/code_insights_api.rb +142 -0
- data/lib/danger/request_sources/github/github.rb +535 -0
- data/lib/danger/request_sources/github/github_review.rb +127 -0
- data/lib/danger/request_sources/github/github_review_resolver.rb +17 -0
- data/lib/danger/request_sources/github/github_review_unsupported.rb +23 -0
- data/lib/danger/request_sources/gitlab.rb +557 -0
- data/lib/danger/request_sources/local_only.rb +50 -0
- data/lib/danger/request_sources/request_source.rb +97 -0
- data/lib/danger/request_sources/support/get_ignored_violation.rb +17 -0
- data/lib/danger/request_sources/vsts.rb +278 -0
- data/lib/danger/request_sources/vsts_api.rb +172 -0
- data/lib/danger/scm_source/git_repo.rb +198 -0
- data/lib/danger/version.rb +4 -0
- data/lib/danger.rb +45 -0
- metadata +351 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
require "danger/plugin_support/plugin"
|
|
2
|
+
|
|
3
|
+
module Danger
|
|
4
|
+
# Handles interacting with GitLab inside a Dangerfile. Provides a few functions which wrap `mr_json` and also
|
|
5
|
+
# through a few standard functions to simplify your code.
|
|
6
|
+
#
|
|
7
|
+
# @example Warn when an MR is classed as work in progress.
|
|
8
|
+
#
|
|
9
|
+
# warn "MR is classed as Work in Progress" if gitlab.mr_title.include? "[WIP]"
|
|
10
|
+
#
|
|
11
|
+
# @example Declare a MR to be simple to avoid specific Danger rules.
|
|
12
|
+
#
|
|
13
|
+
# declared_trivial = (gitlab.mr_title + gitlab.mr_body).include?("#trivial")
|
|
14
|
+
#
|
|
15
|
+
# @example Ensure that labels have been applied to the MR.
|
|
16
|
+
#
|
|
17
|
+
# failure "Please add labels to this MR" if gitlab.mr_labels.empty?
|
|
18
|
+
#
|
|
19
|
+
# @example Ensure that all MRs have an assignee.
|
|
20
|
+
#
|
|
21
|
+
# warn "This MR does not have any assignees yet." unless gitlab.mr_json["assignee"]
|
|
22
|
+
#
|
|
23
|
+
# @example Ensure there is a summary for a MR.
|
|
24
|
+
#
|
|
25
|
+
# failure "Please provide a summary in the Merge Request description" if gitlab.mr_body.length < 5
|
|
26
|
+
#
|
|
27
|
+
# @example Only accept MRs to the develop branch.
|
|
28
|
+
#
|
|
29
|
+
# failure "Please re-submit this MR to develop, we may have already fixed your issue." if gitlab.branch_for_merge != "develop"
|
|
30
|
+
#
|
|
31
|
+
# @example Note when MRs don't reference a milestone, make the warning stick around on subsequent runs
|
|
32
|
+
#
|
|
33
|
+
# has_milestone = gitlab.mr_json["milestone"] != nil
|
|
34
|
+
# warn("This MR does not refer to an existing milestone", sticky: true) unless has_milestone
|
|
35
|
+
#
|
|
36
|
+
# @example Note when a MR cannot be manually merged
|
|
37
|
+
#
|
|
38
|
+
# can_merge = gitlab.mr_json["mergeable"]
|
|
39
|
+
# warn("This MR cannot be merged yet.") unless can_merge
|
|
40
|
+
#
|
|
41
|
+
# @example Highlight when a celebrity makes a merge request.
|
|
42
|
+
#
|
|
43
|
+
# message "Welcome, Danger." if gitlab.mr_author == "dangermcshane"
|
|
44
|
+
#
|
|
45
|
+
# @example Send a message with links to a collection of specific files.
|
|
46
|
+
#
|
|
47
|
+
# if git.modified_files.include? "config/*.js"
|
|
48
|
+
# config_files = git.modified_files.select { |path| path.include? "config/" }
|
|
49
|
+
# message "This MR changes #{ gitlab.html_link(config_files) }"
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# @example Highlight with a clickable link if a Package.json is changed.
|
|
53
|
+
#
|
|
54
|
+
# warn "#{gitlab.html_link("Package.json")} was edited." if git.modified_files.include? "Package.json"
|
|
55
|
+
#
|
|
56
|
+
# @example Select a random group member as assignee if no assignee is selected
|
|
57
|
+
#
|
|
58
|
+
# if gitlab.mr_json["assignee"].nil?
|
|
59
|
+
# reviewer = gitlab.api.group_members(gitlab.api.merge_request_approvals(project_id, mr_id).to_hash["approver_groups"].first["group"]["id"]).sample
|
|
60
|
+
# if gitlab.api.group_members(gitlab.api.merge_request_approvals(project_id, mr_id).to_hash["approver_groups"].first["group"]["id"]).length > 1
|
|
61
|
+
# while reviewer.to_hash["id"] == gitlab.mr_json["author"]["id"] do
|
|
62
|
+
# reviewer = gitlab.api.group_members(gitlab.api.merge_request_approvals(project_id, mr_id).to_hash["approver_groups"].first["group"]["id"]).sample
|
|
63
|
+
# end
|
|
64
|
+
# end
|
|
65
|
+
# message "Reviewer roulete rolled for: #{reviewer.to_hash['name']} (@#{reviewer.to_hash['username']})"
|
|
66
|
+
# gitlab.api.update_merge_request(project_id, mr_id, { assignee_id: reviewer.to_hash["id"] })
|
|
67
|
+
# end
|
|
68
|
+
#
|
|
69
|
+
#
|
|
70
|
+
# @see danger/danger
|
|
71
|
+
# @tags core, gitlab
|
|
72
|
+
#
|
|
73
|
+
class DangerfileGitLabPlugin < Plugin
|
|
74
|
+
# So that this init can fail.
|
|
75
|
+
def self.new(dangerfile)
|
|
76
|
+
return nil if dangerfile.env.request_source.class != Danger::RequestSources::GitLab
|
|
77
|
+
|
|
78
|
+
super
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# The instance name used in the Dangerfile
|
|
82
|
+
# @return [String]
|
|
83
|
+
#
|
|
84
|
+
def self.instance_name
|
|
85
|
+
"gitlab"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def initialize(dangerfile)
|
|
89
|
+
super(dangerfile)
|
|
90
|
+
|
|
91
|
+
@gitlab = dangerfile.env.request_source
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# @!group MR Metadata
|
|
95
|
+
# The title of the Merge Request
|
|
96
|
+
# @return [String]
|
|
97
|
+
#
|
|
98
|
+
def mr_title
|
|
99
|
+
@gitlab.mr_json.title.to_s
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# @!group MR Metadata
|
|
103
|
+
# The body text of the Merge Request
|
|
104
|
+
# @return [String]
|
|
105
|
+
#
|
|
106
|
+
def mr_body
|
|
107
|
+
@gitlab.mr_json.description.to_s
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# @!group MR Metadata
|
|
111
|
+
# The username of the author of the Merge Request
|
|
112
|
+
# @return [String]
|
|
113
|
+
#
|
|
114
|
+
def mr_author
|
|
115
|
+
@gitlab.mr_json.author.username.to_s
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# @!group MR Metadata
|
|
119
|
+
# The labels assigned to the Merge Request
|
|
120
|
+
# @return [String]
|
|
121
|
+
#
|
|
122
|
+
def mr_labels
|
|
123
|
+
@gitlab.mr_json.labels
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# @!group MR Content
|
|
127
|
+
# The unified diff produced by GitLab for this MR
|
|
128
|
+
# see [Unified diff](https://en.wikipedia.org/wiki/Diff_utility#Unified_format)
|
|
129
|
+
# @return [String]
|
|
130
|
+
#
|
|
131
|
+
def mr_diff
|
|
132
|
+
@gitlab.mr_diff
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# @!group MR Changes
|
|
136
|
+
# The array of changes
|
|
137
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
138
|
+
#
|
|
139
|
+
def mr_changes
|
|
140
|
+
@gitlab.mr_changes.changes
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @!group MR Closes issues
|
|
144
|
+
# The array of issues that this MR closes
|
|
145
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
146
|
+
#
|
|
147
|
+
def mr_closes_issues
|
|
148
|
+
@gitlab.mr_closes_issues
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# @!group MR Commit Metadata
|
|
152
|
+
# The branch to which the MR is going to be merged into
|
|
153
|
+
# @deprecated Please use {#branch_for_base} instead
|
|
154
|
+
# @return [String]
|
|
155
|
+
#
|
|
156
|
+
def branch_for_merge
|
|
157
|
+
branch_for_base
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# @!group MR Commit Metadata
|
|
161
|
+
# The branch to which the MR is going to be merged into.
|
|
162
|
+
# @return [String]
|
|
163
|
+
#
|
|
164
|
+
def branch_for_base
|
|
165
|
+
@gitlab.mr_json.target_branch
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# @!group MR Commit Metadata
|
|
169
|
+
# The branch to which the MR is going to be merged from.
|
|
170
|
+
# @return [String]
|
|
171
|
+
#
|
|
172
|
+
def branch_for_head
|
|
173
|
+
@gitlab.mr_json.source_branch
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# @!group MR Commit Metadata
|
|
177
|
+
# The base commit to which the MR is going to be merged as a parent
|
|
178
|
+
# @return [String]
|
|
179
|
+
#
|
|
180
|
+
def base_commit
|
|
181
|
+
@gitlab.mr_json.diff_refs.base_sha
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# @!group MR Commit Metadata
|
|
185
|
+
# The head commit to which the MR is requesting to be merged from
|
|
186
|
+
# @return [String]
|
|
187
|
+
#
|
|
188
|
+
def head_commit
|
|
189
|
+
@gitlab.mr_json.diff_refs.head_sha
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# @!group GitLab Misc
|
|
193
|
+
# The hash that represents the MR's JSON. See documentation for the
|
|
194
|
+
# structure [here](http://docs.gitlab.com/ce/api/merge_requests.html#get-single-mr)
|
|
195
|
+
# @return [Hash]
|
|
196
|
+
#
|
|
197
|
+
def mr_json
|
|
198
|
+
@gitlab.mr_json.to_hash
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# @!group GitLab Misc
|
|
202
|
+
# Provides access to the GitLab API client used inside Danger. Making
|
|
203
|
+
# it easy to use the GitLab API inside a Dangerfile. See the gitlab
|
|
204
|
+
# gem's [documentation](http://www.rubydoc.info/gems/gitlab/Gitlab/Client)
|
|
205
|
+
# for accessible methods.
|
|
206
|
+
# @return [GitLab::Client]
|
|
207
|
+
#
|
|
208
|
+
def api
|
|
209
|
+
@gitlab.client
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# @!group GitLab Misc
|
|
213
|
+
# Returns the web_url of the source project.
|
|
214
|
+
# @return [String]
|
|
215
|
+
#
|
|
216
|
+
def repository_web_url
|
|
217
|
+
@repository_web_url ||= begin
|
|
218
|
+
project = api.project(mr_json["source_project_id"])
|
|
219
|
+
project.web_url
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# @!group GitLab Misc
|
|
224
|
+
# Returns a list of HTML anchors for a file, or files in the head repository. An example would be:
|
|
225
|
+
# `<a href='https://gitlab.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/file.txt'>file.txt</a>`. It returns a string of multiple anchors if passed an array.
|
|
226
|
+
# @param [String or Array<String>] paths
|
|
227
|
+
# A list of strings to convert to gitlab anchors
|
|
228
|
+
# @param [Bool] full_path
|
|
229
|
+
# Shows the full path as the link's text, defaults to `true`.
|
|
230
|
+
#
|
|
231
|
+
# @return [String]
|
|
232
|
+
#
|
|
233
|
+
def html_link(paths, full_path: true)
|
|
234
|
+
paths = [paths] unless paths.kind_of?(Array)
|
|
235
|
+
commit = head_commit
|
|
236
|
+
|
|
237
|
+
paths = paths.map do |path|
|
|
238
|
+
url_path = path.start_with?("/") ? path : "/#{path}"
|
|
239
|
+
text = full_path ? path : File.basename(path)
|
|
240
|
+
create_link("#{repository_web_url}/blob/#{commit}#{url_path}", text)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
return paths.first if paths.count < 2
|
|
244
|
+
|
|
245
|
+
paths.first(paths.count - 1).join(", ") + " & " + paths.last
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# @!group Gitlab Misc
|
|
249
|
+
# Use to ignore inline messages which lay outside a diff's range, thereby not posting the comment.
|
|
250
|
+
# You can set hash to change behavior per each kinds. (ex. `{warning: true, error: false}`)
|
|
251
|
+
# @param [Bool] or [Hash<Symbol, Bool>] dismiss
|
|
252
|
+
# Ignore out of range inline messages, defaults to `true`
|
|
253
|
+
#
|
|
254
|
+
# @return [void]
|
|
255
|
+
def dismiss_out_of_range_messages(dismiss = true)
|
|
256
|
+
if dismiss.kind_of?(Hash)
|
|
257
|
+
@gitlab.dismiss_out_of_range_messages = dismiss
|
|
258
|
+
elsif dismiss.kind_of?(TrueClass)
|
|
259
|
+
@gitlab.dismiss_out_of_range_messages = true
|
|
260
|
+
elsif dismiss.kind_of?(FalseClass)
|
|
261
|
+
@gitlab.dismiss_out_of_range_messages = false
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
%i(title body author labels json diff).each do |suffix|
|
|
266
|
+
alias_method "pr_#{suffix}".to_sym, "mr_#{suffix}".to_sym
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
private
|
|
270
|
+
|
|
271
|
+
def create_link(href, text)
|
|
272
|
+
"<a href='#{href}'>#{text}</a>"
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require "danger/plugin_support/plugin"
|
|
2
|
+
|
|
3
|
+
# Danger
|
|
4
|
+
module Danger
|
|
5
|
+
# Handles interacting with local only plugin inside a Dangerfile.
|
|
6
|
+
# It is support plugin for dry_run command and does not expose any methods.
|
|
7
|
+
# But you can still use other plugins like git
|
|
8
|
+
#
|
|
9
|
+
# @example Check that added lines contains agreed form of words
|
|
10
|
+
#
|
|
11
|
+
# git.diff.each do |chunk|
|
|
12
|
+
# chunk.patch.lines.grep(/^\+/).each do |added_line|
|
|
13
|
+
# if added_line.gsub!(/(?<cancel>cancel)(?<rest>[^l[[:space:]][[:punct:]]]+)/i, '>>\k<cancel>-l-\k<rest><<')
|
|
14
|
+
# fail "Single 'L' for cancellation-alike words in '#{added_line}'"
|
|
15
|
+
# end
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# @see danger/danger
|
|
20
|
+
# @tags core, local_only
|
|
21
|
+
#
|
|
22
|
+
class DangerfileLocalOnlyPlugin < Plugin
|
|
23
|
+
# So that this init can fail.
|
|
24
|
+
def self.new(dangerfile)
|
|
25
|
+
return nil if dangerfile.env.request_source.class != Danger::RequestSources::LocalOnly
|
|
26
|
+
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def initialize(dangerfile)
|
|
31
|
+
super(dangerfile)
|
|
32
|
+
|
|
33
|
+
@local_repo = dangerfile.env.request_source
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The instance name used in the Dangerfile
|
|
37
|
+
# @return [String]
|
|
38
|
+
#
|
|
39
|
+
def self.instance_name
|
|
40
|
+
"local_repo"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
require "danger/danger_core/messages/violation"
|
|
2
|
+
require "danger/danger_core/messages/markdown"
|
|
3
|
+
require "danger/plugin_support/plugin"
|
|
4
|
+
|
|
5
|
+
module Danger
|
|
6
|
+
# Provides the feedback mechanism for Danger. Danger can keep track of
|
|
7
|
+
# messages, warnings, failure and post arbitrary markdown into a comment.
|
|
8
|
+
#
|
|
9
|
+
# The message within which Danger communicates back is amended on each run in a session.
|
|
10
|
+
#
|
|
11
|
+
# Each of `message`, `warn` and `fail` have a `sticky` flag, `false` by default, which
|
|
12
|
+
# when `true` means that the message will be crossed out instead of being removed.
|
|
13
|
+
# If it's not called again on subsequent runs.
|
|
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
|
+
# failure 'Ooops', 'bad bad error', sticky: false
|
|
21
|
+
# markdown '# And', '# Even', '# Markdown', file: "Dangerfile", line: 1
|
|
22
|
+
#
|
|
23
|
+
# By default, using `failure` would fail the corresponding build. Either via an API call, or
|
|
24
|
+
# via the return value for the danger command. Older code examples use `fail` which is an alias
|
|
25
|
+
# of `failure`, but the default Rubocop settings would have an issue with it.
|
|
26
|
+
#
|
|
27
|
+
# You can optionally add `file` and `line` to provide inline feedback on a PR in GitHub, note that
|
|
28
|
+
# only feedback inside the PR's diff will show up inline. Others will appear inside the main comment.
|
|
29
|
+
#
|
|
30
|
+
# It is possible to have Danger ignore specific warnings or errors by writing `Danger: Ignore "[warning/error text]"`.
|
|
31
|
+
#
|
|
32
|
+
# Sidenote: Messaging is the only plugin which adds functions to the root of the Dangerfile.
|
|
33
|
+
#
|
|
34
|
+
# @example Failing a build
|
|
35
|
+
#
|
|
36
|
+
# failure "This build didn't pass tests"
|
|
37
|
+
# failure "Ooops!", "Something bad happened"
|
|
38
|
+
# failure ["This is example", "with array"]
|
|
39
|
+
#
|
|
40
|
+
# @example Failing a build, and note that on subsequent runs
|
|
41
|
+
#
|
|
42
|
+
# failure("This build didn't pass tests", sticky: true)
|
|
43
|
+
#
|
|
44
|
+
# @example Passing a warning
|
|
45
|
+
#
|
|
46
|
+
# warn "This build didn't pass linting"
|
|
47
|
+
# warn "Hm...", "This is not really good"
|
|
48
|
+
# warn ["Multiple warnings", "via array"]
|
|
49
|
+
#
|
|
50
|
+
# @example Displaying a markdown table
|
|
51
|
+
#
|
|
52
|
+
# message = "### Proselint found issues\n\n"
|
|
53
|
+
# message << "Line | Message | Severity |\n"
|
|
54
|
+
# message << "| --- | ----- | ----- |\n"
|
|
55
|
+
# message << "20 | No documentation | Error \n"
|
|
56
|
+
# markdown message
|
|
57
|
+
#
|
|
58
|
+
# markdown "### First issue", "### Second issue"
|
|
59
|
+
# markdown ["### First issue", "### Second issue"]
|
|
60
|
+
#
|
|
61
|
+
# @example Adding an inline warning to a file
|
|
62
|
+
#
|
|
63
|
+
# warn("You shouldn't use puts in your Dangerfile", file: "Dangerfile", line: 10)
|
|
64
|
+
#
|
|
65
|
+
#
|
|
66
|
+
# @see danger/danger
|
|
67
|
+
# @tags core, messaging
|
|
68
|
+
#
|
|
69
|
+
|
|
70
|
+
class DangerfileMessagingPlugin < Plugin
|
|
71
|
+
def initialize(dangerfile)
|
|
72
|
+
super(dangerfile)
|
|
73
|
+
|
|
74
|
+
@warnings = []
|
|
75
|
+
@errors = []
|
|
76
|
+
@messages = []
|
|
77
|
+
@markdowns = []
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# The instance name used in the Dangerfile
|
|
81
|
+
# @return [String]
|
|
82
|
+
#
|
|
83
|
+
def self.instance_name
|
|
84
|
+
"messaging"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @!group Core
|
|
88
|
+
# Print markdown to below the table
|
|
89
|
+
#
|
|
90
|
+
# @param [String, Array<String>] message
|
|
91
|
+
# The markdown based message to be printed below the table
|
|
92
|
+
# @param [String] file
|
|
93
|
+
# Optional. Path to the file that the message is for.
|
|
94
|
+
# @param [String] line
|
|
95
|
+
# Optional. The line in the file to present the message in.
|
|
96
|
+
# @return [void]
|
|
97
|
+
#
|
|
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
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# @!group Core
|
|
108
|
+
# Print out a generate message on the PR
|
|
109
|
+
#
|
|
110
|
+
# @param [String, Array<String>] message
|
|
111
|
+
# The message to present to the user
|
|
112
|
+
# @param [Boolean] sticky
|
|
113
|
+
# Whether the message should be kept after it was fixed,
|
|
114
|
+
# defaults to `false`.
|
|
115
|
+
# @param [String] file
|
|
116
|
+
# Optional. Path to the file that the message is for.
|
|
117
|
+
# @param [String] line
|
|
118
|
+
# Optional. The line in the file to present the message in.
|
|
119
|
+
# @return [void]
|
|
120
|
+
#
|
|
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, type: :message) if message
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# @!group Core
|
|
132
|
+
# Specifies a problem, but not critical
|
|
133
|
+
#
|
|
134
|
+
# @param [String, Array<String>] message
|
|
135
|
+
# The message to present to the user
|
|
136
|
+
# @param [Boolean] sticky
|
|
137
|
+
# Whether the message should be kept after it was fixed,
|
|
138
|
+
# defaults to `false`.
|
|
139
|
+
# @param [String] file
|
|
140
|
+
# Optional. Path to the file that the message is for.
|
|
141
|
+
# @param [String] line
|
|
142
|
+
# Optional. The line in the file to present the message in.
|
|
143
|
+
# @return [void]
|
|
144
|
+
#
|
|
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
|
+
|
|
153
|
+
@warnings << Violation.new(warning, sticky, file, line, type: :warning) if warning
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# @!group Core
|
|
158
|
+
# Declares a CI blocking error
|
|
159
|
+
#
|
|
160
|
+
# @param [String, Array<String>] message
|
|
161
|
+
# The message to present to the user
|
|
162
|
+
# @param [Boolean] sticky
|
|
163
|
+
# Whether the message should be kept after it was fixed,
|
|
164
|
+
# defaults to `false`.
|
|
165
|
+
# @param [String] file
|
|
166
|
+
# Optional. Path to the file that the message is for.
|
|
167
|
+
# @param [String] line
|
|
168
|
+
# Optional. The line in the file to present the message in.
|
|
169
|
+
# @return [void]
|
|
170
|
+
#
|
|
171
|
+
def fail(*failures, **options)
|
|
172
|
+
sticky = options.fetch(:sticky, false)
|
|
173
|
+
file = options.fetch(:file, nil)
|
|
174
|
+
line = options.fetch(:line, nil)
|
|
175
|
+
|
|
176
|
+
failures.flatten.each do |failure|
|
|
177
|
+
next if should_ignore_violation(failure)
|
|
178
|
+
|
|
179
|
+
@errors << Violation.new(failure, sticky, file, line, type: :error) if failure
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
alias failure fail
|
|
184
|
+
|
|
185
|
+
# @!group Reporting
|
|
186
|
+
# A list of all messages passed to Danger, including
|
|
187
|
+
# the markdowns.
|
|
188
|
+
#
|
|
189
|
+
# @visibility hidden
|
|
190
|
+
# @return [Hash]
|
|
191
|
+
def status_report
|
|
192
|
+
{
|
|
193
|
+
errors: @errors.map(&:message).clone.freeze,
|
|
194
|
+
warnings: @warnings.map(&:message).clone.freeze,
|
|
195
|
+
messages: @messages.map(&:message).clone.freeze,
|
|
196
|
+
markdowns: @markdowns.clone.freeze
|
|
197
|
+
}
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# @!group Reporting
|
|
201
|
+
# A list of all violations passed to Danger, we don't
|
|
202
|
+
# anticipate users of Danger needing to use this.
|
|
203
|
+
#
|
|
204
|
+
# @visibility hidden
|
|
205
|
+
# @return [Hash]
|
|
206
|
+
def violation_report
|
|
207
|
+
{
|
|
208
|
+
errors: @errors.clone.freeze,
|
|
209
|
+
warnings: @warnings.clone.freeze,
|
|
210
|
+
messages: @messages.clone.freeze
|
|
211
|
+
}
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
private
|
|
215
|
+
|
|
216
|
+
def should_ignore_violation(message)
|
|
217
|
+
env.request_source.ignored_violations.include? message
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|