-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Handle too long PR titles correctly #16517
Merged
zeripath
merged 8 commits into
go-gitea:main
from
zeripath:fix-16507-long-commit-messages
Jul 25, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b559b3d
Handle too long PR titles correctly
zeripath b1c2294
use ellipsis …
zeripath 6e1c072
Update routers/web/repo/pull.go
zeripath 46deda4
Update routers/web/repo/pull.go
zeripath 887c0f1
as per lunny
zeripath 6424efd
placate lint
zeripath d8fe118
Merge branch 'main' into fix-16507-long-commit-messages
zeripath 6f73e2f
Merge branch 'main' into fix-16507-long-commit-messages
zeripath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package util | ||
|
||
import "unicode/utf8" | ||
|
||
// SplitStringAtByteN splits a string at byte n accounting for rune boundaries. (Combining characters are not accounted for.) | ||
func SplitStringAtByteN(input string, n int) (left, right string) { | ||
if len(input) <= n { | ||
left = input | ||
return | ||
} | ||
|
||
if !utf8.ValidString(input) { | ||
left = input[:n-3] + "..." | ||
right = "..." + input[n-3:] | ||
return | ||
} | ||
|
||
// in UTF8 "…" is 3 bytes so doesn't really gain us anything... | ||
end := 0 | ||
for end <= n-3 { | ||
_, size := utf8.DecodeRuneInString(input[end:]) | ||
if end+size > n-3 { | ||
break | ||
} | ||
end += size | ||
} | ||
|
||
left = input[:end] + "…" | ||
right = "…" + input[end:] | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ValidString
don't mean it's totally ascii. Maybe we should correct it.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.
The test here is to simply abort trying to be nice if the string is not a valid utf8 string. (Which could be ASCII, Big5, UTF-16...)
If you don't have a utf-8 string in your commit header - getting it truncated nicely is going to be the least of your worries. We really don't handle other encodings in git commit headers.