Repository navigation
Add limit-commit-title-length feature - #2115
Conversation
| function init(): void { | ||
| const inputs = select.all<HTMLInputElement>([ | ||
| '#commit-summary-input', // Commit title on edit file page | ||
| '#pull_request_title', // PR title while creating PR |
There was a problem hiding this comment.
This is unrelated. If the user wants the PR title to match the commit they’ll do so when merging the PR 🙂
There was a problem hiding this comment.
When creating a PR from a branch with a very long commit title, GitHub already separates out pull request title to 70 characters in title field and the rest into the message field.
So this should be a good practice for both the contributor (while opening PR) and for the owner (while merging PR) right!?
There was a problem hiding this comment.
The actual limit seems to be 72 characters, after which GitHub clips back to 70 characters.
One thing I noticed is that validation does not apply to the initial value (or values set programmatically, like by sync-pr-title-message):
- Set commit title via
field.value = '0'.repeat(100) - Press "Commit" button
- The submission won't be stopped
insert-text-textarea does't trigger validation either, nor does firing input events.
Probably sync-pr-issue-title needs to be clipped to 72 characters as well, unless you find a way to trigger validation after setting the title (I couldn't. checkValidity and reportValidity report true even if the form isn't valid, which is ridiculous)
The one thing I still can't figure out. But from what I've tested it looks like for the browser to validate autofilled inputs, the constraints have to be already present when the DOM is being created. To bypass this I've tried In the example screenshot below, the input wasn't touched while running the following snippets. But by using To be frank, @bfred-it's avatar sums up this whole situation for triggering validation for autofilled input fields. |
I'm thinking of sticking to GitHub's convention of 70 character limit, to be consistent with GH. I can't say if this actually happens, but we might loose data when moving between 70 and 72. @bfred-it WDYT!? |
GitHub's limit is 72, I just tested it
Definitely, I like that the browsers say "it should be 72, but now there are 76", which we wouldn't get with
Hehe yeah, setting the value programmatically breaks the validation altogether, so I think the only option we have is to trim |
- Extend commit title length from 70 to 72
I should've read the spec for that one, turned out to be completely different from what I thought it would be. @bfred-it take a look at 739fcd5, as we are already limiting PR title length to 72 characters when the PR is being created there should not be many issues here. But we might also need to extend this to limit to editing PR and issue titles too. |
|
Ok, we should restore the JS validation, but it can be very simple: On input
setValidity(field.length > limit && `The title should not be longer than 72 characters, but is currently ${field.length}`)Almost one line |
|
Uhm, the suggestion I gave you was literally one line of code inside the listener. No need to make it more complex I think. Perhaps the same function needs to be run when the form is submitted as well, as long as it blocks the submission when it fails. Also we can drop the maxlength attribute altogether since we now have JS validation. It makes it easier to edit the text in it Likewise we can drop the PR title limit altogether. This feature will error on merge, if the merger has RGH and the feature is enabled, rather than by the PR sender |
|
All done!
|
This also validates input values automatically restored by GitHub on page load for merge box
| for (const inputField of inputs) { | ||
| inputField.dispatchEvent(new Event('input')); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Good idea, I wonder if this makes the submit handler unnecessary. I don't think the title field is ever programmatically changed when the PR merge panel is open; even GitHub specifically avoids this.
In that case, validityCallback can be simplified as I had first suggested, likely.
Also this event only needs to be triggered on the title field because that's what this feature cares about.
There was a problem hiding this comment.
In that case, validityCallback can be simplified as I had first suggested, likely.
Yup!
Also this event only needs to be triggered on the title field because that's what this feature cares about.
The merge input field can be on index 0 or 1 of the inputFields variable when querying DOM. Instead of searching for it, I just figured it'd be easy to trigger input events on all of them. Doesn't matter that much anyway.
There was a problem hiding this comment.
I had assumed that fields was [title, message] but I think it's always just one; the double selector made me think it was two. I think you just need a select and you can drop the loop
limit-commit-title-length feature
|
:neato: 😎 |
|
Can you add this to the readme? |




Closes #1475.
maxlengthproperty to 70.Test
While creating a PR or merging it, the input fields do not accept characters greater than 70 characters in length.