From 0e7dc9e43663af3e115d950b0fb60d4dc778d7f1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 31 Oct 2025 09:43:32 +0100 Subject: [PATCH 1/9] Update golangci-lint to v2.6.0 --- .golangci.yml | 3 ++- Makefile | 2 +- models/asymkey/ssh_key_parse.go | 4 +++- models/perm/access/repo_permission.go | 9 +++++++-- models/user/user.go | 4 ++-- modules/auth/password/password.go | 8 ++++++-- modules/git/foreachref/format.go | 4 +++- modules/git/notes_nogogit.go | 6 ++++-- modules/setting/config.go | 5 ++++- modules/setting/config_env.go | 16 ++++++++++------ modules/templates/util_render.go | 4 +++- modules/timeutil/since.go | 4 +++- routers/api/packages/rubygems/rubygems.go | 4 +++- routers/web/auth/oauth2_provider.go | 4 +++- routers/web/user/setting/keys.go | 7 +++++-- services/gitdiff/gitdiff.go | 4 +++- services/webhook/dingtalk.go | 8 +++++--- services/webhook/discord.go | 6 ++++-- services/webhook/feishu.go | 8 +++++--- services/webhook/matrix.go | 6 ++++-- services/webhook/msteams.go | 8 +++++--- services/webhook/slack.go | 6 ++++-- services/webhook/telegram.go | 6 ++++-- services/webhook/wechatwork.go | 8 +++++--- services/wiki/wiki_path.go | 4 ++-- 25 files changed, 100 insertions(+), 48 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 483843bc55dca..96fa88a593096 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,9 +14,9 @@ linters: - govet - ineffassign - mirror + - modernize - nakedret - nolintlint - - perfsprint - revive - staticcheck - testifylint @@ -55,6 +55,7 @@ linters: disabled-checks: - ifElseChain - singleCaseSwitch # Every time this occurred in the code, there was no other way. + - deprecatedComment # conflicts with go-swagger comments revive: severity: error rules: diff --git a/Makefile b/Makefile index 7531e56d83406..ffa7471aa0ccf 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ XGO_VERSION := go-1.25.x AIR_PACKAGE ?= github.com/air-verse/air@v1 EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3 GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.9.2 -GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0 +GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0 GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.15 MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.7.0 SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.33.1 diff --git a/models/asymkey/ssh_key_parse.go b/models/asymkey/ssh_key_parse.go index fc39f28624d87..b37d35fc4989c 100644 --- a/models/asymkey/ssh_key_parse.go +++ b/models/asymkey/ssh_key_parse.go @@ -66,6 +66,7 @@ func parseKeyString(content string) (string, error) { lines := strings.Split(content, "\n") continuationLine := false + var keyContentSb69 strings.Builder for _, line := range lines { // Skip lines that: // 1) are a continuation of the previous line, @@ -74,9 +75,10 @@ func parseKeyString(content string) (string, error) { if continuationLine || strings.ContainsAny(line, ":-") { continuationLine = strings.HasSuffix(line, "\\") } else { - keyContent += line + keyContentSb69.WriteString(line) } } + keyContent += keyContentSb69.String() t, err := extractTypeFromBase64Key(keyContent) if err != nil { diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 034557db33a8d..3859381a596f4 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "slices" + "strings" actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" @@ -171,6 +172,7 @@ func (p *Permission) LogString() string { format := " 2 { entry, err = tree.GetTreeEntryByPath(commitID) if err == nil { - path += commitID + pathSb36.WriteString(commitID) break } if IsErrNotExist(err) { tree, err = tree.SubTree(commitID[0:2]) - path += commitID[0:2] + "/" + pathSb36.WriteString(commitID[0:2] + "/") commitID = commitID[2:] } if err != nil { @@ -52,6 +53,7 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) return err } } + path += pathSb36.String() blob := entry.Blob() dataRc, err := blob.DataAsync() diff --git a/modules/setting/config.go b/modules/setting/config.go index 4c5d2df7d8a01..1eca8831478c6 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -4,6 +4,7 @@ package setting import ( + "strings" "sync" "code.gitea.io/gitea/modules/log" @@ -24,9 +25,11 @@ type OpenWithEditorAppsType []OpenWithEditorApp func (t OpenWithEditorAppsType) ToTextareaString() string { ret := "" + var retSb27 strings.Builder for _, app := range t { - ret += app.DisplayName + " = " + app.OpenURL + "\n" + retSb27.WriteString(app.DisplayName + " = " + app.OpenURL + "\n") } + ret += retSb27.String() return ret } diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go index 8b204e5c7c939..15ba1edf5e69d 100644 --- a/modules/setting/config_env.go +++ b/modules/setting/config_env.go @@ -48,18 +48,20 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { inKey := false last := 0 escapeStringIndices := escapeRegex.FindAllStringIndex(encoded, -1) + var keySb51 strings.Builder + var sectionSb51 strings.Builder for _, unescapeIdx := range escapeStringIndices { preceding := encoded[last:unescapeIdx[0]] if !inKey { if splitter := strings.Index(preceding, "__"); splitter > -1 { - section += preceding[:splitter] + sectionSb51.WriteString(preceding[:splitter]) inKey = true - key += preceding[splitter+2:] + keySb51.WriteString(preceding[splitter+2:]) } else { - section += preceding + sectionSb51.WriteString(preceding) } } else { - key += preceding + keySb51.WriteString(preceding) } toDecode := encoded[unescapeIdx[0]+3 : unescapeIdx[1]-1] decodedBytes := make([]byte, len(toDecode)/2) @@ -69,12 +71,14 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { decodedBytes[i] = byte(byteInt) } if inKey { - key += string(decodedBytes) + keySb51.Write(decodedBytes) } else { - section += string(decodedBytes) + sectionSb51.Write(decodedBytes) } last = unescapeIdx[1] } + key += keySb51.String() + section += sectionSb51.String() remaining := encoded[last:] if !inKey { if splitter := strings.Index(remaining, "__"); splitter > -1 { diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 132ca4d9160ae..00dd2f63c6c1b 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -250,14 +250,16 @@ func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink strin isPullRequest := issue != nil && issue.IsPull baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues")) htmlCode := `` + var htmlCodeSb253 strings.Builder for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so if label == nil { continue } link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID) - htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link))) + htmlCodeSb253.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link)))) } + htmlCode += htmlCodeSb253.String() htmlCode += "" return template.HTML(htmlCode) } diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index 2c89ae38d566c..1658ebddd344d 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -96,13 +96,15 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string { } var timeStr, diffStr string + var timeStrSb99 strings.Builder for { if diff == 0 { break } diff, diffStr = computeTimeDiffFloor(diff, lang) - timeStr += ", " + diffStr + timeStrSb99.WriteString(", " + diffStr) } + timeStr += timeStrSb99.String() return strings.TrimPrefix(timeStr, ", ") } diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go index 1ecf93592e17c..9d8971962e075 100644 --- a/routers/api/packages/rubygems/rubygems.go +++ b/routers/api/packages/rubygems/rubygems.go @@ -434,13 +434,15 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model. func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) { ret := "---\n" + var retSb437 strings.Builder for _, v := range versions { dep, err := makePackageVersionDependency(ctx, v, c) if err != nil { return "", err } - ret += dep + "\n" + retSb437.WriteString(dep + "\n") } + ret += retSb437.String() return ret, nil } diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 1dc40d6a75fed..cfb0f1526adbb 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -180,9 +180,11 @@ func AuthorizeOAuth(ctx *context.Context) { errs = form.Validate(ctx.Req, errs) if len(errs) > 0 { errstring := "" + var errstringSb183 strings.Builder for _, e := range errs { - errstring += e.Error() + "\n" + errstringSb183.WriteString(e.Error() + "\n") } + errstring += errstringSb183.String() ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring)) return } diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go index 6b5a7a2e2a0bd..fc1db300ed9f4 100644 --- a/routers/web/user/setting/keys.go +++ b/routers/web/user/setting/keys.go @@ -7,6 +7,7 @@ package setting import ( "errors" "net/http" + "strings" asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/db" @@ -132,10 +133,12 @@ func KeysPost(ctx *context.Context) { return } keyIDs := "" + var keyIDsSb135 strings.Builder for _, key := range keys { - keyIDs += key.KeyID - keyIDs += ", " + keyIDsSb135.WriteString(key.KeyID) + keyIDsSb135.WriteString(", ") } + keyIDs += keyIDsSb135.String() if len(keyIDs) > 0 { keyIDs = keyIDs[:len(keyIDs)-2] } diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 96aea8308c92a..22e08d1d67ee0 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1141,13 +1141,15 @@ func readFileName(rd *strings.Reader) (string, bool) { _, _ = fmt.Fscanf(rd, "%s ", &name) char, _ := rd.ReadByte() _ = rd.UnreadByte() + var nameSb1144 strings.Builder for !(char == 0 || char == '"' || char == 'b') { var suffix string _, _ = fmt.Fscanf(rd, "%s ", &suffix) - name += " " + suffix + nameSb1144.WriteString(" " + suffix) char, _ = rd.ReadByte() _ = rd.UnreadByte() } + name += nameSb1144.String() } if len(name) < 2 { log.Error("Unable to determine name from reader: reader=%+v", rd) diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index 5bbc610fe5c7b..05aede896687a 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -74,18 +74,20 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { var text string // for each commit, generate attachment text + var textSb77 strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName + textSb77.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\r\n" + textSb77.WriteString("\r\n") } } + text += textSb77.String() return createDingtalkPayload(title, text, linkText, titleLink), nil } diff --git a/services/webhook/discord.go b/services/webhook/discord.go index 6f045bd112590..c2fc9750c7f95 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -161,6 +161,7 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { var text string // for each commit, generate attachment text + var textSb164 strings.Builder for i, commit := range p.Commits { // limit the commit message display to just the summary, otherwise it would be hard to read message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 2)[0], "\r") @@ -169,12 +170,13 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { if utf8.RuneCountInString(message) > 50 { message = fmt.Sprintf("%.47s...", message) } - text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name) + textSb164.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\n" + textSb164.WriteString("\n") } } + text += textSb164.String() return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil } diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index b6ee80c44cc7a..b531631c023ec 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -78,18 +78,20 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) { text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) // for each commit, generate attachment text + var textSb81 strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName + textSb81.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\r\n" + textSb81.WriteString("\r\n") } } + text += textSb81.String() return newFeishuTextPayload(text), nil } diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index 57b1ece26350f..84c4ea8c6bf82 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -176,13 +176,15 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) { text := fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink) // for each commit, generate a new line text + var textSb179 strings.Builder for i, commit := range p.Commits { - text += fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name) + textSb179.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "
" + textSb179.WriteString("
") } } + text += textSb179.String() return m.newPayload(text, p.Commits...) } diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index 450a544b42ee4..3272f80c9b84c 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -133,14 +133,16 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { var text string // for each commit, generate attachment text + var textSb136 strings.Builder for i, commit := range p.Commits { - text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name) + textSb136.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\n\n" + textSb136.WriteString("\n\n") } } + text += textSb136.String() return createMSTeamsPayload( p.Repo, diff --git a/services/webhook/slack.go b/services/webhook/slack.go index 3d645a55d0441..cef60c217d3a7 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -210,13 +210,15 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { var attachmentText string // for each commit, generate attachment text + var attachmentTextSb213 strings.Builder for i, commit := range p.Commits { - attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)) + attachmentTextSb213.WriteString(fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - attachmentText += "\n" + attachmentTextSb213.WriteString("\n") } } + attachmentText += attachmentTextSb213.String() return s.createPayload(text, []SlackAttachment{{ Color: s.Color, diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index fdd428b45c7a0..0949da7ecc3aa 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -95,12 +95,14 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) { title := fmt.Sprintf(`[%s:%s] %s`, htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName), htmlLinkFormatter(titleLink, branchName), html.EscapeString(commitDesc)) var htmlCommits string + var htmlCommitsSb98 strings.Builder for _, commit := range p.Commits { - htmlCommits += fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n"))) + htmlCommitsSb98.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))) if commit.Author != nil { - htmlCommits += " - " + html.EscapeString(commit.Author.Name) + htmlCommitsSb98.WriteString(" - " + html.EscapeString(commit.Author.Name)) } } + htmlCommits += htmlCommitsSb98.String() return createTelegramPayloadHTML(title + htmlCommits), nil } diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index 187531740658b..b5249579bc12e 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -79,6 +79,7 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error var text string // for each commit, generate attachment text + var textSb82 strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { @@ -86,14 +87,15 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error } message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n") - text += fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, - message, authorName) + textSb82.WriteString(fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, + message, authorName)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\n" + textSb82.WriteString("\n") } } + text += textSb82.String() return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil } diff --git a/services/wiki/wiki_path.go b/services/wiki/wiki_path.go index 212a35ea2551e..fc032244b5cee 100644 --- a/services/wiki/wiki_path.go +++ b/services/wiki/wiki_path.go @@ -129,8 +129,8 @@ func GitPathToWebPath(s string) (wp WebPath, err error) { func WebPathToUserTitle(s WebPath) (dir, display string) { dir = path.Dir(string(s)) display = path.Base(string(s)) - if strings.HasSuffix(display, ".md") { - display = strings.TrimSuffix(display, ".md") + if before, ok := strings.CutSuffix(display, ".md"); ok { + display = before display, _ = url.PathUnescape(display) } display, _ = unescapeSegment(display) From f42ebb1622a1923f14631517cfb522d2d0f8f9d0 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 1 Nov 2025 11:14:55 +0100 Subject: [PATCH 2/9] fix var names --- models/asymkey/gpg_key_test.go | 6 +++--- models/asymkey/ssh_key_parse.go | 6 +++--- models/perm/access/repo_permission.go | 12 ++++++------ modules/auth/password/password.go | 12 ++++++------ modules/git/foreachref/format.go | 6 +++--- modules/git/notes_nogogit.go | 8 ++++---- modules/setting/config.go | 6 +++--- modules/setting/config_env.go | 20 ++++++++++---------- modules/templates/util_render.go | 6 +++--- modules/timeutil/since.go | 6 +++--- routers/api/packages/rubygems/rubygems.go | 6 +++--- routers/web/auth/oauth2_provider.go | 6 +++--- routers/web/user/setting/keys.go | 8 ++++---- services/gitdiff/gitdiff.go | 6 +++--- services/webhook/dingtalk.go | 8 ++++---- services/webhook/discord.go | 8 ++++---- services/webhook/feishu.go | 8 ++++---- services/webhook/matrix.go | 8 ++++---- services/webhook/msteams.go | 8 ++++---- services/webhook/slack.go | 8 ++++---- services/webhook/telegram.go | 8 ++++---- services/webhook/wechatwork.go | 8 ++++---- 22 files changed, 89 insertions(+), 89 deletions(-) diff --git a/models/asymkey/gpg_key_test.go b/models/asymkey/gpg_key_test.go index 4621337f11b07..c4574d1e0a4d1 100644 --- a/models/asymkey/gpg_key_test.go +++ b/models/asymkey/gpg_key_test.go @@ -214,7 +214,7 @@ MUBFeGFtcGxlLmNvbT6JATgEEwECACIFAllEBvMCGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAAoJEFMOzOY274DFw5EIAKc4jiYaMb1HDKrSv0tphgNxPFEY83/J 9CZggO7BINxlb7z/lH1i0U2h2Ha9E3VJTJQF80zBCaIvtU2UNrgVmSKoc0BdE/2S rS9MAl29sXxf1BfvXHu12Suvo8O/ZFP45Vm/3kkHuasHyOV1GwUWnynt1qo0zUEn -WMIcB8USlmMT1TnSb10YKBd/BpGF3crFDJLfAHRumZUk4knDDWUOWy5RCOG8cedc +WMIcB8USlmMT1TnSbYKBd/BpGF3crFDJLfAHRumZUk4knDDWUOWy5RCOG8cedc VTAhfdoKRRO3PchOfz6Rls/hew12mRNayqxuLQl2+BX+BWu+25dR3qyiS+twLbk6 Rjpb0S+RQTkYIUoI0SEZpxcTZso11xF5KNpKZ9aAoiLJqkNF5h4oPSe5AQ0EWUQG 8wEIALiMMqh3NF3ON/z7hQfeU24bCl/WdfJwCR9CWU/jx4X4gZq2C2aGtytGN5g/ @@ -299,7 +299,7 @@ BwIGFQoJCAsCBBYCAwECHgECF4AWIQTVtMQ7SKh59jUpNuZZNG4Oo1xn5QUCXKjY rQUJBUTnEgAKCRBZNG4Oo1xn5VhkD/42pGYstRMvrO37wJDnnLDm+ZPb0RGy80Ru Nt3S6OmU3TFuU9mj/FBc8VNs6xr0CCMVVM/CXX1gXCHhADss1YDaOcRsl5wVJ6EF tbpEXT/USMw3dV4Y8OYUSNxyEitzKt25CnOdWGPYaJG3YOtAR0qwopMiAgLrgLy9 -mugXqnrykF7yN27i6iRi2Jk9K7tSb4owpw1kuToJrNGThAkz+3nvXG5oRiYFTlH3 +mugXqnrykF7yN27i6iRi2Jk9K7tSbowpw1kuToJrNGThAkz+3nvXG5oRiYFTlH3 pATx34r+QOg1o3giomP49cP4ohxvQFP90w2/cURhLqEKdR6N1X0bTXRQvy8G+4Wl QMl8WYPzQUrKGMgj/f7Uhb3pFFLCcnCaYFdUj+fvshg5NMLGVztENz9x7Vr5n51o Hj9WuM3s65orKrGhMUk4NJCsQWJUHnSNsEXsuir9ocwCv4unIJuoOukNJigL4d5o @@ -370,7 +370,7 @@ D2wBYWE6tlRqT4j7u6u9vRjShKH+A1UpLV2pEtaIQ3wfbt6GIwFJHWU506m3RCCn pL46fAOVKS1GSuf79koXsZeECJRSbipXz3TJs0TqiQKzBBgBCAAmAhsCFiEE1bTE O0ioefY1KTbmWTRuDqNcZ+UFAlyo2PAFCQM9QGYAgXYgBBkRCAAdFiEENVUmaGTK bX/0Wqbnz8OUl/GybgcFAltMzAoACgkQz8OUl/Gybgf0OwD/c4hwqsfZ79t7pM9d -PPWYQ1jyq2g3ELMKyPp79GmL0qsA/2t2qkaOEX3y7egmhL/iKyqASb4y/JTABGMU +PPWYQ1jyq2g3ELMKyPp79GmL0qsA/2t2qkaOEX3y7egmhL/iKyqASby/JTABGMU hy5GjBhxCRBZNG4Oo1xn5WBvEACbCAQRC00FYoktuRzQQy2LCJe13AUS1/lCWv8B Qu7hTmM8TC/iNmYk71qeYInQMp/12b0HSWcv8IBmOlMy2GTjgnTgiwpqY5nhtb9O uB5H2g6fpu7FFG9ARhtH9PiTMwOUzfZFUz0tDdEEG5sayzWUcY3zjmJFmHSg5A9B diff --git a/models/asymkey/ssh_key_parse.go b/models/asymkey/ssh_key_parse.go index b37d35fc4989c..5846e0c026039 100644 --- a/models/asymkey/ssh_key_parse.go +++ b/models/asymkey/ssh_key_parse.go @@ -66,7 +66,7 @@ func parseKeyString(content string) (string, error) { lines := strings.Split(content, "\n") continuationLine := false - var keyContentSb69 strings.Builder + var keyContentSb strings.Builder for _, line := range lines { // Skip lines that: // 1) are a continuation of the previous line, @@ -75,10 +75,10 @@ func parseKeyString(content string) (string, error) { if continuationLine || strings.ContainsAny(line, ":-") { continuationLine = strings.HasSuffix(line, "\\") } else { - keyContentSb69.WriteString(line) + keyContentSb.WriteString(line) } } - keyContent += keyContentSb69.String() + keyContent += keyContentSb.String() t, err := extractTypeFromBase64Key(keyContent) if err != nil { diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 3859381a596f4..74f7aa10bbf28 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -172,7 +172,7 @@ func (p *Permission) LogString() string { format := " 2 { entry, err = tree.GetTreeEntryByPath(commitID) if err == nil { - pathSb36.WriteString(commitID) + pathSb.WriteString(commitID) break } if IsErrNotExist(err) { tree, err = tree.SubTree(commitID[0:2]) - pathSb36.WriteString(commitID[0:2] + "/") + pathSb.WriteString(commitID[0:2] + "/") commitID = commitID[2:] } if err != nil { @@ -53,7 +53,7 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) return err } } - path += pathSb36.String() + path += pathSb.String() blob := entry.Blob() dataRc, err := blob.DataAsync() diff --git a/modules/setting/config.go b/modules/setting/config.go index 1eca8831478c6..290760420e2c4 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -25,11 +25,11 @@ type OpenWithEditorAppsType []OpenWithEditorApp func (t OpenWithEditorAppsType) ToTextareaString() string { ret := "" - var retSb27 strings.Builder + var retSb strings.Builder for _, app := range t { - retSb27.WriteString(app.DisplayName + " = " + app.OpenURL + "\n") + retSb.WriteString(app.DisplayName + " = " + app.OpenURL + "\n") } - ret += retSb27.String() + ret += retSb.String() return ret } diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go index 15ba1edf5e69d..ab290f1ce45bc 100644 --- a/modules/setting/config_env.go +++ b/modules/setting/config_env.go @@ -48,20 +48,20 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { inKey := false last := 0 escapeStringIndices := escapeRegex.FindAllStringIndex(encoded, -1) - var keySb51 strings.Builder - var sectionSb51 strings.Builder + var keySb strings.Builder + var sectionSb strings.Builder for _, unescapeIdx := range escapeStringIndices { preceding := encoded[last:unescapeIdx[0]] if !inKey { if splitter := strings.Index(preceding, "__"); splitter > -1 { - sectionSb51.WriteString(preceding[:splitter]) + sectionSb.WriteString(preceding[:splitter]) inKey = true - keySb51.WriteString(preceding[splitter+2:]) + keySb.WriteString(preceding[splitter+2:]) } else { - sectionSb51.WriteString(preceding) + sectionSb.WriteString(preceding) } } else { - keySb51.WriteString(preceding) + keySb.WriteString(preceding) } toDecode := encoded[unescapeIdx[0]+3 : unescapeIdx[1]-1] decodedBytes := make([]byte, len(toDecode)/2) @@ -71,14 +71,14 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { decodedBytes[i] = byte(byteInt) } if inKey { - keySb51.Write(decodedBytes) + keySb.Write(decodedBytes) } else { - sectionSb51.Write(decodedBytes) + sectionSb.Write(decodedBytes) } last = unescapeIdx[1] } - key += keySb51.String() - section += sectionSb51.String() + key += keySb.String() + section += sectionSb.String() remaining := encoded[last:] if !inKey { if splitter := strings.Index(remaining, "__"); splitter > -1 { diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 00dd2f63c6c1b..39530cb7311f5 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -250,16 +250,16 @@ func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink strin isPullRequest := issue != nil && issue.IsPull baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues")) htmlCode := `` - var htmlCodeSb253 strings.Builder + var htmlCodeSb strings.Builder for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so if label == nil { continue } link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID) - htmlCodeSb253.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link)))) + htmlCodeSb.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link)))) } - htmlCode += htmlCodeSb253.String() + htmlCode += htmlCodeSb.String() htmlCode += "" return template.HTML(htmlCode) } diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index 1658ebddd344d..cdafd6c82db92 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -96,15 +96,15 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string { } var timeStr, diffStr string - var timeStrSb99 strings.Builder + var timeStrSb strings.Builder for { if diff == 0 { break } diff, diffStr = computeTimeDiffFloor(diff, lang) - timeStrSb99.WriteString(", " + diffStr) + timeStrSb.WriteString(", " + diffStr) } - timeStr += timeStrSb99.String() + timeStr += timeStrSb.String() return strings.TrimPrefix(timeStr, ", ") } diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go index 9d8971962e075..3c4cabbda119f 100644 --- a/routers/api/packages/rubygems/rubygems.go +++ b/routers/api/packages/rubygems/rubygems.go @@ -434,15 +434,15 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model. func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) { ret := "---\n" - var retSb437 strings.Builder + var retSb strings.Builder for _, v := range versions { dep, err := makePackageVersionDependency(ctx, v, c) if err != nil { return "", err } - retSb437.WriteString(dep + "\n") + retSb.WriteString(dep + "\n") } - ret += retSb437.String() + ret += retSb.String() return ret, nil } diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index cfb0f1526adbb..4a4310b0a19dc 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -180,11 +180,11 @@ func AuthorizeOAuth(ctx *context.Context) { errs = form.Validate(ctx.Req, errs) if len(errs) > 0 { errstring := "" - var errstringSb183 strings.Builder + var errstringSb strings.Builder for _, e := range errs { - errstringSb183.WriteString(e.Error() + "\n") + errstringSb.WriteString(e.Error() + "\n") } - errstring += errstringSb183.String() + errstring += errstringSb.String() ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring)) return } diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go index fc1db300ed9f4..a8939d0106a1d 100644 --- a/routers/web/user/setting/keys.go +++ b/routers/web/user/setting/keys.go @@ -133,12 +133,12 @@ func KeysPost(ctx *context.Context) { return } keyIDs := "" - var keyIDsSb135 strings.Builder + var keyIDsSb strings.Builder for _, key := range keys { - keyIDsSb135.WriteString(key.KeyID) - keyIDsSb135.WriteString(", ") + keyIDsSb.WriteString(key.KeyID) + keyIDsSb.WriteString(", ") } - keyIDs += keyIDsSb135.String() + keyIDs += keyIDsSb.String() if len(keyIDs) > 0 { keyIDs = keyIDs[:len(keyIDs)-2] } diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 22e08d1d67ee0..98d4b0db73b31 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1141,15 +1141,15 @@ func readFileName(rd *strings.Reader) (string, bool) { _, _ = fmt.Fscanf(rd, "%s ", &name) char, _ := rd.ReadByte() _ = rd.UnreadByte() - var nameSb1144 strings.Builder + var nameSb strings.Builder for !(char == 0 || char == '"' || char == 'b') { var suffix string _, _ = fmt.Fscanf(rd, "%s ", &suffix) - nameSb1144.WriteString(" " + suffix) + nameSb.WriteString(" " + suffix) char, _ = rd.ReadByte() _ = rd.UnreadByte() } - name += nameSb1144.String() + name += nameSb.String() } if len(name) < 2 { log.Error("Unable to determine name from reader: reader=%+v", rd) diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index 05aede896687a..d2647cb158efe 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -74,20 +74,20 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { var text string // for each commit, generate attachment text - var textSb77 strings.Builder + var textSb strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - textSb77.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + textSb.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, strings.TrimRight(commit.Message, "\r\n")) + authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb77.WriteString("\r\n") + textSb.WriteString("\r\n") } } - text += textSb77.String() + text += textSb.String() return createDingtalkPayload(title, text, linkText, titleLink), nil } diff --git a/services/webhook/discord.go b/services/webhook/discord.go index c2fc9750c7f95..f82ceaed869cf 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -161,7 +161,7 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { var text string // for each commit, generate attachment text - var textSb164 strings.Builder + var textSb strings.Builder for i, commit := range p.Commits { // limit the commit message display to just the summary, otherwise it would be hard to read message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 2)[0], "\r") @@ -170,13 +170,13 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { if utf8.RuneCountInString(message) > 50 { message = fmt.Sprintf("%.47s...", message) } - textSb164.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)) + textSb.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb164.WriteString("\n") + textSb.WriteString("\n") } } - text += textSb164.String() + text += textSb.String() return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil } diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index b531631c023ec..34d4c02231415 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -78,20 +78,20 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) { text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) // for each commit, generate attachment text - var textSb81 strings.Builder + var textSb strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - textSb81.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + textSb.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, strings.TrimRight(commit.Message, "\r\n")) + authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb81.WriteString("\r\n") + textSb.WriteString("\r\n") } } - text += textSb81.String() + text += textSb.String() return newFeishuTextPayload(text), nil } diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index 84c4ea8c6bf82..9354095d907cc 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -176,15 +176,15 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) { text := fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink) // for each commit, generate a new line text - var textSb179 strings.Builder + var textSb strings.Builder for i, commit := range p.Commits { - textSb179.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)) + textSb.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb179.WriteString("
") + textSb.WriteString("
") } } - text += textSb179.String() + text += textSb.String() return m.newPayload(text, p.Commits...) } diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index 3272f80c9b84c..9d272b2b9db30 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -133,16 +133,16 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { var text string // for each commit, generate attachment text - var textSb136 strings.Builder + var textSb strings.Builder for i, commit := range p.Commits { - textSb136.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, + textSb.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb136.WriteString("\n\n") + textSb.WriteString("\n\n") } } - text += textSb136.String() + text += textSb.String() return createMSTeamsPayload( p.Repo, diff --git a/services/webhook/slack.go b/services/webhook/slack.go index cef60c217d3a7..0949b92f74e2c 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -210,15 +210,15 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { var attachmentText string // for each commit, generate attachment text - var attachmentTextSb213 strings.Builder + var attachmentTextSb strings.Builder for i, commit := range p.Commits { - attachmentTextSb213.WriteString(fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))) + attachmentTextSb.WriteString(fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - attachmentTextSb213.WriteString("\n") + attachmentTextSb.WriteString("\n") } } - attachmentText += attachmentTextSb213.String() + attachmentText += attachmentTextSb.String() return s.createPayload(text, []SlackAttachment{{ Color: s.Color, diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index 0949da7ecc3aa..af3eb17ec057b 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -95,14 +95,14 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) { title := fmt.Sprintf(`[%s:%s] %s`, htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName), htmlLinkFormatter(titleLink, branchName), html.EscapeString(commitDesc)) var htmlCommits string - var htmlCommitsSb98 strings.Builder + var htmlCommitsSb strings.Builder for _, commit := range p.Commits { - htmlCommitsSb98.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))) + htmlCommitsSb.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))) if commit.Author != nil { - htmlCommitsSb98.WriteString(" - " + html.EscapeString(commit.Author.Name)) + htmlCommitsSb.WriteString(" - " + html.EscapeString(commit.Author.Name)) } } - htmlCommits += htmlCommitsSb98.String() + htmlCommits += htmlCommitsSb.String() return createTelegramPayloadHTML(title + htmlCommits), nil } diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index b5249579bc12e..d17d2a4ab5d01 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -79,7 +79,7 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error var text string // for each commit, generate attachment text - var textSb82 strings.Builder + var textSb strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { @@ -87,15 +87,15 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error } message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n") - textSb82.WriteString(fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, + textSb.WriteString(fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, message, authorName)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb82.WriteString("\n") + textSb.WriteString("\n") } } - text += textSb82.String() + text += textSb.String() return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil } From c234b812ef73a04176dbfc8ca2faa5b5adbf9bdf Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 1 Nov 2025 11:16:29 +0100 Subject: [PATCH 3/9] restore fixture --- models/asymkey/gpg_key_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/asymkey/gpg_key_test.go b/models/asymkey/gpg_key_test.go index c4574d1e0a4d1..4621337f11b07 100644 --- a/models/asymkey/gpg_key_test.go +++ b/models/asymkey/gpg_key_test.go @@ -214,7 +214,7 @@ MUBFeGFtcGxlLmNvbT6JATgEEwECACIFAllEBvMCGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAAoJEFMOzOY274DFw5EIAKc4jiYaMb1HDKrSv0tphgNxPFEY83/J 9CZggO7BINxlb7z/lH1i0U2h2Ha9E3VJTJQF80zBCaIvtU2UNrgVmSKoc0BdE/2S rS9MAl29sXxf1BfvXHu12Suvo8O/ZFP45Vm/3kkHuasHyOV1GwUWnynt1qo0zUEn -WMIcB8USlmMT1TnSbYKBd/BpGF3crFDJLfAHRumZUk4knDDWUOWy5RCOG8cedc +WMIcB8USlmMT1TnSb10YKBd/BpGF3crFDJLfAHRumZUk4knDDWUOWy5RCOG8cedc VTAhfdoKRRO3PchOfz6Rls/hew12mRNayqxuLQl2+BX+BWu+25dR3qyiS+twLbk6 Rjpb0S+RQTkYIUoI0SEZpxcTZso11xF5KNpKZ9aAoiLJqkNF5h4oPSe5AQ0EWUQG 8wEIALiMMqh3NF3ON/z7hQfeU24bCl/WdfJwCR9CWU/jx4X4gZq2C2aGtytGN5g/ @@ -299,7 +299,7 @@ BwIGFQoJCAsCBBYCAwECHgECF4AWIQTVtMQ7SKh59jUpNuZZNG4Oo1xn5QUCXKjY rQUJBUTnEgAKCRBZNG4Oo1xn5VhkD/42pGYstRMvrO37wJDnnLDm+ZPb0RGy80Ru Nt3S6OmU3TFuU9mj/FBc8VNs6xr0CCMVVM/CXX1gXCHhADss1YDaOcRsl5wVJ6EF tbpEXT/USMw3dV4Y8OYUSNxyEitzKt25CnOdWGPYaJG3YOtAR0qwopMiAgLrgLy9 -mugXqnrykF7yN27i6iRi2Jk9K7tSbowpw1kuToJrNGThAkz+3nvXG5oRiYFTlH3 +mugXqnrykF7yN27i6iRi2Jk9K7tSb4owpw1kuToJrNGThAkz+3nvXG5oRiYFTlH3 pATx34r+QOg1o3giomP49cP4ohxvQFP90w2/cURhLqEKdR6N1X0bTXRQvy8G+4Wl QMl8WYPzQUrKGMgj/f7Uhb3pFFLCcnCaYFdUj+fvshg5NMLGVztENz9x7Vr5n51o Hj9WuM3s65orKrGhMUk4NJCsQWJUHnSNsEXsuir9ocwCv4unIJuoOukNJigL4d5o @@ -370,7 +370,7 @@ D2wBYWE6tlRqT4j7u6u9vRjShKH+A1UpLV2pEtaIQ3wfbt6GIwFJHWU506m3RCCn pL46fAOVKS1GSuf79koXsZeECJRSbipXz3TJs0TqiQKzBBgBCAAmAhsCFiEE1bTE O0ioefY1KTbmWTRuDqNcZ+UFAlyo2PAFCQM9QGYAgXYgBBkRCAAdFiEENVUmaGTK bX/0Wqbnz8OUl/GybgcFAltMzAoACgkQz8OUl/Gybgf0OwD/c4hwqsfZ79t7pM9d -PPWYQ1jyq2g3ELMKyPp79GmL0qsA/2t2qkaOEX3y7egmhL/iKyqASby/JTABGMU +PPWYQ1jyq2g3ELMKyPp79GmL0qsA/2t2qkaOEX3y7egmhL/iKyqASb4y/JTABGMU hy5GjBhxCRBZNG4Oo1xn5WBvEACbCAQRC00FYoktuRzQQy2LCJe13AUS1/lCWv8B Qu7hTmM8TC/iNmYk71qeYInQMp/12b0HSWcv8IBmOlMy2GTjgnTgiwpqY5nhtb9O uB5H2g6fpu7FFG9ARhtH9PiTMwOUzfZFUz0tDdEEG5sayzWUcY3zjmJFmHSg5A9B From 13ad5a134a6a97dd9714e1c303b4efed41316f03 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 1 Nov 2025 11:20:54 +0100 Subject: [PATCH 4/9] fix --- .golangci.yml | 1 + models/perm/access/repo_permission.go | 16 ++++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 96fa88a593096..bd51691969172 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,6 +17,7 @@ linters: - modernize - nakedret - nolintlint + - perfsprint - revive - staticcheck - testifylint diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 74f7aa10bbf28..8fcd34f2aec91 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -169,10 +169,9 @@ func (p *Permission) ReadableUnitTypes() []unit.Type { } func (p *Permission) LogString() string { - format := "") + return fmt.Sprintf(formatSb.String(), args...) } func applyPublicAccessPermission(unitType unit.Type, accessMode perm_model.AccessMode, modeMap *map[unit.Type]perm_model.AccessMode) { From 3408302589ebf33625f175a994edadb8e2a8295e Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 1 Nov 2025 11:40:36 +0100 Subject: [PATCH 5/9] clean up string builders --- modules/auth/password/password.go | 6 ++---- modules/git/foreachref/format.go | 4 +--- modules/git/notes_nogogit.go | 4 +--- modules/setting/config.go | 4 +--- modules/setting/config_env.go | 4 ++-- modules/templates/util_render.go | 7 +++---- modules/timeutil/since.go | 5 ++--- routers/api/packages/rubygems/rubygems.go | 5 ++--- routers/web/auth/oauth2_provider.go | 4 +--- routers/web/user/setting/keys.go | 3 +-- services/webhook/dingtalk.go | 4 +--- services/webhook/discord.go | 4 +--- services/webhook/feishu.go | 8 ++++---- services/webhook/matrix.go | 8 ++++---- services/webhook/msteams.go | 4 +--- services/webhook/slack.go | 4 +--- services/webhook/telegram.go | 4 +--- services/webhook/wechatwork.go | 4 +--- 18 files changed, 30 insertions(+), 56 deletions(-) diff --git a/modules/auth/password/password.go b/modules/auth/password/password.go index c8e15acb8d456..f5209f0c8c0ec 100644 --- a/modules/auth/password/password.go +++ b/modules/auth/password/password.go @@ -61,25 +61,23 @@ func NewComplexity() { } func setupComplexity(values []string) { + var validCharsSb strings.Builder if len(values) != 1 || values[0] != "off" { - var validCharsSb strings.Builder for _, val := range values { if complexity, ok := charComplexities[val]; ok { validCharsSb.WriteString(complexity.ValidChars) requiredList = append(requiredList, complexity) } } - validChars += validCharsSb.String() if len(requiredList) == 0 { // No valid character classes found; use all classes as default - var validCharsSb strings.Builder for _, complexity := range charComplexities { validCharsSb.WriteString(complexity.ValidChars) requiredList = append(requiredList, complexity) } - validChars += validCharsSb.String() } } + validChars = validCharsSb.String() if validChars == "" { // No complexities to check; provide a sensible default for password generation validChars = charComplexities["lower"].ValidChars + charComplexities["upper"].ValidChars + charComplexities["digit"].ValidChars diff --git a/modules/git/foreachref/format.go b/modules/git/foreachref/format.go index 302d37914d63c..e05c772478a02 100644 --- a/modules/git/foreachref/format.go +++ b/modules/git/foreachref/format.go @@ -75,11 +75,9 @@ func (f Format) Parser(r io.Reader) *Parser { // hexEscaped produces hex-escpaed characters from a string. For example, "\n\0" // would turn into "%0a%00". func (f Format) hexEscaped(delim []byte) string { - escaped := "" var escapedSb strings.Builder for i := range delim { escapedSb.WriteString("%" + hex.EncodeToString([]byte{delim[i]})) } - escaped += escapedSb.String() - return escaped + return escapedSb.String() } diff --git a/modules/git/notes_nogogit.go b/modules/git/notes_nogogit.go index f843d2489d0c7..0056c679df280 100644 --- a/modules/git/notes_nogogit.go +++ b/modules/git/notes_nogogit.go @@ -26,8 +26,6 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) return err } - path := "" - tree := ¬es.Tree log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", tree.ID, commitID) @@ -53,7 +51,7 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) return err } } - path += pathSb.String() + path := pathSb.String() blob := entry.Blob() dataRc, err := blob.DataAsync() diff --git a/modules/setting/config.go b/modules/setting/config.go index 290760420e2c4..54e0e95cbfb72 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -24,13 +24,11 @@ type OpenWithEditorApp struct { type OpenWithEditorAppsType []OpenWithEditorApp func (t OpenWithEditorAppsType) ToTextareaString() string { - ret := "" var retSb strings.Builder for _, app := range t { retSb.WriteString(app.DisplayName + " = " + app.OpenURL + "\n") } - ret += retSb.String() - return ret + return retSb.String() } func DefaultOpenWithEditorApps() OpenWithEditorAppsType { diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go index ab290f1ce45bc..9fa9367c25e4d 100644 --- a/modules/setting/config_env.go +++ b/modules/setting/config_env.go @@ -77,8 +77,8 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { } last = unescapeIdx[1] } - key += keySb.String() - section += sectionSb.String() + key = keySb.String() + section = sectionSb.String() remaining := encoded[last:] if !inKey { if splitter := strings.Index(remaining, "__"); splitter > -1 { diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 39530cb7311f5..4d6d9c66a727c 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -249,8 +249,8 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML { isPullRequest := issue != nil && issue.IsPull baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues")) - htmlCode := `` var htmlCodeSb strings.Builder + htmlCodeSb.WriteString(``) for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so if label == nil { @@ -259,9 +259,8 @@ func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink strin link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID) htmlCodeSb.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link)))) } - htmlCode += htmlCodeSb.String() - htmlCode += "" - return template.HTML(htmlCode) + htmlCodeSb.WriteString("") + return template.HTML(htmlCodeSb.String()) } func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML { diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index cdafd6c82db92..17a76efdfd98f 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -95,7 +95,7 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string { return lang.TrString("tool.now") } - var timeStr, diffStr string + var diffStr string var timeStrSb strings.Builder for { if diff == 0 { @@ -105,6 +105,5 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string { diff, diffStr = computeTimeDiffFloor(diff, lang) timeStrSb.WriteString(", " + diffStr) } - timeStr += timeStrSb.String() - return strings.TrimPrefix(timeStr, ", ") + return strings.TrimPrefix(timeStrSb.String(), ", ") } diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go index 3c4cabbda119f..fec2165d12929 100644 --- a/routers/api/packages/rubygems/rubygems.go +++ b/routers/api/packages/rubygems/rubygems.go @@ -433,8 +433,8 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model. } func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) { - ret := "---\n" var retSb strings.Builder + retSb.WriteString("---\n") for _, v := range versions { dep, err := makePackageVersionDependency(ctx, v, c) if err != nil { @@ -442,8 +442,7 @@ func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVer } retSb.WriteString(dep + "\n") } - ret += retSb.String() - return ret, nil + return retSb.String(), nil } func makeGemFullFileName(gemName, version, platform string) string { diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 4a4310b0a19dc..3204e04e6c41a 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -179,13 +179,11 @@ func AuthorizeOAuth(ctx *context.Context) { errs := binding.Errors{} errs = form.Validate(ctx.Req, errs) if len(errs) > 0 { - errstring := "" var errstringSb strings.Builder for _, e := range errs { errstringSb.WriteString(e.Error() + "\n") } - errstring += errstringSb.String() - ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring)) + ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstringSb.String())) return } diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go index a8939d0106a1d..db59199e5ae5a 100644 --- a/routers/web/user/setting/keys.go +++ b/routers/web/user/setting/keys.go @@ -132,13 +132,12 @@ func KeysPost(ctx *context.Context) { } return } - keyIDs := "" var keyIDsSb strings.Builder for _, key := range keys { keyIDsSb.WriteString(key.KeyID) keyIDsSb.WriteString(", ") } - keyIDs += keyIDsSb.String() + keyIDs := keyIDsSb.String() if len(keyIDs) > 0 { keyIDs = keyIDs[:len(keyIDs)-2] } diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index d2647cb158efe..978b03a4ee450 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -72,7 +72,6 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text string // for each commit, generate attachment text var textSb strings.Builder for i, commit := range p.Commits { @@ -87,9 +86,8 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { textSb.WriteString("\r\n") } } - text += textSb.String() - return createDingtalkPayload(title, text, linkText, titleLink), nil + return createDingtalkPayload(title, textSb.String(), linkText, titleLink), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/discord.go b/services/webhook/discord.go index f82ceaed869cf..8174e26b1fbfb 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -159,7 +159,6 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text string // for each commit, generate attachment text var textSb strings.Builder for i, commit := range p.Commits { @@ -176,9 +175,8 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { textSb.WriteString("\n") } } - text += textSb.String() - return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil + return d.createPayload(p.Sender, title, textSb.String(), titleLink, greenColor), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index 34d4c02231415..7de26f577623f 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -76,9 +76,10 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) { commitDesc string ) - text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) - // for each commit, generate attachment text var textSb strings.Builder + textSb.WriteString(fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)) + + // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string if commit.Author != nil { @@ -91,9 +92,8 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) { textSb.WriteString("\r\n") } } - text += textSb.String() - return newFeishuTextPayload(text), nil + return newFeishuTextPayload(textSb.String()), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index 9354095d907cc..ced947d6ad245 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -173,10 +173,11 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) { repoLink := htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName) branchLink := MatrixLinkToRef(p.Repo.HTMLURL, p.Ref) - text := fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink) - // for each commit, generate a new line text var textSb strings.Builder + textSb.WriteString(fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink)) + + // for each commit, generate a new line text for i, commit := range p.Commits { textSb.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)) // add linebreak to each commit but the last @@ -184,9 +185,8 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) { textSb.WriteString("
") } } - text += textSb.String() - return m.newPayload(text, p.Commits...) + return m.newPayload(textSb.String(), p.Commits...) } // PullRequest implements payloadConvertor PullRequest method diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index 9d272b2b9db30..aba1b9abd17a9 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -131,7 +131,6 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text string // for each commit, generate attachment text var textSb strings.Builder for i, commit := range p.Commits { @@ -142,13 +141,12 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { textSb.WriteString("\n\n") } } - text += textSb.String() return createMSTeamsPayload( p.Repo, p.Sender, title, - text, + textSb.String(), titleLink, greenColor, &MSTeamsFact{"Commit count:", strconv.Itoa(p.TotalCommits)}, diff --git a/services/webhook/slack.go b/services/webhook/slack.go index 0949b92f74e2c..90d107ad6bf1d 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -208,7 +208,6 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { branchLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref) text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName) - var attachmentText string // for each commit, generate attachment text var attachmentTextSb strings.Builder for i, commit := range p.Commits { @@ -218,13 +217,12 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { attachmentTextSb.WriteString("\n") } } - attachmentText += attachmentTextSb.String() return s.createPayload(text, []SlackAttachment{{ Color: s.Color, Title: p.Repo.HTMLURL, TitleLink: p.Repo.HTMLURL, - Text: attachmentText, + Text: attachmentTextSb.String(), }}), nil } diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index af3eb17ec057b..a4d5c4c3a6717 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -94,7 +94,6 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) { } title := fmt.Sprintf(`[%s:%s] %s`, htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName), htmlLinkFormatter(titleLink, branchName), html.EscapeString(commitDesc)) - var htmlCommits string var htmlCommitsSb strings.Builder for _, commit := range p.Commits { htmlCommitsSb.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))) @@ -102,8 +101,7 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) { htmlCommitsSb.WriteString(" - " + html.EscapeString(commit.Author.Name)) } } - htmlCommits += htmlCommitsSb.String() - return createTelegramPayloadHTML(title + htmlCommits), nil + return createTelegramPayloadHTML(title + htmlCommitsSb.String()), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index d17d2a4ab5d01..a2fadee92fadf 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -77,7 +77,6 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error title := fmt.Sprintf("# %s:%s %s ", p.Repo.FullName, branchName, commitDesc) - var text string // for each commit, generate attachment text var textSb strings.Builder for i, commit := range p.Commits { @@ -95,8 +94,7 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error textSb.WriteString("\n") } } - text += textSb.String() - return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil + return newWechatworkMarkdownPayload(title + "\r\n\r\n" + textSb.String()), nil } // Issue implements PayloadConvertor Issue method From 54c2a2acd0ecb75e5fe477c50ebf09937cfc0d50 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 1 Nov 2025 11:42:09 +0100 Subject: [PATCH 6/9] restore newline --- models/perm/access/repo_permission.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 8fcd34f2aec91..49851c65b7269 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -172,6 +172,7 @@ func (p *Permission) LogString() string { var formatSb strings.Builder formatSb.WriteString(" Date: Mon, 3 Nov 2025 19:24:59 +0100 Subject: [PATCH 7/9] disable stringsbuilder and concat-loop --- .golangci.yml | 5 +++++ models/asymkey/ssh_key_parse.go | 4 +--- models/perm/access/repo_permission.go | 16 +++++++--------- modules/auth/password/password.go | 6 ++---- modules/git/foreachref/format.go | 6 +++--- modules/git/notes_nogogit.go | 8 ++++---- modules/setting/config.go | 7 +++---- modules/setting/config_env.go | 16 ++++++---------- modules/templates/util_render.go | 9 ++++----- modules/timeutil/since.go | 7 +++---- routers/api/packages/rubygems/rubygems.go | 7 +++---- routers/web/auth/oauth2_provider.go | 6 +++--- routers/web/user/setting/keys.go | 8 +++----- services/gitdiff/gitdiff.go | 4 +--- services/webhook/dingtalk.go | 10 +++++----- services/webhook/discord.go | 8 ++++---- services/webhook/feishu.go | 12 +++++------- services/webhook/matrix.go | 10 ++++------ services/webhook/msteams.go | 10 +++++----- services/webhook/slack.go | 8 ++++---- services/webhook/telegram.go | 8 ++++---- services/webhook/wechatwork.go | 10 +++++----- 22 files changed, 84 insertions(+), 101 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index bd51691969172..60482c415fde7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -109,6 +109,11 @@ linters: - require-error usetesting: os-temp-dir: true + modernize: + disable: + - stringsbuilder + perfsprint: + concat-loop: false exclusions: generated: lax presets: diff --git a/models/asymkey/ssh_key_parse.go b/models/asymkey/ssh_key_parse.go index 5846e0c026039..fc39f28624d87 100644 --- a/models/asymkey/ssh_key_parse.go +++ b/models/asymkey/ssh_key_parse.go @@ -66,7 +66,6 @@ func parseKeyString(content string) (string, error) { lines := strings.Split(content, "\n") continuationLine := false - var keyContentSb strings.Builder for _, line := range lines { // Skip lines that: // 1) are a continuation of the previous line, @@ -75,10 +74,9 @@ func parseKeyString(content string) (string, error) { if continuationLine || strings.ContainsAny(line, ":-") { continuationLine = strings.HasSuffix(line, "\\") } else { - keyContentSb.WriteString(line) + keyContent += line } } - keyContent += keyContentSb.String() t, err := extractTypeFromBase64Key(keyContent) if err != nil { diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 49851c65b7269..034557db33a8d 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "slices" - "strings" actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" @@ -169,8 +168,7 @@ func (p *Permission) ReadableUnitTypes() []unit.Type { } func (p *Permission) LogString() string { - var formatSb strings.Builder - formatSb.WriteString("") - return fmt.Sprintf(formatSb.String(), args...) + format += "\n\t]>" + return fmt.Sprintf(format, args...) } func applyPublicAccessPermission(unitType unit.Type, accessMode perm_model.AccessMode, modeMap *map[unit.Type]perm_model.AccessMode) { diff --git a/modules/auth/password/password.go b/modules/auth/password/password.go index f5209f0c8c0ec..a1e101dd621cb 100644 --- a/modules/auth/password/password.go +++ b/modules/auth/password/password.go @@ -61,23 +61,21 @@ func NewComplexity() { } func setupComplexity(values []string) { - var validCharsSb strings.Builder if len(values) != 1 || values[0] != "off" { for _, val := range values { if complexity, ok := charComplexities[val]; ok { - validCharsSb.WriteString(complexity.ValidChars) + validChars += complexity.ValidChars requiredList = append(requiredList, complexity) } } if len(requiredList) == 0 { // No valid character classes found; use all classes as default for _, complexity := range charComplexities { - validCharsSb.WriteString(complexity.ValidChars) + validChars += complexity.ValidChars requiredList = append(requiredList, complexity) } } } - validChars = validCharsSb.String() if validChars == "" { // No complexities to check; provide a sensible default for password generation validChars = charComplexities["lower"].ValidChars + charComplexities["upper"].ValidChars + charComplexities["digit"].ValidChars diff --git a/modules/git/foreachref/format.go b/modules/git/foreachref/format.go index e05c772478a02..d9573a55d628c 100644 --- a/modules/git/foreachref/format.go +++ b/modules/git/foreachref/format.go @@ -75,9 +75,9 @@ func (f Format) Parser(r io.Reader) *Parser { // hexEscaped produces hex-escpaed characters from a string. For example, "\n\0" // would turn into "%0a%00". func (f Format) hexEscaped(delim []byte) string { - var escapedSb strings.Builder + escaped := "" for i := range delim { - escapedSb.WriteString("%" + hex.EncodeToString([]byte{delim[i]})) + escaped += "%" + hex.EncodeToString([]byte{delim[i]}) } - return escapedSb.String() + return escaped } diff --git a/modules/git/notes_nogogit.go b/modules/git/notes_nogogit.go index 0056c679df280..4da375c3211a3 100644 --- a/modules/git/notes_nogogit.go +++ b/modules/git/notes_nogogit.go @@ -26,21 +26,22 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) return err } + path := "" + tree := ¬es.Tree log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", tree.ID, commitID) var entry *TreeEntry originalCommitID := commitID - var pathSb strings.Builder for len(commitID) > 2 { entry, err = tree.GetTreeEntryByPath(commitID) if err == nil { - pathSb.WriteString(commitID) + path += commitID break } if IsErrNotExist(err) { tree, err = tree.SubTree(commitID[0:2]) - pathSb.WriteString(commitID[0:2] + "/") + path += commitID[0:2] + "/" commitID = commitID[2:] } if err != nil { @@ -51,7 +52,6 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) return err } } - path := pathSb.String() blob := entry.Blob() dataRc, err := blob.DataAsync() diff --git a/modules/setting/config.go b/modules/setting/config.go index 54e0e95cbfb72..4c5d2df7d8a01 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -4,7 +4,6 @@ package setting import ( - "strings" "sync" "code.gitea.io/gitea/modules/log" @@ -24,11 +23,11 @@ type OpenWithEditorApp struct { type OpenWithEditorAppsType []OpenWithEditorApp func (t OpenWithEditorAppsType) ToTextareaString() string { - var retSb strings.Builder + ret := "" for _, app := range t { - retSb.WriteString(app.DisplayName + " = " + app.OpenURL + "\n") + ret += app.DisplayName + " = " + app.OpenURL + "\n" } - return retSb.String() + return ret } func DefaultOpenWithEditorApps() OpenWithEditorAppsType { diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go index 9fa9367c25e4d..8b204e5c7c939 100644 --- a/modules/setting/config_env.go +++ b/modules/setting/config_env.go @@ -48,20 +48,18 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { inKey := false last := 0 escapeStringIndices := escapeRegex.FindAllStringIndex(encoded, -1) - var keySb strings.Builder - var sectionSb strings.Builder for _, unescapeIdx := range escapeStringIndices { preceding := encoded[last:unescapeIdx[0]] if !inKey { if splitter := strings.Index(preceding, "__"); splitter > -1 { - sectionSb.WriteString(preceding[:splitter]) + section += preceding[:splitter] inKey = true - keySb.WriteString(preceding[splitter+2:]) + key += preceding[splitter+2:] } else { - sectionSb.WriteString(preceding) + section += preceding } } else { - keySb.WriteString(preceding) + key += preceding } toDecode := encoded[unescapeIdx[0]+3 : unescapeIdx[1]-1] decodedBytes := make([]byte, len(toDecode)/2) @@ -71,14 +69,12 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { decodedBytes[i] = byte(byteInt) } if inKey { - keySb.Write(decodedBytes) + key += string(decodedBytes) } else { - sectionSb.Write(decodedBytes) + section += string(decodedBytes) } last = unescapeIdx[1] } - key = keySb.String() - section = sectionSb.String() remaining := encoded[last:] if !inKey { if splitter := strings.Index(remaining, "__"); splitter > -1 { diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 4d6d9c66a727c..132ca4d9160ae 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -249,18 +249,17 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML { isPullRequest := issue != nil && issue.IsPull baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues")) - var htmlCodeSb strings.Builder - htmlCodeSb.WriteString(``) + htmlCode := `` for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so if label == nil { continue } link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID) - htmlCodeSb.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link)))) + htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link))) } - htmlCodeSb.WriteString("") - return template.HTML(htmlCodeSb.String()) + htmlCode += "" + return template.HTML(htmlCode) } func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML { diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index 17a76efdfd98f..2c89ae38d566c 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -95,15 +95,14 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string { return lang.TrString("tool.now") } - var diffStr string - var timeStrSb strings.Builder + var timeStr, diffStr string for { if diff == 0 { break } diff, diffStr = computeTimeDiffFloor(diff, lang) - timeStrSb.WriteString(", " + diffStr) + timeStr += ", " + diffStr } - return strings.TrimPrefix(timeStrSb.String(), ", ") + return strings.TrimPrefix(timeStr, ", ") } diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go index fec2165d12929..1ecf93592e17c 100644 --- a/routers/api/packages/rubygems/rubygems.go +++ b/routers/api/packages/rubygems/rubygems.go @@ -433,16 +433,15 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model. } func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) { - var retSb strings.Builder - retSb.WriteString("---\n") + ret := "---\n" for _, v := range versions { dep, err := makePackageVersionDependency(ctx, v, c) if err != nil { return "", err } - retSb.WriteString(dep + "\n") + ret += dep + "\n" } - return retSb.String(), nil + return ret, nil } func makeGemFullFileName(gemName, version, platform string) string { diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 3204e04e6c41a..1dc40d6a75fed 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -179,11 +179,11 @@ func AuthorizeOAuth(ctx *context.Context) { errs := binding.Errors{} errs = form.Validate(ctx.Req, errs) if len(errs) > 0 { - var errstringSb strings.Builder + errstring := "" for _, e := range errs { - errstringSb.WriteString(e.Error() + "\n") + errstring += e.Error() + "\n" } - ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstringSb.String())) + ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring)) return } diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go index db59199e5ae5a..6b5a7a2e2a0bd 100644 --- a/routers/web/user/setting/keys.go +++ b/routers/web/user/setting/keys.go @@ -7,7 +7,6 @@ package setting import ( "errors" "net/http" - "strings" asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/db" @@ -132,12 +131,11 @@ func KeysPost(ctx *context.Context) { } return } - var keyIDsSb strings.Builder + keyIDs := "" for _, key := range keys { - keyIDsSb.WriteString(key.KeyID) - keyIDsSb.WriteString(", ") + keyIDs += key.KeyID + keyIDs += ", " } - keyIDs := keyIDsSb.String() if len(keyIDs) > 0 { keyIDs = keyIDs[:len(keyIDs)-2] } diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 98d4b0db73b31..96aea8308c92a 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1141,15 +1141,13 @@ func readFileName(rd *strings.Reader) (string, bool) { _, _ = fmt.Fscanf(rd, "%s ", &name) char, _ := rd.ReadByte() _ = rd.UnreadByte() - var nameSb strings.Builder for !(char == 0 || char == '"' || char == 'b') { var suffix string _, _ = fmt.Fscanf(rd, "%s ", &suffix) - nameSb.WriteString(" " + suffix) + name += " " + suffix char, _ = rd.ReadByte() _ = rd.UnreadByte() } - name += nameSb.String() } if len(name) < 2 { log.Error("Unable to determine name from reader: reader=%+v", rd) diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index 978b03a4ee450..5bbc610fe5c7b 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -72,22 +72,22 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) + var text string // for each commit, generate attachment text - var textSb strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - textSb.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName) + text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb.WriteString("\r\n") + text += "\r\n" } } - return createDingtalkPayload(title, textSb.String(), linkText, titleLink), nil + return createDingtalkPayload(title, text, linkText, titleLink), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/discord.go b/services/webhook/discord.go index 8174e26b1fbfb..6f045bd112590 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -159,8 +159,8 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) + var text string // for each commit, generate attachment text - var textSb strings.Builder for i, commit := range p.Commits { // limit the commit message display to just the summary, otherwise it would be hard to read message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 2)[0], "\r") @@ -169,14 +169,14 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { if utf8.RuneCountInString(message) > 50 { message = fmt.Sprintf("%.47s...", message) } - textSb.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)) + text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb.WriteString("\n") + text += "\n" } } - return d.createPayload(p.Sender, title, textSb.String(), titleLink, greenColor), nil + return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index 7de26f577623f..b6ee80c44cc7a 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -76,24 +76,22 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) { commitDesc string ) - var textSb strings.Builder - textSb.WriteString(fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)) - + text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - textSb.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName) + text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb.WriteString("\r\n") + text += "\r\n" } } - return newFeishuTextPayload(textSb.String()), nil + return newFeishuTextPayload(text), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index ced947d6ad245..57b1ece26350f 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -173,20 +173,18 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) { repoLink := htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName) branchLink := MatrixLinkToRef(p.Repo.HTMLURL, p.Ref) - - var textSb strings.Builder - textSb.WriteString(fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink)) + text := fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink) // for each commit, generate a new line text for i, commit := range p.Commits { - textSb.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)) + text += fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb.WriteString("
") + text += "
" } } - return m.newPayload(textSb.String(), p.Commits...) + return m.newPayload(text, p.Commits...) } // PullRequest implements payloadConvertor PullRequest method diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index aba1b9abd17a9..450a544b42ee4 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -131,14 +131,14 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) + var text string // for each commit, generate attachment text - var textSb strings.Builder for i, commit := range p.Commits { - textSb.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)) + text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb.WriteString("\n\n") + text += "\n\n" } } @@ -146,7 +146,7 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { p.Repo, p.Sender, title, - textSb.String(), + text, titleLink, greenColor, &MSTeamsFact{"Commit count:", strconv.Itoa(p.TotalCommits)}, diff --git a/services/webhook/slack.go b/services/webhook/slack.go index 90d107ad6bf1d..3d645a55d0441 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -208,13 +208,13 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { branchLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref) text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName) + var attachmentText string // for each commit, generate attachment text - var attachmentTextSb strings.Builder for i, commit := range p.Commits { - attachmentTextSb.WriteString(fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))) + attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - attachmentTextSb.WriteString("\n") + attachmentText += "\n" } } @@ -222,7 +222,7 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { Color: s.Color, Title: p.Repo.HTMLURL, TitleLink: p.Repo.HTMLURL, - Text: attachmentTextSb.String(), + Text: attachmentText, }}), nil } diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index a4d5c4c3a6717..fdd428b45c7a0 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -94,14 +94,14 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) { } title := fmt.Sprintf(`[%s:%s] %s`, htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName), htmlLinkFormatter(titleLink, branchName), html.EscapeString(commitDesc)) - var htmlCommitsSb strings.Builder + var htmlCommits string for _, commit := range p.Commits { - htmlCommitsSb.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))) + htmlCommits += fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n"))) if commit.Author != nil { - htmlCommitsSb.WriteString(" - " + html.EscapeString(commit.Author.Name)) + htmlCommits += " - " + html.EscapeString(commit.Author.Name) } } - return createTelegramPayloadHTML(title + htmlCommitsSb.String()), nil + return createTelegramPayloadHTML(title + htmlCommits), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index a2fadee92fadf..187531740658b 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -77,8 +77,8 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error title := fmt.Sprintf("# %s:%s %s ", p.Repo.FullName, branchName, commitDesc) + var text string // for each commit, generate attachment text - var textSb strings.Builder for i, commit := range p.Commits { var authorName string if commit.Author != nil { @@ -86,15 +86,15 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error } message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n") - textSb.WriteString(fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, - message, authorName)) + text += fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, + message, authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - textSb.WriteString("\n") + text += "\n" } } - return newWechatworkMarkdownPayload(title + "\r\n\r\n" + textSb.String()), nil + return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil } // Issue implements PayloadConvertor Issue method From f2347dfea72f6715be9a373eb5662c1c44ee8231 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 3 Nov 2025 19:38:37 +0100 Subject: [PATCH 8/9] re-enable stringsbuilder and run autofix --- .golangci.yml | 3 --- models/perm/access/repo_permission.go | 16 +++++++++------- modules/git/foreachref/format.go | 6 +++--- modules/setting/config.go | 7 ++++--- modules/templates/util_render.go | 9 +++++---- routers/api/packages/rubygems/rubygems.go | 7 ++++--- routers/web/auth/oauth2_provider.go | 6 +++--- services/webhook/dingtalk.go | 10 +++++----- services/webhook/discord.go | 8 ++++---- services/webhook/feishu.go | 11 ++++++----- services/webhook/matrix.go | 9 +++++---- services/webhook/msteams.go | 10 +++++----- services/webhook/slack.go | 8 ++++---- services/webhook/telegram.go | 8 ++++---- services/webhook/wechatwork.go | 10 +++++----- 15 files changed, 66 insertions(+), 62 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 60482c415fde7..5f47de0d0d352 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -109,9 +109,6 @@ linters: - require-error usetesting: os-temp-dir: true - modernize: - disable: - - stringsbuilder perfsprint: concat-loop: false exclusions: diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 034557db33a8d..f3f6d4b0a2e39 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "slices" + "strings" actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" @@ -168,7 +169,8 @@ func (p *Permission) ReadableUnitTypes() []unit.Type { } func (p *Permission) LogString() string { - format := "") + return fmt.Sprintf(format.String(), args...) } func applyPublicAccessPermission(unitType unit.Type, accessMode perm_model.AccessMode, modeMap *map[unit.Type]perm_model.AccessMode) { diff --git a/modules/git/foreachref/format.go b/modules/git/foreachref/format.go index d9573a55d628c..d2f9998fe818c 100644 --- a/modules/git/foreachref/format.go +++ b/modules/git/foreachref/format.go @@ -75,9 +75,9 @@ func (f Format) Parser(r io.Reader) *Parser { // hexEscaped produces hex-escpaed characters from a string. For example, "\n\0" // would turn into "%0a%00". func (f Format) hexEscaped(delim []byte) string { - escaped := "" + var escaped strings.Builder for i := range delim { - escaped += "%" + hex.EncodeToString([]byte{delim[i]}) + escaped.WriteString("%" + hex.EncodeToString([]byte{delim[i]})) } - return escaped + return escaped.String() } diff --git a/modules/setting/config.go b/modules/setting/config.go index 4c5d2df7d8a01..fb99325a9561d 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -4,6 +4,7 @@ package setting import ( + "strings" "sync" "code.gitea.io/gitea/modules/log" @@ -23,11 +24,11 @@ type OpenWithEditorApp struct { type OpenWithEditorAppsType []OpenWithEditorApp func (t OpenWithEditorAppsType) ToTextareaString() string { - ret := "" + var ret strings.Builder for _, app := range t { - ret += app.DisplayName + " = " + app.OpenURL + "\n" + ret.WriteString(app.DisplayName + " = " + app.OpenURL + "\n") } - return ret + return ret.String() } func DefaultOpenWithEditorApps() OpenWithEditorAppsType { diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 132ca4d9160ae..7ff0b204f0440 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -249,17 +249,18 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML { isPullRequest := issue != nil && issue.IsPull baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues")) - htmlCode := `` + var htmlCode strings.Builder + htmlCode.WriteString(``) for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so if label == nil { continue } link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID) - htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link))) + htmlCode.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link)))) } - htmlCode += "" - return template.HTML(htmlCode) + htmlCode.WriteString("") + return template.HTML(htmlCode.String()) } func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML { diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go index 1ecf93592e17c..69764c1df3f6d 100644 --- a/routers/api/packages/rubygems/rubygems.go +++ b/routers/api/packages/rubygems/rubygems.go @@ -433,15 +433,16 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model. } func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) { - ret := "---\n" + var ret strings.Builder + ret.WriteString("---\n") for _, v := range versions { dep, err := makePackageVersionDependency(ctx, v, c) if err != nil { return "", err } - ret += dep + "\n" + ret.WriteString(dep + "\n") } - return ret, nil + return ret.String(), nil } func makeGemFullFileName(gemName, version, platform string) string { diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 1dc40d6a75fed..02e1a502858cd 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -179,11 +179,11 @@ func AuthorizeOAuth(ctx *context.Context) { errs := binding.Errors{} errs = form.Validate(ctx.Req, errs) if len(errs) > 0 { - errstring := "" + var errstring strings.Builder for _, e := range errs { - errstring += e.Error() + "\n" + errstring.WriteString(e.Error() + "\n") } - ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring)) + ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring.String())) return } diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index 5bbc610fe5c7b..955826544f6a1 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -72,22 +72,22 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text string + var text strings.Builder // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName + text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\r\n" + text.WriteString("\r\n") } } - return createDingtalkPayload(title, text, linkText, titleLink), nil + return createDingtalkPayload(title, text.String(), linkText, titleLink), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/discord.go b/services/webhook/discord.go index 6f045bd112590..19af779120da4 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -159,7 +159,7 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text string + var text strings.Builder // for each commit, generate attachment text for i, commit := range p.Commits { // limit the commit message display to just the summary, otherwise it would be hard to read @@ -169,14 +169,14 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { if utf8.RuneCountInString(message) > 50 { message = fmt.Sprintf("%.47s...", message) } - text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name) + text.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\n" + text.WriteString("\n") } } - return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil + return d.createPayload(p.Sender, title, text.String(), titleLink, greenColor), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index b6ee80c44cc7a..ecce9acc43621 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -76,22 +76,23 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) { commitDesc string ) - text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) + var text strings.Builder + text.WriteString(fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)) // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName + text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\r\n" + text.WriteString("\r\n") } } - return newFeishuTextPayload(text), nil + return newFeishuTextPayload(text.String()), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index 57b1ece26350f..63fbbf40a962f 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -173,18 +173,19 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) { repoLink := htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName) branchLink := MatrixLinkToRef(p.Repo.HTMLURL, p.Ref) - text := fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink) + var text strings.Builder + text.WriteString(fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink)) // for each commit, generate a new line text for i, commit := range p.Commits { - text += fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name) + text.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "
" + text.WriteString("
") } } - return m.newPayload(text, p.Commits...) + return m.newPayload(text.String(), p.Commits...) } // PullRequest implements payloadConvertor PullRequest method diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index 450a544b42ee4..fa39e7228e3ad 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -131,14 +131,14 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text string + var text strings.Builder // for each commit, generate attachment text for i, commit := range p.Commits { - text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name) + text.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\n\n" + text.WriteString("\n\n") } } @@ -146,7 +146,7 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { p.Repo, p.Sender, title, - text, + text.String(), titleLink, greenColor, &MSTeamsFact{"Commit count:", strconv.Itoa(p.TotalCommits)}, diff --git a/services/webhook/slack.go b/services/webhook/slack.go index 3d645a55d0441..0b3dda467cc09 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -208,13 +208,13 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { branchLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref) text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName) - var attachmentText string + var attachmentText strings.Builder // for each commit, generate attachment text for i, commit := range p.Commits { - attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)) + attachmentText.WriteString(fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - attachmentText += "\n" + attachmentText.WriteString("\n") } } @@ -222,7 +222,7 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { Color: s.Color, Title: p.Repo.HTMLURL, TitleLink: p.Repo.HTMLURL, - Text: attachmentText, + Text: attachmentText.String(), }}), nil } diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index fdd428b45c7a0..2abc743fabd3f 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -94,14 +94,14 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) { } title := fmt.Sprintf(`[%s:%s] %s`, htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName), htmlLinkFormatter(titleLink, branchName), html.EscapeString(commitDesc)) - var htmlCommits string + var htmlCommits strings.Builder for _, commit := range p.Commits { - htmlCommits += fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n"))) + htmlCommits.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))) if commit.Author != nil { - htmlCommits += " - " + html.EscapeString(commit.Author.Name) + htmlCommits.WriteString(" - " + html.EscapeString(commit.Author.Name)) } } - return createTelegramPayloadHTML(title + htmlCommits), nil + return createTelegramPayloadHTML(title + htmlCommits.String()), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index 187531740658b..da9c6b584c288 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -77,7 +77,7 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error title := fmt.Sprintf("# %s:%s %s ", p.Repo.FullName, branchName, commitDesc) - var text string + var text strings.Builder // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string @@ -86,15 +86,15 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error } message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n") - text += fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, - message, authorName) + text.WriteString(fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, + message, authorName)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\n" + text.WriteString("\n") } } - return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil + return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text.String()), nil } // Issue implements PayloadConvertor Issue method From 1cff2d427a0b8f82f7cb82e9b1ef63fffd1b619f Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 3 Nov 2025 19:43:27 +0100 Subject: [PATCH 9/9] Revert "re-enable stringsbuilder and run autofix" This reverts commit f2347dfea72f6715be9a373eb5662c1c44ee8231. --- .golangci.yml | 3 +++ models/perm/access/repo_permission.go | 16 +++++++--------- modules/git/foreachref/format.go | 6 +++--- modules/setting/config.go | 7 +++---- modules/templates/util_render.go | 9 ++++----- routers/api/packages/rubygems/rubygems.go | 7 +++---- routers/web/auth/oauth2_provider.go | 6 +++--- services/webhook/dingtalk.go | 10 +++++----- services/webhook/discord.go | 8 ++++---- services/webhook/feishu.go | 11 +++++------ services/webhook/matrix.go | 9 ++++----- services/webhook/msteams.go | 10 +++++----- services/webhook/slack.go | 8 ++++---- services/webhook/telegram.go | 8 ++++---- services/webhook/wechatwork.go | 10 +++++----- 15 files changed, 62 insertions(+), 66 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5f47de0d0d352..60482c415fde7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -109,6 +109,9 @@ linters: - require-error usetesting: os-temp-dir: true + modernize: + disable: + - stringsbuilder perfsprint: concat-loop: false exclusions: diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index f3f6d4b0a2e39..034557db33a8d 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "slices" - "strings" actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" @@ -169,8 +168,7 @@ func (p *Permission) ReadableUnitTypes() []unit.Type { } func (p *Permission) LogString() string { - var format strings.Builder - format.WriteString("") - return fmt.Sprintf(format.String(), args...) + format += "\n\t]>" + return fmt.Sprintf(format, args...) } func applyPublicAccessPermission(unitType unit.Type, accessMode perm_model.AccessMode, modeMap *map[unit.Type]perm_model.AccessMode) { diff --git a/modules/git/foreachref/format.go b/modules/git/foreachref/format.go index d2f9998fe818c..d9573a55d628c 100644 --- a/modules/git/foreachref/format.go +++ b/modules/git/foreachref/format.go @@ -75,9 +75,9 @@ func (f Format) Parser(r io.Reader) *Parser { // hexEscaped produces hex-escpaed characters from a string. For example, "\n\0" // would turn into "%0a%00". func (f Format) hexEscaped(delim []byte) string { - var escaped strings.Builder + escaped := "" for i := range delim { - escaped.WriteString("%" + hex.EncodeToString([]byte{delim[i]})) + escaped += "%" + hex.EncodeToString([]byte{delim[i]}) } - return escaped.String() + return escaped } diff --git a/modules/setting/config.go b/modules/setting/config.go index fb99325a9561d..4c5d2df7d8a01 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -4,7 +4,6 @@ package setting import ( - "strings" "sync" "code.gitea.io/gitea/modules/log" @@ -24,11 +23,11 @@ type OpenWithEditorApp struct { type OpenWithEditorAppsType []OpenWithEditorApp func (t OpenWithEditorAppsType) ToTextareaString() string { - var ret strings.Builder + ret := "" for _, app := range t { - ret.WriteString(app.DisplayName + " = " + app.OpenURL + "\n") + ret += app.DisplayName + " = " + app.OpenURL + "\n" } - return ret.String() + return ret } func DefaultOpenWithEditorApps() OpenWithEditorAppsType { diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 7ff0b204f0440..132ca4d9160ae 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -249,18 +249,17 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML { isPullRequest := issue != nil && issue.IsPull baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues")) - var htmlCode strings.Builder - htmlCode.WriteString(``) + htmlCode := `` for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so if label == nil { continue } link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID) - htmlCode.WriteString(string(ut.RenderLabelWithLink(label, template.URL(link)))) + htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link))) } - htmlCode.WriteString("") - return template.HTML(htmlCode.String()) + htmlCode += "" + return template.HTML(htmlCode) } func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML { diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go index 69764c1df3f6d..1ecf93592e17c 100644 --- a/routers/api/packages/rubygems/rubygems.go +++ b/routers/api/packages/rubygems/rubygems.go @@ -433,16 +433,15 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model. } func makePackageInfo(ctx *context.Context, versions []*packages_model.PackageVersion, c *cache.EphemeralCache) (string, error) { - var ret strings.Builder - ret.WriteString("---\n") + ret := "---\n" for _, v := range versions { dep, err := makePackageVersionDependency(ctx, v, c) if err != nil { return "", err } - ret.WriteString(dep + "\n") + ret += dep + "\n" } - return ret.String(), nil + return ret, nil } func makeGemFullFileName(gemName, version, platform string) string { diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 02e1a502858cd..1dc40d6a75fed 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -179,11 +179,11 @@ func AuthorizeOAuth(ctx *context.Context) { errs := binding.Errors{} errs = form.Validate(ctx.Req, errs) if len(errs) > 0 { - var errstring strings.Builder + errstring := "" for _, e := range errs { - errstring.WriteString(e.Error() + "\n") + errstring += e.Error() + "\n" } - ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring.String())) + ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring)) return } diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index 955826544f6a1..5bbc610fe5c7b 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -72,22 +72,22 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text strings.Builder + var text string // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName) + text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text.WriteString("\r\n") + text += "\r\n" } } - return createDingtalkPayload(title, text.String(), linkText, titleLink), nil + return createDingtalkPayload(title, text, linkText, titleLink), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/discord.go b/services/webhook/discord.go index 19af779120da4..6f045bd112590 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -159,7 +159,7 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text strings.Builder + var text string // for each commit, generate attachment text for i, commit := range p.Commits { // limit the commit message display to just the summary, otherwise it would be hard to read @@ -169,14 +169,14 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { if utf8.RuneCountInString(message) > 50 { message = fmt.Sprintf("%.47s...", message) } - text.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)) + text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text.WriteString("\n") + text += "\n" } } - return d.createPayload(p.Sender, title, text.String(), titleLink, greenColor), nil + return d.createPayload(p.Sender, title, text, titleLink, greenColor), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index ecce9acc43621..b6ee80c44cc7a 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -76,23 +76,22 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) { commitDesc string ) - var text strings.Builder - text.WriteString(fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)) + text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string if commit.Author != nil { authorName = " - " + commit.Author.Name } - text.WriteString(fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n")) + authorName) + text += fmt.Sprintf("[%s](%s) %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n")) + authorName // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text.WriteString("\r\n") + text += "\r\n" } } - return newFeishuTextPayload(text.String()), nil + return newFeishuTextPayload(text), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index 63fbbf40a962f..57b1ece26350f 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -173,19 +173,18 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) { repoLink := htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName) branchLink := MatrixLinkToRef(p.Repo.HTMLURL, p.Ref) - var text strings.Builder - text.WriteString(fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink)) + text := fmt.Sprintf("[%s] %s pushed %s to %s:
", repoLink, p.Pusher.UserName, commitDesc, branchLink) // for each commit, generate a new line text for i, commit := range p.Commits { - text.WriteString(fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name)) + text += fmt.Sprintf("%s: %s - %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), commit.Message, commit.Author.Name) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text.WriteString("
") + text += "
" } } - return m.newPayload(text.String(), p.Commits...) + return m.newPayload(text, p.Commits...) } // PullRequest implements payloadConvertor PullRequest method diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index fa39e7228e3ad..450a544b42ee4 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -131,14 +131,14 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc) - var text strings.Builder + var text string // for each commit, generate attachment text for i, commit := range p.Commits { - text.WriteString(fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)) + text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, + strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text.WriteString("\n\n") + text += "\n\n" } } @@ -146,7 +146,7 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) { p.Repo, p.Sender, title, - text.String(), + text, titleLink, greenColor, &MSTeamsFact{"Commit count:", strconv.Itoa(p.TotalCommits)}, diff --git a/services/webhook/slack.go b/services/webhook/slack.go index 0b3dda467cc09..3d645a55d0441 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -208,13 +208,13 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { branchLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref) text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName) - var attachmentText strings.Builder + var attachmentText string // for each commit, generate attachment text for i, commit := range p.Commits { - attachmentText.WriteString(fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))) + attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - attachmentText.WriteString("\n") + attachmentText += "\n" } } @@ -222,7 +222,7 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) { Color: s.Color, Title: p.Repo.HTMLURL, TitleLink: p.Repo.HTMLURL, - Text: attachmentText.String(), + Text: attachmentText, }}), nil } diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index 2abc743fabd3f..fdd428b45c7a0 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -94,14 +94,14 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) { } title := fmt.Sprintf(`[%s:%s] %s`, htmlLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName), htmlLinkFormatter(titleLink, branchName), html.EscapeString(commitDesc)) - var htmlCommits strings.Builder + var htmlCommits string for _, commit := range p.Commits { - htmlCommits.WriteString(fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n")))) + htmlCommits += fmt.Sprintf("\n[%s] %s", htmlLinkFormatter(commit.URL, commit.ID[:7]), html.EscapeString(strings.TrimRight(commit.Message, "\r\n"))) if commit.Author != nil { - htmlCommits.WriteString(" - " + html.EscapeString(commit.Author.Name)) + htmlCommits += " - " + html.EscapeString(commit.Author.Name) } } - return createTelegramPayloadHTML(title + htmlCommits.String()), nil + return createTelegramPayloadHTML(title + htmlCommits), nil } // Issue implements PayloadConvertor Issue method diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index da9c6b584c288..187531740658b 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -77,7 +77,7 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error title := fmt.Sprintf("# %s:%s %s ", p.Repo.FullName, branchName, commitDesc) - var text strings.Builder + var text string // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string @@ -86,15 +86,15 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error } message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n") - text.WriteString(fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, - message, authorName)) + text += fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, + message, authorName) // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text.WriteString("\n") + text += "\n" } } - return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text.String()), nil + return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil } // Issue implements PayloadConvertor Issue method