-
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 option to control PR description max length + set reasonable defaults for each platform #7487
Add option to control PR description max length + set reasonable defaults for each platform #7487
Conversation
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.
Please add tests
@deivid-rodriguez @jeffwidman if you have chance to review I would appreciate it. There is major change for terraform providers that causes a PR description that exceeds the codecommit limit and is blowing up on us. Thanks! |
@deivid-rodriguez @jeffwidman @jurre Any estimate on when you all will be able to look at this? |
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.
Looks great!
Nice thorough test cases too (🎩 💁♂️ to @yeikel for the nudge).
14c6d16
to
6d8a525
Compare
Hmm, I just noticed this already exists in 2 other places: dependabot-core/common/lib/dependabot/pull_request_creator/github.rb Lines 351 to 362 in 221a6e5
dependabot-core/common/lib/dependabot/clients/azure.rb Lines 378 to 389 in 221a6e5
And this PR will add a third... And all the other platforms (BitBucket, GitLab, etc) also have PR limits:
This is going to become a mess quickly if each client has their own implementation. So could we instead pull this truncation helper into the common PR description creator functionality? Azure may need to remain a special case since they calculate character limits based on the UTF-16 case, but the others can all be DRY'd up. What about this, you implement the CodeCommit solution via a common/generic solution, and then I'll handle migrating the existing instances to this common/generic solution? No need for you to do that. A quick peek looks like all the clients in https://github.com/dependabot/dependabot-core/blob/221a6e5599ea1e8c30f6167b0a1bbe48c0b8e15f/common/lib/dependabot/pull_request_creator.rb build their PR descriptions using dependabot-core/common/lib/dependabot/pull_request_creator/message_builder.rb Lines 50 to 56 in 221a6e5
So could you take this
You can see a similar idea in this PR that wires up a common param for truncating the length of the PR branch name: The one bit I'm a little unclear on is how to set a default value, because there's no point in each caller of this code having to manually set the value... most everyone will simply want the default for their platform. My guess is this call:
Would look more like: pr_description: message.pr_message(CODECOMMIT.MAX_PR_DESCRIPTION_LENGTH), Or you may need to hook it into the memo'ized MessageBuilder, my Ruby foo isn't strong enough to know the best way to do this w/o spending a bit more time on it: dependabot-core/common/lib/dependabot/pull_request_creator.rb Lines 218 to 232 in 221a6e5
Overall though this doesn't look like too much more work here... your existing set of tests should be fine, just move them over to the common code. If you want to just wire it up for CodeCommit, then I can handle the cleanup of moving the GitHub truncation code to using this new common param. |
Realized after I approved that this should be a common feature to all PRs, not just codecommit
As illustrated by #7564 (comment), some users will probably have valid reasons for truncating the PR description even shorter than their platform's limit. So ideally we both set the per-platform default and also make it a configurable param. |
I will take a look at this later today or tomorrow. Thanks! |
@jeffwidman I have moved the truncate and updated the calls. "my Ruby foo isn't strong enough to know the best way to do this" - My Ruby fu was all gained contributing here to dependabot, I am learning as I go 😁 |
@jeffwidman I also tested this using the dry run script against code commit to see if the default values were properly selected and then if overriding worked, as well as with passing encoding param. After a couple of tweaks it did exactly what I expected it would. Excited to get this one merged. Hopefully this passes muster. |
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.
This looks really solid to me! Nice job. I appreciate you going the extra mile to make the encoding arg generic so we can use it beyond Azure.
A few small nits, feel free to push back on any of them if you think I'm missing something or just plain wrong. 😁
What do you think about also setting default values for BitBucket and GitLab?
- https://docs.gitlab.com/ee/administration/instance_limits.html#size-of-comments-and-descriptions-of-issues-merge-requests-and-epics
- https://jira.atlassian.com/browse/BSERV-14135#:~:text=Currently%2C%20the%20max%20length%20of,property%20to%20increase%20this%20limit.
It'd be super simple to tack onto this PR since it's just setting a few more values / case statements. And I'm not too particular about our inability to test them because if they happen to be wrong other folks who are using on those platforms can always come along and correct it since this is OSS.
@@ -88,6 +90,8 @@ def initialize(source:, base_commit:, dependencies:, files:, credentials:, | |||
@provider_metadata = provider_metadata | |||
@message = message | |||
@dependency_group = dependency_group | |||
@pr_message_max_length = pr_message_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.
Any reason why you picked pr_message...
rather than pr_description...
?
My thinking is there are multiple messages tied to a PR, for example comments, reviews, etc but only one main description tied to it... Just checked and GitHub, AWS CodeCommit, BitBucket, GitLab, ADO all call it PR/MR Description, so appears that's relatively consistent terminology...
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 named it that as the method called is pr_message in MessageBuilder
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.
Ah, gotcha, yeah, it probably wouldn't hurt to rename that to DescriptionBuilder (totally out of scope of this PR)... I'll look into that after this is merged... let's leave this comment unresolved as a reminder to me.
Just remembered that @mburumaxwell had noticed that My inclination is to first land this PR as-is, as it's semi-generic so will have a larger impact, then circle back and rebase/try to his PR after this is merged. |
I was going to do this, but I actually use bitbucket and was able to create a PR with a description longer than that value in that ticket, so I was not sure what the real limit was. Since gitlab and bitbucket didnt have values before I just figured leave it as is and if someone comes across an issue then they would add the limit. |
Yeah, changing that in this PR changes the scope even more. Hopefully this gets merged and then he can address with the new changes. |
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 applied a few more mostly cosmetic changes, we've worked together enough that I was pretty sure you wouldn't mind if it helps this land sooner. 😁
This is my last remaining question--once you address this I'll approve/merge:
https://github.com/dependabot/dependabot-core/pull/7487/files#r1273880291
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.
Thank you again!
Is this one of the changes you made? |
1ee9489
to
dbfd0bd
Compare
Yeah, I screwed up the whitespace using the GitHub UI ```suggestion tool... I just fixed it. |
Fix the character length limit error by setting it in the `MessageBuilder`. This reacts to changes made in dependabot/dependabot-core#7487
Add option to set the max character length of the PR description. Any descriptions longer than the max will get truncated with a clear message to the user that the remaining description was truncated.
This is mostly a refactor / moving of existing code that had been copy/pasted across several PR creators so that we have a clean generic version that can re-used everywhere.
In addition to being configurable, this also sets reasonable defaults for some of the platforms that supports.
Fix #6976