Skip to content

Commit

Permalink
Replace yaml.v2 with yaml.v3 (#21832)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wolfogre authored Nov 21, 2022
1 parent b4802b9 commit e4eaa68
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ require (
golang.org/x/tools v0.1.12
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
mvdan.cc/xurls/v2 v2.4.0
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
Expand Down Expand Up @@ -293,6 +292,7 @@ require (
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

Expand Down
11 changes: 5 additions & 6 deletions modules/migration/file_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"fmt"
"os"
"strings"
"time"

"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"

"github.com/santhosh-tekuri/jsonschema/v5"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

// Load project data from file, with optional validation
Expand Down Expand Up @@ -84,13 +85,9 @@ func validate(bs []byte, datatype interface{}, isJSON bool) error {
func toStringKeys(val interface{}) (interface{}, error) {
var err error
switch val := val.(type) {
case map[interface{}]interface{}:
case map[string]interface{}:
m := make(map[string]interface{})
for k, v := range val {
k, ok := k.(string)
if !ok {
return nil, fmt.Errorf("found non-string key %T %s", k, k)
}
m[k], err = toStringKeys(v)
if err != nil {
return nil, err
Expand All @@ -106,6 +103,8 @@ func toStringKeys(val interface{}) (interface{}, error) {
}
}
return l, nil
case time.Time:
return val.Format(time.RFC3339), nil
default:
return val, nil
}
Expand Down
2 changes: 1 addition & 1 deletion modules/packages/helm/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"code.gitea.io/gitea/modules/validation"

"github.com/hashicorp/go-version"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion modules/packages/pub/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"code.gitea.io/gitea/modules/validation"

"github.com/hashicorp/go-version"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions modules/packages/rubygems/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

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

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var (
Expand Down Expand Up @@ -120,7 +120,7 @@ func (r requirement) AsVersionRequirement() []VersionRequirement {
if !ok {
continue
}
vm, ok := req[1].(map[interface{}]interface{})
vm, ok := req[1].(map[string]interface{})
if !ok {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"code.gitea.io/gitea/routers/api/packages/helper"
packages_service "code.gitea.io/gitea/services/packages"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

func apiError(ctx *context.Context, status int, obj interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion services/migrations/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"code.gitea.io/gitea/modules/structs"

"github.com/google/uuid"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var _ base.Uploader = &RepositoryDumper{}
Expand Down
2 changes: 1 addition & 1 deletion services/migrations/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

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

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

// RepositoryRestorer implements an Downloader from the local directory
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api_packages_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

func TestPackageHelm(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/dump_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"code.gitea.io/gitea/services/migrations"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

func TestDumpRestore(t *testing.T) {
Expand Down

0 comments on commit e4eaa68

Please sign in to comment.