Skip to content

suggest-commit-title-limit - Enable on PR title - #7428

Merged
fregante merged 5 commits into
mainfrom
pr-title-limit
Jun 18, 2024
Merged

fregante merged 5 commits into
mainfrom
pr-title-limit

Conversation

@fregante

Copy link
Copy Markdown
Member

Test URLs

Here

Screenshot

Screenshot 5

@fregante

Copy link
Copy Markdown
Member Author

cc @karlhorky

@karlhorky

karlhorky commented Jun 12, 2024 •

Copy link
Copy Markdown
Contributor

Amazing, thanks!

Doesn't GitHub UI cut off after 50 characters? Would it make sense to make this configurable? (or just adopt the shorter 50 characters length to match GitHub?)

The original issue also mentioned that 50 characters is the limit for GitHub, but was eventually changed to 72, which doesn't seem like a common length rule (often the 50/72 rule is cited, 50 characters limit for titles and 72 characters for subsequent lines):

@karlhorky

karlhorky commented Jun 12, 2024 •

Copy link
Copy Markdown
Contributor

More research:

On this PR it seems like the GitHub UI is truncating after 67 characters (so 72 would be an unfortunate length leading to truncation in the UI):

Screenshot 2024-06-12 at 15 46 26

> 'Revert "use-first-commit-message-for-new-prs - Preserve previous us'.length
67

I guess I would suggest by default going with 50 characters (because that is also what GitHub uses), and then allowing configuration for those who want more characters.

@fregante

Copy link
Copy Markdown
Member Author

Doesn't GitHub UI cut off after 50 characters?

Never, 50 is just a suggestion for commits titles.

72 is GitHub's actual limit (72 characters are allowed, less than that is clipped to 70 + ellipsis I guess)

The hard limit for PR titles is 256 characters:

Would it make sense to make this configurable?

No: https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#3-it-doesnt-require-options

67

That' missing the backticks used to turn part of the title into title, so 67 + 2 + ... = 72.


As for the limit to use here, we actually had this issue before and it was the reason why we dropped this feature (we either had it or tried to add it before).

The issue: PR titles are used as commit titles together with (#123), so the limit should probably be 72 - 4 - String(prNumber).length

@fregante

Copy link
Copy Markdown
Member Author

You can see it live here: #2178 (comment)

@karlhorky

karlhorky commented Jun 12, 2024 •

Copy link
Copy Markdown
Contributor

That' missing the backticks used to turn part of the title into title, so 67 + 2 + ... = 72.

Interesting, so that means GitHub is rendering an ellipsis character with the ... but still counting all 3 characters 🤔 weird.

But good catch on the backticks, which I indeed did not count there.

The issue: PR titles are used as commit titles together with (#123), so the limit should probably be 72 - 4 - String(prNumber).length

Given the new information about the 72 characters, makes sense to me 👍

Never, 50 is just a suggestion for commits titles.

Would still be nice for users to be able to configure the limit to whatever they want, since some may want to:

  • match the recommendation in the GitHub commit title UI
  • match the Linux recommendation (which is also 50 characters for a commit title)
  • match any other team / style requirements that they have

@fregante

Copy link
Copy Markdown
Member Author

configure the limit

Will never happen, we just don't do that: https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#3-it-doesnt-require-options

I don’t think even GitHub cares enough about that to make it a per-repo limitation. If you want actual limits you'll have to use GitHub Actions and protected branches.

The scope of suggest-commit-title-limit is to avoid mistakenly exceeding this invisible 72-character limit that makes commits harder to read in a list when clipped. We had initially avoided limiting PR titles because there's no such limit in PR titles. I'm adding it now because PR titles eventually end up as part of the commit title anyway.

@fregante
fregante marked this pull request as draft June 12, 2024 18:16
@fregante
fregante marked this pull request as ready for review June 18, 2024 16:43
@fregante

Copy link
Copy Markdown
Member Author

Calculation now includes the PR number:

Untitled

@fregante

Copy link
Copy Markdown
Member Author

Sorry that it couldn't match the desired length count 🙏

@fregante
fregante enabled auto-merge (squash) June 18, 2024 16:44
@fregante
fregante merged commit e02f1c1 into main Jun 18, 2024
@fregante
fregante deleted the pr-title-limit branch June 18, 2024 16:44
@karlhorky

karlhorky commented Jun 18, 2024 •

Copy link
Copy Markdown
Contributor

Nice, no worries - I can understand your logic with it 👍

Maybe 50-character commit title counts are outdated. 72 is much more roomy, and will probably make it easier to be expressive for complex changes without too much endless "character golfing" re-editing.

I'll consider switching for our team.

@karlhorky

Copy link
Copy Markdown
Contributor

@fregante it appears this isn't applying on the "Files changed" tab in PRs - /pull/<number>/files (maybe also not applying on other tabs)

Screenshot 2024-06-24 at 12 01 56

Would it be possible to also apply this to other tabs? I tried looking for a URL / regex in the diff, but I didn't see anything that would match the /pull/<number> pattern in this PR...

@fregante

fregante commented Jun 24, 2024 •

Copy link
Copy Markdown
Member Author

Indeed! The check is called isPRConversation. It can be changed to isPR. PR welcome. I’m not sure if the other part of the feature will cause issues though, might be worth creating two init (features.add accepts multiple arguments)

edit: the single detection change should be enough

@karlhorky

Copy link
Copy Markdown
Contributor

@fregante ok, maybe this is the one you mean?

@fregante

Copy link
Copy Markdown
Member Author

Thank you!

@karlhorky

karlhorky commented Aug 15, 2024 •

Copy link
Copy Markdown
Contributor

I just realized today, another place that this is missing is the "create new PR" URL on the compare page:

Screenshot 2024-08-15 at 11 18 06

Example URL:

https://github.com/karlhorky/project/compare/x?expand=1

HTML:

<div class="discussion-topic-header p-0 mb-3">
  <h3 id="pull_request_title_header" data-view-component="true" class="f4 mb-2">Add a title</h3>
  <text-expander keys=":" data-emoji-url="/autocomplete/emoji" class="position-relative">
    <input class="form-control required title js-session-resumable js-quick-submit FormControl-input FormControl-large valid" placeholder="Title" aria-labelledby="pull_request_title_header" autofocus="autofocus" autocomplete="off" required="required" type="text" value="PR title here" name="pull_request[title]" id="pull_request_title">
  </text-expander>
</div>

Would this also just be another item in the include array from the pageDetect object?

@karlhorky

Copy link
Copy Markdown
Contributor

@fregante created a draft PR here, in case pageDetect.isCompare would work here:

karlhorky added a commit to karlhorky/dotfiles that referenced this pull request Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Suggest length limit for PR titles

2 participants