-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add max length option to BranchNamer #5338
Conversation
|
||
# Shorten the ref in case users refs have length limits | ||
if @max_length | ||
sanitized_name[0, @max_length] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried that we'd end up with duplicate branch names in this scenario, as we'd end up truncating the bit that makes them unique (the version), and I think that could cause issues. Maybe we should truncate the dependency_name_part
instead? From the linked issue it seems like this happens when a bunch of dependencies are updated in lockstep, so you end up with a long name part like: rails-and-draper-and-rails-controller-testing-and-rspec-rails-and-font-awesome-rails-and...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a valid concern.
Would you be okay with taking a hash of the full-length branch name and taking the first max_length
characters from that if max_length
is specified? (At some point we'd have to choose the lesser of 2 evils, we cannot deal with going over the limit, however then you do lose pretty branch names)
edit: your suggestion in the edit is probably better and more in spirit of what you want to achieve though 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah a hash could also work, it's a tad safer I guess (if for some reason the combination of dependency names changes, it's still unique)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went for @nudded's suggestion with the safer hash. It's a bit smart in the sense that when part of the branch name can be kept, it is kept. E.g., for the branch "business-and-work-and-desks-and-tables-and-chairs-and-lunch", the results (including default prefixes) are:
80 chars: dependabot/bundler/business-and-work-and-desks-and-tables-and-chairs-and-lunch
(fits within 80 chars)
70 chars: dependabot/bundler/business-and2a62321b0f24418298904dedd6dada473213321
(prefixes are saved, but is padded with hash to 70 chars)
50 chars: dependabotd2a62321b0f24418298904dedd6dada473213321
(still shortened including a bit of the prefixes)
40 chars: d2a62321b0f24418298904dedd6dada473213321
(just enough to store the full sha1 hash)
20 chars: d2a62321b0f244182989
(hash is shortened to make it fit within 20 chars)
It doesn't help that much for shorter max lengths, especially if prefixes are involved, but in the case where the max length is set to 150, I hope this will aid users when they can at least see the start of the branch name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clean solution @TomNaessens 👍
Approving the CI runs for first-time contributor as the PR seems headed in a generally useful direction. |
Sorry, took a while to get the feedback processed. Let me know what you think of the changes! |
@TomNaessens , thanks for opening this, we've also ran into a similar problem. Seems like there are just some linter issues left (most of which can be autocorrected); @jeffwidman / @jurre, does this need more work, or do the changes look good? :) |
Thanks! Should be fixed now 🙇♂️ |
Rebased, once CI passes I'll merge to |
This PR adds a max length option to the BranchNamer and addresses #3107. Also relevant for the "... and may contain a maximum of 128 characters" part of #396.
This is a backwards compatible change and requires no configuration: when no option is passed, no truncating is performed on the branch name.
As this is my first contribution here, let me know if I missed some conventions, or if there are additional changes expected!