Skip to content

Commit ee862f4

Browse files
committed
Change method to normalize lock reason in the API endpoint
1 parent 0b134aa commit ee862f4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

routers/api/v1/repo/issue_lock.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"errors"
88
"net/http"
99
"strings"
10-
"unicode"
1110

1211
issues_model "code.gitea.io/gitea/models/issues"
1312
api "code.gitea.io/gitea/modules/structs"
1413
"code.gitea.io/gitea/modules/web"
1514
"code.gitea.io/gitea/services/context"
15+
16+
"golang.org/x/text/cases"
17+
"golang.org/x/text/language"
1618
)
1719

1820
// LockIssue lock an issue
@@ -55,15 +57,12 @@ func LockIssue(ctx *context.APIContext) {
5557
// "404":
5658
// "$ref": "#/responses/notFound"
5759

60+
caser := cases.Title(language.English)
5861
reason := web.GetForm(ctx).(*api.LockIssueOption).Reason
5962
reason = strings.ToLower(reason)
60-
61-
if reason != "" {
62-
// make the first character uppercase
63-
runes := []rune(reason)
64-
runes[0] = unicode.ToUpper(runes[0])
65-
reason = string(runes)
66-
}
63+
reason_parts := strings.Split(reason, " ")
64+
reason_parts[0] = caser.String(reason_parts[0])
65+
reason = strings.Join(reason_parts, " ")
6766

6867
if !issues_model.IsValidReason(reason) {
6968
ctx.APIError(http.StatusBadRequest, errors.New("reason not valid"))

0 commit comments

Comments
 (0)