Skip to content

Commit 2faaf81

Browse files
wolfogrefsologureng
authored andcommitted
Replace yaml.v2 with yaml.v3 (go-gitea#21832)
I don't see why we have to use two versions of yaml. The difference between the two versions has nothing to do with our usage.
1 parent 50af57f commit 2faaf81

File tree

10 files changed

+15
-16
lines changed

10 files changed

+15
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ require (
102102
golang.org/x/tools v0.1.12
103103
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
104104
gopkg.in/ini.v1 v1.67.0
105-
gopkg.in/yaml.v2 v2.4.0
106105
gopkg.in/yaml.v3 v3.0.1
107106
mvdan.cc/xurls/v2 v2.4.0
108107
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
@@ -293,6 +292,7 @@ require (
293292
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
294293
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
295294
gopkg.in/warnings.v0 v0.1.2 // indirect
295+
gopkg.in/yaml.v2 v2.4.0 // indirect
296296
sigs.k8s.io/yaml v1.2.0 // indirect
297297
)
298298

modules/migration/file_format.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"fmt"
99
"os"
1010
"strings"
11+
"time"
1112

1213
"code.gitea.io/gitea/modules/json"
1314
"code.gitea.io/gitea/modules/log"
1415

1516
"github.com/santhosh-tekuri/jsonschema/v5"
16-
"gopkg.in/yaml.v2"
17+
"gopkg.in/yaml.v3"
1718
)
1819

1920
// Load project data from file, with optional validation
@@ -84,13 +85,9 @@ func validate(bs []byte, datatype interface{}, isJSON bool) error {
8485
func toStringKeys(val interface{}) (interface{}, error) {
8586
var err error
8687
switch val := val.(type) {
87-
case map[interface{}]interface{}:
88+
case map[string]interface{}:
8889
m := make(map[string]interface{})
8990
for k, v := range val {
90-
k, ok := k.(string)
91-
if !ok {
92-
return nil, fmt.Errorf("found non-string key %T %s", k, k)
93-
}
9491
m[k], err = toStringKeys(v)
9592
if err != nil {
9693
return nil, err
@@ -106,6 +103,8 @@ func toStringKeys(val interface{}) (interface{}, error) {
106103
}
107104
}
108105
return l, nil
106+
case time.Time:
107+
return val.Format(time.RFC3339), nil
109108
default:
110109
return val, nil
111110
}

modules/packages/helm/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/validation"
1515

1616
"github.com/hashicorp/go-version"
17-
"gopkg.in/yaml.v2"
17+
"gopkg.in/yaml.v3"
1818
)
1919

2020
var (

modules/packages/pub/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"code.gitea.io/gitea/modules/validation"
1616

1717
"github.com/hashicorp/go-version"
18-
"gopkg.in/yaml.v2"
18+
"gopkg.in/yaml.v3"
1919
)
2020

2121
var (

modules/packages/rubygems/metadata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
"code.gitea.io/gitea/modules/validation"
1616

17-
"gopkg.in/yaml.v2"
17+
"gopkg.in/yaml.v3"
1818
)
1919

2020
var (
@@ -120,7 +120,7 @@ func (r requirement) AsVersionRequirement() []VersionRequirement {
120120
if !ok {
121121
continue
122122
}
123-
vm, ok := req[1].(map[interface{}]interface{})
123+
vm, ok := req[1].(map[string]interface{})
124124
if !ok {
125125
continue
126126
}

routers/api/packages/helm/helm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"code.gitea.io/gitea/routers/api/packages/helper"
2424
packages_service "code.gitea.io/gitea/services/packages"
2525

26-
"gopkg.in/yaml.v2"
26+
"gopkg.in/yaml.v3"
2727
)
2828

2929
func apiError(ctx *context.Context, status int, obj interface{}) {

services/migrations/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"code.gitea.io/gitea/modules/structs"
2727

2828
"github.com/google/uuid"
29-
"gopkg.in/yaml.v2"
29+
"gopkg.in/yaml.v3"
3030
)
3131

3232
var _ base.Uploader = &RepositoryDumper{}

services/migrations/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
base "code.gitea.io/gitea/modules/migration"
1515

16-
"gopkg.in/yaml.v2"
16+
"gopkg.in/yaml.v3"
1717
)
1818

1919
// RepositoryRestorer implements an Downloader from the local directory

tests/integration/api_packages_helm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"code.gitea.io/gitea/tests"
2323

2424
"github.com/stretchr/testify/assert"
25-
"gopkg.in/yaml.v2"
25+
"gopkg.in/yaml.v3"
2626
)
2727

2828
func TestPackageHelm(t *testing.T) {

tests/integration/dump_restore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"code.gitea.io/gitea/services/migrations"
2626

2727
"github.com/stretchr/testify/assert"
28-
"gopkg.in/yaml.v2"
28+
"gopkg.in/yaml.v3"
2929
)
3030

3131
func TestDumpRestore(t *testing.T) {

0 commit comments

Comments
 (0)