chore: misc go 1.27 tweaks (#39069)

Follow-up to https://github.com/go-gitea/gitea/pull/39068, which
disabled `modernize` entirely.

- re-enable `modernize`, with only the new `embedlit` rule disabled. It
flattens embedded struct literals across ~145 files, and orphans imports
in 6 of them that the fixer does not remove
- apply the rest of the suite: `errors.AsType`, `reflect.TypeAssert`,
`strings.Cut`, and dropping the legacy import comment
- use the new stdlib `uuid` package, `github.com/google/uuid` becomes
indirect
- use `strings.CutLast` in place of manual `LastIndex` slicing in label
scopes, email domains and the diff tree list
- take the header lint skip dirs from the `go.mod` `ignore` directive
and skip dot-directories, instead of hardcoding the list

Assisted-by: Claude Code:claude-opus-5
This commit is contained in:
silverwind
2026-08-24 20:26:10 +02:00
committed by GitHub
parent 59a43c8733
commit 32728fc581
32 changed files with 83 additions and 72 deletions
+1 -1
View File
@@ -14,6 +14,7 @@ import (
"slices"
"strings"
"time"
"uuid"
"gitea.dev/models/db"
"gitea.dev/modules/container"
@@ -21,7 +22,6 @@ import (
"gitea.dev/modules/timeutil"
"gitea.dev/modules/util"
uuid "github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
"golang.org/x/oauth2"
"xorm.io/builder"
+3 -3
View File
@@ -186,11 +186,11 @@ func (l *Label) ExclusiveScope() string {
if !l.Exclusive {
return ""
}
lastIndex := strings.LastIndex(l.Name, "/")
if lastIndex == -1 || lastIndex == 0 || lastIndex == len(l.Name)-1 {
scope, name, found := strings.CutLast(l.Name, "/")
if !found || scope == "" || name == "" {
return ""
}
return l.Name[:lastIndex]
return scope
}
// CompareLabelForDisplay compares labels for displaying them in dropdowns or lists.
+1 -1
View File
@@ -617,7 +617,7 @@ func searchRepositoryByCondition(ctx context.Context, opts SearchRepoOptions, co
args = append(args, opts.PriorityOwnerID)
} else if strings.Count(opts.Keyword, "/") == 1 {
// With "owner/repo" search times, prioritise results which match the owner field
orgName := strings.Split(opts.Keyword, "/")[0]
orgName, _, _ := strings.Cut(opts.Keyword, "/")
orderBy = db.SearchOrderBy(fmt.Sprintf("CASE WHEN owner_name LIKE ? THEN 0 ELSE 1 END, %s", orderBy))
args = append(args, orgName)
}
+2 -3
View File
@@ -11,13 +11,12 @@ import (
"mime/multipart"
"os"
"path/filepath"
"uuid"
"gitea.dev/models/db"
"gitea.dev/modules/log"
"gitea.dev/modules/setting"
"gitea.dev/modules/util"
gouuid "github.com/google/uuid"
)
// ErrUploadNotExist represents a "UploadNotExist" kind of error.
@@ -60,7 +59,7 @@ func (upload *Upload) LocalPath() string {
// NewUpload creates a new upload object.
func NewUpload(ctx context.Context, name string, buf []byte, file multipart.File) (_ *Upload, err error) {
upload := &Upload{
UUID: gouuid.New().String(),
UUID: uuid.New().String(),
Name: name,
}
+2 -2
View File
@@ -7,6 +7,7 @@ import (
"context"
"errors"
"time"
"uuid"
"gitea.dev/models/db"
"gitea.dev/modules/json"
@@ -15,7 +16,6 @@ import (
"gitea.dev/modules/timeutil"
webhook_module "gitea.dev/modules/webhook"
gouuid "github.com/google/uuid"
"xorm.io/builder"
)
@@ -119,7 +119,7 @@ func HookTasks(ctx context.Context, hookID int64, page int) ([]*HookTask, error)
// CreateHookTask creates a new hook task,
// it handles conversion from Payload to PayloadContent.
func CreateHookTask(ctx context.Context, t *HookTask) (*HookTask, error) {
t.UUID = gouuid.New().String()
t.UUID = uuid.New().String()
if t.Delivered == 0 {
t.Delivered = timeutil.TimeStampNanoNow()
}
+1 -1
View File
@@ -7,6 +7,7 @@ import (
"context"
"testing"
"time"
"uuid"
"gitea.dev/models/db"
"gitea.dev/models/unittest"
@@ -15,7 +16,6 @@ import (
"gitea.dev/modules/timeutil"
webhook_module "gitea.dev/modules/webhook"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"xorm.io/builder"