enhance: Migrate remaining gopkg.in/yaml.v3 usages to go.yaml.in/yaml/v4 (#37866)

### Description
Replaces all remaining direct `gopkg.in/yaml.v3` imports with
`go.yaml.in/yaml/v4` across models, modules, routers, services, and
integration tests. `gopkg.in/yaml.v3` moves from a direct to an indirect
dependency in `go.mod`.

#### API compatibility

The yaml.Node type, node.Kind/node.Content traversal style
(modules/markup/markdown/convertyaml.go), and the
UnmarshalYAML(*yaml.Node) interface signature
(modules/optional/serialization.go) are all preserved in v4 — no
call-site changes were required beyond the import path.

**Related:**
- https://github.com/go-gitea/gitea/pull/36564#issuecomment-4526536805

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Claude (Opus 4.8) <noreply@anthropic.com>
This commit is contained in:
Pascal Zimmermann
2026-05-29 01:12:11 +00:00
committed by GitHub
co-authored by silverwind Claude
parent 90d443b46c
commit ea723fe482
24 changed files with 26 additions and 26 deletions
+1 -1
View File
@@ -113,7 +113,6 @@ require (
google.golang.org/grpc v1.81.1 google.golang.org/grpc v1.81.1
google.golang.org/protobuf v1.36.11 google.golang.org/protobuf v1.36.11
gopkg.in/ini.v1 v1.67.2 gopkg.in/ini.v1 v1.67.2
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.50.1 modernc.org/sqlite v1.50.1
mvdan.cc/xurls/v2 v2.6.0 mvdan.cc/xurls/v2 v2.6.0
strk.kbt.io/projects/go/libravatar v0.0.0-20260301104140-add494e31dab strk.kbt.io/projects/go/libravatar v0.0.0-20260301104140-add494e31dab
@@ -282,6 +281,7 @@ require (
golang.org/x/tools v0.44.0 // indirect golang.org/x/tools v0.44.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401020348-3a24fdc17823 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260401020348-3a24fdc17823 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.72.3 // indirect modernc.org/libc v1.72.3 // indirect
modernc.org/mathutil v1.7.1 // indirect modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect modernc.org/memory v1.11.0 // indirect
+1 -1
View File
@@ -16,7 +16,7 @@ import (
"gitea.dev/models/db" "gitea.dev/models/db"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
"xorm.io/xorm" "xorm.io/xorm"
"xorm.io/xorm/schemas" "xorm.io/xorm/schemas"
) )
+1 -1
View File
@@ -14,7 +14,7 @@ import (
api "gitea.dev/modules/structs" api "gitea.dev/modules/structs"
"gitea.dev/modules/util" "gitea.dev/modules/util"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
// CouldBe indicates a file with the filename could be a template, // CouldBe indicates a file with the filename could be a template,
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"gitea.dev/modules/options" "gitea.dev/modules/options"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
type labelFile struct { type labelFile struct {
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/ast"
east "github.com/yuin/goldmark/extension/ast" east "github.com/yuin/goldmark/extension/ast"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func nodeToTable(meta *yaml.Node) ast.Node { func nodeToTable(meta *yaml.Node) ast.Node {
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func isYAMLSeparator(line []byte) bool { func isYAMLSeparator(line []byte) bool {
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"gitea.dev/modules/markup" "gitea.dev/modules/markup"
"github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/ast"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
// RenderConfig represents rendering configuration for this file // RenderConfig represents rendering configuration for this file
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func TestRenderConfig_UnmarshalYAML(t *testing.T) { func TestRenderConfig_UnmarshalYAML(t *testing.T) {
+1 -1
View File
@@ -13,7 +13,7 @@ import (
"gitea.dev/modules/log" "gitea.dev/modules/log"
"github.com/santhosh-tekuri/jsonschema/v6" "github.com/santhosh-tekuri/jsonschema/v6"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
// schemaLoader implements jsonschema.URLLoader // schemaLoader implements jsonschema.URLLoader
+1 -1
View File
@@ -6,7 +6,7 @@ package optional
import ( import (
"gitea.dev/modules/json" "gitea.dev/modules/json"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func (o *Option[T]) UnmarshalJSON(data []byte) error { func (o *Option[T]) UnmarshalJSON(data []byte) error {
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"gitea.dev/modules/optional" "gitea.dev/modules/optional"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
type testSerializationStruct struct { type testSerializationStruct struct {
+1 -1
View File
@@ -13,7 +13,7 @@ import (
"gitea.dev/modules/validation" "gitea.dev/modules/validation"
"github.com/hashicorp/go-version" "github.com/hashicorp/go-version"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
var ( var (
+1 -1
View File
@@ -14,7 +14,7 @@ import (
"gitea.dev/modules/validation" "gitea.dev/modules/validation"
"github.com/hashicorp/go-version" "github.com/hashicorp/go-version"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
var ( var (
+1 -1
View File
@@ -14,7 +14,7 @@ import (
"gitea.dev/modules/util" "gitea.dev/modules/util"
"gitea.dev/modules/validation" "gitea.dev/modules/validation"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
var ( var (
+2 -2
View File
@@ -10,7 +10,7 @@ import (
"strings" "strings"
"time" "time"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
// StateType issue state type // StateType issue state type
@@ -231,7 +231,7 @@ func (l *IssueTemplateStringSlice) UnmarshalYAML(value *yaml.Node) error {
*l = labels *l = labels
return nil return nil
} }
return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateStringSlice", value.Line, value.ShortTag()) return fmt.Errorf("cannot unmarshal %s into IssueTemplateStringSlice", value.ShortTag())
} }
type IssueConfigContactLink struct { type IssueConfigContactLink struct {
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func TestIssueTemplate_Type(t *testing.T) { func TestIssueTemplate_Type(t *testing.T) {
@@ -88,7 +88,7 @@ labels:
b: bb b: bb
`, `,
tmpl: &IssueTemplate{}, tmpl: &IssueTemplate{},
wantErr: "line 3: cannot unmarshal !!map into IssueTemplateStringSlice", wantErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!map into IssueTemplateStringSlice",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
+1 -1
View File
@@ -23,7 +23,7 @@ import (
"gitea.dev/services/context" "gitea.dev/services/context"
packages_service "gitea.dev/services/packages" packages_service "gitea.dev/services/packages"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func apiError(ctx *context.Context, status int, obj any) { func apiError(ctx *context.Context, status int, obj any) {
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"gitea.dev/services/context" "gitea.dev/services/context"
"gitea.dev/services/mailer" "gitea.dev/services/mailer"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func MailPreviewRender(ctx *context.Context) { func MailPreviewRender(ctx *context.Context) {
+1 -1
View File
@@ -16,7 +16,7 @@ import (
api "gitea.dev/modules/structs" api "gitea.dev/modules/structs"
"gitea.dev/modules/util" "gitea.dev/modules/util"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
// templateDirCandidates issue templates directory // templateDirCandidates issue templates directory
+1 -1
View File
@@ -26,7 +26,7 @@ import (
"gitea.dev/modules/structs" "gitea.dev/modules/structs"
"github.com/google/uuid" "github.com/google/uuid"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
var _ base.Uploader = &RepositoryDumper{} var _ base.Uploader = &RepositoryDumper{}
+1 -1
View File
@@ -12,7 +12,7 @@ import (
base "gitea.dev/modules/migration" base "gitea.dev/modules/migration"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
// RepositoryRestorer implements an Downloader from the local directory // RepositoryRestorer implements an Downloader from the local directory
+1 -1
View File
@@ -16,7 +16,7 @@ import (
"gitea.dev/tests" "gitea.dev/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func createIssueConfig(t *testing.T, user *user_model.User, repo *repo_model.Repository, issueConfig map[string]any) { func createIssueConfig(t *testing.T, user *user_model.User, repo *repo_model.Repository, issueConfig map[string]any) {
+1 -1
View File
@@ -20,7 +20,7 @@ import (
"gitea.dev/tests" "gitea.dev/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func TestPackageHelm(t *testing.T) { func TestPackageHelm(t *testing.T) {
+1 -1
View File
@@ -24,7 +24,7 @@ import (
"gitea.dev/services/migrations" "gitea.dev/services/migrations"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "go.yaml.in/yaml/v4"
) )
func TestDumpRestore(t *testing.T) { func TestDumpRestore(t *testing.T) {