Class: Dependabot::PullRequestCreator::MessageBuilder
- Inherits:
-
Object
- Object
- Dependabot::PullRequestCreator::MessageBuilder
- Defined in:
- lib/dependabot/pull_request_creator/message_builder.rb,
lib/dependabot/pull_request_creator/message_builder/issue_linker.rb,
lib/dependabot/pull_request_creator/message_builder/metadata_presenter.rb,
lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb
Overview
MessageBuilder builds PR message for a dependency update
Defined Under Namespace
Classes: IssueLinker, LinkAndMentionSanitizer, MetadataPresenter
Constant Summary collapse
- TRUNCATED_MSG =
"...\n\n_Description has been truncated_"
Instance Attribute Summary collapse
-
#commit_message_options ⇒ Object
readonly
Returns the value of attribute commit_message_options.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#dependency_group ⇒ Object
readonly
Returns the value of attribute dependency_group.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#github_redirection_service ⇒ Object
readonly
Returns the value of attribute github_redirection_service.
-
#ignore_conditions ⇒ Object
readonly
Returns the value of attribute ignore_conditions.
-
#pr_message_encoding ⇒ Object
Returns the value of attribute pr_message_encoding.
-
#pr_message_footer ⇒ Object
readonly
Returns the value of attribute pr_message_footer.
-
#pr_message_header ⇒ Object
readonly
Returns the value of attribute pr_message_header.
-
#pr_message_max_length ⇒ Object
Returns the value of attribute pr_message_max_length.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#vulnerabilities_fixed ⇒ Object
readonly
Returns the value of attribute vulnerabilities_fixed.
Instance Method Summary collapse
- #commit_message ⇒ Object
-
#initialize(source:, dependencies:, files:, credentials:, pr_message_header: nil, pr_message_footer: nil, commit_message_options: {}, vulnerabilities_fixed: {}, github_redirection_service: DEFAULT_GITHUB_REDIRECTION_SERVICE, dependency_group: nil, pr_message_max_length: nil, pr_message_encoding: nil, ignore_conditions: []) ⇒ MessageBuilder
constructor
A new instance of MessageBuilder.
- #message ⇒ Object
- #pr_message ⇒ Object
- #pr_name ⇒ Object
-
#truncate_pr_message(msg) ⇒ Object
Truncate PR message as determined by the pr_message_max_length and pr_message_encoding instance variables The encoding is used when calculating length, all messages are returned as ruby UTF_8 encoded string.
- #unignore_commands? ⇒ Boolean
Constructor Details
#initialize(source:, dependencies:, files:, credentials:, pr_message_header: nil, pr_message_footer: nil, commit_message_options: {}, vulnerabilities_fixed: {}, github_redirection_service: DEFAULT_GITHUB_REDIRECTION_SERVICE, dependency_group: nil, pr_message_max_length: nil, pr_message_encoding: nil, ignore_conditions: []) ⇒ MessageBuilder
Returns a new instance of MessageBuilder.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 31 def initialize(source:, dependencies:, files:, credentials:, pr_message_header: nil, pr_message_footer: nil, commit_message_options: {}, vulnerabilities_fixed: {}, github_redirection_service: DEFAULT_GITHUB_REDIRECTION_SERVICE, dependency_group: nil, pr_message_max_length: nil, pr_message_encoding: nil, ignore_conditions: []) @dependencies = dependencies @files = files @source = source @credentials = credentials @pr_message_header = @pr_message_footer = @commit_message_options = @vulnerabilities_fixed = vulnerabilities_fixed @github_redirection_service = github_redirection_service @dependency_group = dependency_group @pr_message_max_length = @pr_message_encoding = @ignore_conditions = ignore_conditions end |
Instance Attribute Details
#commit_message_options ⇒ Object (readonly)
Returns the value of attribute commit_message_options.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def @commit_message_options end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def credentials @credentials end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def dependencies @dependencies end |
#dependency_group ⇒ Object (readonly)
Returns the value of attribute dependency_group.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def dependency_group @dependency_group end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def files @files end |
#github_redirection_service ⇒ Object (readonly)
Returns the value of attribute github_redirection_service.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def github_redirection_service @github_redirection_service end |
#ignore_conditions ⇒ Object (readonly)
Returns the value of attribute ignore_conditions.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def ignore_conditions @ignore_conditions end |
#pr_message_encoding ⇒ Object
Returns the value of attribute pr_message_encoding.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def @pr_message_encoding end |
#pr_message_footer ⇒ Object (readonly)
Returns the value of attribute pr_message_footer.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def @pr_message_footer end |
#pr_message_header ⇒ Object (readonly)
Returns the value of attribute pr_message_header.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def @pr_message_header end |
#pr_message_max_length ⇒ Object
Returns the value of attribute pr_message_max_length.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def @pr_message_max_length end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def source @source end |
#vulnerabilities_fixed ⇒ Object (readonly)
Returns the value of attribute vulnerabilities_fixed.
23 24 25 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 23 def vulnerabilities_fixed @vulnerabilities_fixed end |
Instance Method Details
#commit_message ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 105 def = commit_subject + "\n\n" += += += "\n\n" + if rescue StandardError => e Dependabot.logger.error("Error while generating commit message: #{e.}") = commit_subject += "\n\n" + if end |
#message ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 118 def Dependabot::PullRequestCreator::Message.new( pr_name: pr_name, pr_message: , commit_message: ) end |
#pr_message ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 61 def # TODO: Remove unignore_commands? feature flag once we are confident # that it is working as expected msg = if unignore_commands? "#{}" \ "#{}" \ "#{}" \ "#{ignore_conditions_table}" \ "#{}" else "#{}" \ "#{}" \ "#{}" \ "#{}" end (msg) rescue StandardError => e Dependabot.logger.error("Error while generating PR message: #{e.}") + end |
#pr_name ⇒ Object
55 56 57 58 59 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 55 def pr_name name = dependency_group ? group_pr_name : solo_pr_name name[0] = name[0].capitalize if pr_name_prefixer.capitalize_first_word? "#{pr_name_prefix}#{name}" end |
#truncate_pr_message(msg) ⇒ Object
Truncate PR message as determined by the pr_message_max_length and pr_message_encoding instance variables The encoding is used when calculating length, all messages are returned as ruby UTF_8 encoded string
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 89 def (msg) return msg if .nil? msg = msg.dup msg = msg.force_encoding() unless .nil? if msg.length > tr_msg = .nil? ? TRUNCATED_MSG : (+TRUNCATED_MSG).dup.force_encoding() trunc_length = - tr_msg.length msg = (msg[0..trunc_length] + tr_msg) end # if we used a custom encoding for calculating length, then we need to force back to UTF-8 msg.force_encoding(Encoding::UTF_8) unless .nil? msg end |
#unignore_commands? ⇒ Boolean
83 84 85 |
# File 'lib/dependabot/pull_request_creator/message_builder.rb', line 83 def unignore_commands? Experiments.enabled?(:unignore_commands) end |