mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Refactor "string truncate" (#32984)
This commit is contained in:
@@ -109,7 +109,7 @@ func (a *actionNotifier) CreateIssueComment(ctx context.Context, doer *user_mode
|
||||
IsPrivate: issue.Repo.IsPrivate,
|
||||
}
|
||||
|
||||
truncatedContent, truncatedRight := util.SplitStringAtByteN(comment.Content, 200)
|
||||
truncatedContent, truncatedRight := util.EllipsisDisplayStringX(comment.Content, 200)
|
||||
if truncatedRight != "" {
|
||||
// in case the content is in a Latin family language, we remove the last broken word.
|
||||
lastSpaceIdx := strings.LastIndex(truncatedContent, " ")
|
||||
|
@@ -10,9 +10,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/jaytaylor/html2text"
|
||||
gomail "github.com/wneessen/go-mail"
|
||||
@@ -54,7 +54,7 @@ func (m *Message) ToMessage() *gomail.Msg {
|
||||
|
||||
plainBody, err := html2text.FromString(m.Body)
|
||||
if err != nil || setting.MailService.SendAsPlainText {
|
||||
if strings.Contains(base.TruncateString(m.Body, 100), "<html>") {
|
||||
if strings.Contains(util.TruncateRunes(m.Body, 100), "<html>") {
|
||||
log.Warn("Mail contains HTML but configured to send as plain text.")
|
||||
}
|
||||
msg.SetBodyString("text/plain", plainBody)
|
||||
|
@@ -19,7 +19,6 @@ import (
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
base_module "code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/label"
|
||||
@@ -409,7 +408,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
|
||||
RepoID: g.repo.ID,
|
||||
Repo: g.repo,
|
||||
Index: issue.Number,
|
||||
Title: base_module.TruncateString(issue.Title, 255),
|
||||
Title: util.TruncateRunes(issue.Title, 255),
|
||||
Content: issue.Content,
|
||||
Ref: issue.Ref,
|
||||
IsClosed: issue.State == "closed",
|
||||
|
@@ -179,7 +179,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
|
||||
return err
|
||||
}
|
||||
|
||||
rel.Title, _ = util.SplitStringAtByteN(rel.Title, 255)
|
||||
rel.Title = util.EllipsisDisplayString(rel.Title, 255)
|
||||
rel.LowerTagName = strings.ToLower(rel.TagName)
|
||||
if err = db.Insert(gitRepo.Ctx, rel); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user