Extract shared PR title construction to MessageBuilderUtils#14045
Extract shared PR title construction to MessageBuilderUtils#14045thavaahariharangit wants to merge 7 commits into
Conversation
Add a utility module that centralizes PR title construction logic, enabling reuse across different message builder implementations. This ensures future updates to title construction affect all builders consistently.
| # @return [String] The constructed PR title | ||
| # | ||
| # @example Basic usage | ||
| # build_pr_title(title: "bump foo to 1.0", prefix: "chore: ") |
There was a problem hiding this comment.
Could this be spit into further arguments or a custom input class?
For example
- Prefix
- Dependency name
- current version
- new version
There was a problem hiding this comment.
Thanks for raising this point, @yeikel.
However, Not all PR titles follow a uniform structure with dependency name, current version, and new version.
For grouped dependency updates, the title structure is fundamentally different:
- Grouped updates may include multiple dependencies, so there's no single dependency name, current version, or new version to display
- Multi-ecosystem groups use an entirely different format, such as:
Bump the "group-name" group with N updates across multiple ecosystems
The primary goal of this PR is to address the duplication identified by @kbukum1 in a review comment. The following pattern was being duplicated in two places:
- The API layer (when grouping multiple ecosystem PRs together)
- The core layer (when setting the prefix for regular PRs)
def combined_pr_title
title = base_title
title = capitalize_first_word(title) if pr_name_prefixer&.capitalize_first_word?
"#{pr_name_prefix}#{title}"
end
This extraction consolidates the shared title construction logic (applying prefix and capitalization rules) into MessageBuilderUtils, while keeping the base_title generation flexible for each caller to define based on their specific context.
There was a problem hiding this comment.
Thank for the context and explanation; I did forget about grouped updates and you're totally right!
…sage_builder_utils.rb Co-authored-by: Yeikel Santana <email@yeikel.com>
…sage_builder_utils.rb Co-authored-by: Yeikel Santana <email@yeikel.com>
…sage_builder_utils.rb Co-authored-by: Yeikel Santana <email@yeikel.com>
| ).returns(String) | ||
| end | ||
| def self.build_pr_title(title:, prefix: "", capitalize_first_word: false) | ||
| result_title = title.dup |
There was a problem hiding this comment.
Why is this dup call needed?
There was a problem hiding this comment.
The .dup is needed because the next line mutates the string in-place:
result_title[0] = T.must(result_title[0]).capitalize
Using string[0] = ... modifies the original string object. Without .dup, the caller's original title string would be mutated, which could cause unexpected side effects.
| params( | ||
| prefix: T.nilable(String), | ||
| prefix_development: T.nilable(String), | ||
| include_scope: T.nilable(T::Boolean) |
There was a problem hiding this comment.
Can this actually be nil? I thought it could only be true or false, but I could be wrong
There was a problem hiding this comment.
Yes, include_scope can be nil.
This value originates from the dependabot.yml configuration file:
version: 2
multi-ecosystem-groups:
all-updates:
schedule:
interval: "weekly"
commit-message:
prefix: "chore"
include: "scope"
The include property is optional, so there are three possible states:
- Absent → parsed as nil (use default behavior)
- Present with
"scope"→ converted to true (include scope in prefix) - Present with other/empty value → could be
false(explicitly disable scope)
This is why the method correctly uses T.nilable(T::Boolean) for the type signature and checks unless include_scope.nil? rather than just if include_scope
There was a problem hiding this comment.
I see, thank your for the explanation. Just for my own understanding, what is the "default behavior"
Or in other words, what is the difference between "default behavior" and false?
|
This work is covered by this PR |
What are you trying to accomplish?
Add a utility module that centralizes PR title construction logic, enabling reuse across different message builder implementations.
Context:
dependabot-coredependabot-apiSince
dependabot-apiusesdependabot-coreas a dependency, we're extracting the shared title construction logic intodependabot-core. This ensures future updates to title construction affect both builders consistently.Anything you want to highlight for special attention from reviewers?
Only the PR title construction logic is extracted to this shared utility. The other two properties
pr_messageandcommit_messageremain separate because:Since these have fundamentally different approaches, sharing them wouldn't be necessary.
How will you know you've accomplished your goal?
Checklist