Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tooling/danger/suggestion.rb')
-rw-r--r--tooling/danger/suggestion.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/tooling/danger/suggestion.rb b/tooling/danger/suggestion.rb
new file mode 100644
index 00000000000..da3c6b0e76f
--- /dev/null
+++ b/tooling/danger/suggestion.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+require 'forwardable'
+require_relative 'suggestor'
+
+module Tooling
+ module Danger
+ # A basic suggestion.
+ #
+ # A subclass needs to define the following constants:
+ # * MATCH (Regexp) - A Regexp to match file lines
+ # * REPLACEMENT (String) - A suggestion replacement text
+ # * SUGGESTION (String) - A suggestion text
+ #
+ # @see Suggestor
+ class Suggestion
+ extend Forwardable
+ include ::Tooling::Danger::Suggestor
+
+ def_delegators :@context, :helper, :project_helper, :markdown
+
+ attr_reader :filename
+
+ def initialize(filename, context:)
+ @filename = filename
+ @context = context
+ end
+
+ def suggest
+ add_suggestion(
+ filename: filename,
+ regex: self.class::MATCH,
+ replacement: self.class::REPLACEMENT,
+ comment_text: self.class::SUGGESTION
+ )
+ end
+ end
+ end
+end