updated g2g dependencies
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2021-11-07 21:13:07 +01:00
parent 0c587b783f
commit 174289b1fe
10 changed files with 104 additions and 85 deletions

9
go.mod
View File

@ -2,9 +2,6 @@ module git.paulbsd.com/paulbsd/g2g
go 1.17 go 1.17
require ( require gopkg.in/ini.v1 v1.63.2
github.com/gopherjs/gopherjs v0.0.0-20210406100015-1e088ea4ee04 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect require github.com/stretchr/testify v1.7.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
gopkg.in/ini.v1 v1.62.0
)

29
go.sum
View File

@ -1,17 +1,12 @@
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/gopherjs/gopherjs v0.0.0-20210406100015-1e088ea4ee04 h1:Enykqupm0u6qiUZAc+SiFkMJVqt4o8knNcKJu8NdlJ0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gopherjs/gopherjs v0.0.0-20210406100015-1e088ea4ee04/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

View File

@ -43,7 +43,7 @@ func GetReposFromGitHub(config *config.Config) ([]GitHubRepo, error) {
} }
} }
fmt.Println(fmt.Sprintf("%d repositories fetched from Github", len(repofulllist))) fmt.Printf("%d repositories fetched from Github\n", len(repofulllist))
return repofulllist, nil return repofulllist, nil
} }
@ -64,7 +64,7 @@ func GetGitHubResponse(config *config.Config, url string) (*http.Response, error
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Error on status code %s", resp.Status) return nil, fmt.Errorf("error on status code %s", resp.Status)
} }
return resp, nil return resp, nil
@ -77,6 +77,9 @@ func CheckGiteaExistingRepo(config *config.Config, repo GitHubRepo) (bool, error
gitearepourl := fmt.Sprintf(config.GiteaRepoURLTmpl, config.GiteaDestUsername, repo.Name) gitearepourl := fmt.Sprintf(config.GiteaRepoURLTmpl, config.GiteaDestUsername, repo.Name)
req, err := http.NewRequest("GET", gitearepourl, nil) req, err := http.NewRequest("GET", gitearepourl, nil)
if err != nil {
return false, err
}
req.Header.Set("Authorization", config.GiteaAuthToken) req.Header.Set("Authorization", config.GiteaAuthToken)
client := &http.Client{} client := &http.Client{}
@ -90,7 +93,7 @@ func CheckGiteaExistingRepo(config *config.Config, repo GitHubRepo) (bool, error
} else if resp.StatusCode == http.StatusNotFound { } else if resp.StatusCode == http.StatusNotFound {
isExists = false isExists = false
} else { } else {
return false, fmt.Errorf("Can't determine error, cancelling, error %s in gitea webservice", resp.Status) return false, fmt.Errorf("can't determine error, cancelling, error %s in gitea webservice", resp.Status)
} }
return isExists, nil return isExists, nil
@ -116,15 +119,18 @@ func GetGiteaUserUID(config *config.Config) error {
} }
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
err = errors.New("Error invoking gitea webservice") err = errors.New("error invoking gitea webservice")
return err return err
} }
respbody, err := ioutil.ReadAll(resp.Body) respbody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
err = json.Unmarshal(respbody, &giteaorg) err = json.Unmarshal(respbody, &giteaorg)
if err != nil { if err != nil {
err = errors.New("Failed to parse user ID from gitea webservice, check auth") err = errors.New("failed to parse user ID from gitea webservice, check auth")
return err return err
} }
@ -158,46 +164,21 @@ func MigrateReposToGitea(config *config.Config, wg *sync.WaitGroup, jobs chan Gi
for { for {
elem, more := <-jobs elem, more := <-jobs
if more { if more {
client := &http.Client{}
existingrepo, err := CheckGiteaExistingRepo(config, elem) existingrepo, err := CheckGiteaExistingRepo(config, elem)
if err != nil { if err != nil {
return err return err
} }
if !existingrepo { if !existingrepo {
repo := GiteaRepo{ err = MigrateRepo(elem, config)
UID: config.GiteaUID,
RepoName: elem.Name,
Mirror: true,
CloneAddr: elem.CloneURL}
jsondata, err := json.Marshal(repo)
req, err := http.NewRequest("POST", config.GiteaMigrateURL, bytes.NewBufferString(string(jsondata)))
if err != nil { if err != nil {
return err
}
req.Header.Add("Content-Type", "application/json")
req.Header.Set("Authorization", config.GiteaAuthToken)
client.Timeout = config.G2gRequestTimeout
fmt.Println(fmt.Sprintf("Migrating repo %s to gitea rest api", elem.Name))
resp, err := client.Do(req)
if err != nil {
return err
}
if resp.StatusCode != 201 {
err = fmt.Errorf("Error when migrating repo %s to gitea with status code %d on gitea webservice", elem.Name, resp.StatusCode)
log.Println(err) log.Println(err)
continue
} }
} else { } else {
fmt.Println(fmt.Sprintf("Not migrating, %s exists in gitea", elem.Name)) fmt.Printf("Not migrating, %s exists in gitea\n", elem.Name)
} }
} else { } else {
fmt.Println(fmt.Sprintf("All repo migrated on thread num %d", thr)) fmt.Printf("All repo migrated on thread num %d\n", thr)
wg.Done() wg.Done()
done <- true done <- true
return nil return nil
@ -205,6 +186,40 @@ func MigrateReposToGitea(config *config.Config, wg *sync.WaitGroup, jobs chan Gi
} }
} }
func MigrateRepo(elem GitHubRepo, config *config.Config) (err error) {
client := &http.Client{}
repo := GiteaRepo{
UID: config.GiteaUID,
RepoName: elem.Name,
Mirror: true,
CloneAddr: elem.CloneURL}
jsondata, err := json.Marshal(repo)
if err != nil {
return err
}
req, err := http.NewRequest("POST", config.GiteaMigrateURL, bytes.NewBufferString(string(jsondata)))
if err != nil {
return err
}
req.Header.Add("Content-Type", "application/json")
req.Header.Set("Authorization", config.GiteaAuthToken)
client.Timeout = config.G2gRequestTimeout
fmt.Printf("Migrating repo %s to gitea rest api\n", elem.Name)
resp, err := client.Do(req)
if err != nil {
return err
}
if resp.StatusCode != 201 {
err = fmt.Errorf("error when migrating repo %s to gitea with status code %d on gitea webservice", elem.Name, resp.StatusCode)
log.Println(err)
}
return err
}
// GitHubRepo githubrepo struct // GitHubRepo githubrepo struct
type GitHubRepo struct { type GitHubRepo struct {
Name string `json:"name"` Name string `json:"name"`

21
vendor/gopkg.in/ini.v1/.golangci.yml generated vendored Normal file
View File

@ -0,0 +1,21 @@
linters-settings:
nakedret:
max-func-lines: 0 # Disallow any unnamed return statement
linters:
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- nakedret
- gofmt
- rowserrcheck
- unconvert
- goimports

2
vendor/gopkg.in/ini.v1/codecov.yml generated vendored
View File

@ -6,4 +6,4 @@ coverage:
threshold: 1% threshold: 1%
comment: comment:
layout: 'diff, files' layout: 'diff'

4
vendor/gopkg.in/ini.v1/ini.go generated vendored
View File

@ -1,5 +1,3 @@
// +build go1.6
// Copyright 2014 Unknwon // Copyright 2014 Unknwon
// //
// Licensed under the Apache License, Version 2.0 (the "License"): you may // Licensed under the Apache License, Version 2.0 (the "License"): you may
@ -125,6 +123,8 @@ type LoadOptions struct {
ReaderBufferSize int ReaderBufferSize int
// AllowNonUniqueSections indicates whether to allow sections with the same name multiple times. // AllowNonUniqueSections indicates whether to allow sections with the same name multiple times.
AllowNonUniqueSections bool AllowNonUniqueSections bool
// AllowDuplicateShadowValues indicates whether values for shadowed keys should be deduplicated.
AllowDuplicateShadowValues bool
} }
// DebugFunc is the type of function called to log parse events. // DebugFunc is the type of function called to log parse events.

17
vendor/gopkg.in/ini.v1/key.go generated vendored
View File

@ -54,14 +54,16 @@ func (k *Key) addShadow(val string) error {
return errors.New("cannot add shadow to auto-increment or boolean key") return errors.New("cannot add shadow to auto-increment or boolean key")
} }
// Deduplicate shadows based on their values. if !k.s.f.options.AllowDuplicateShadowValues {
if k.value == val { // Deduplicate shadows based on their values.
return nil if k.value == val {
}
for i := range k.shadows {
if k.shadows[i].value == val {
return nil return nil
} }
for i := range k.shadows {
if k.shadows[i].value == val {
return nil
}
}
} }
shadow := newKey(k.s, k.name, val) shadow := newKey(k.s, k.name, val)
@ -781,10 +783,8 @@ func (k *Key) parseUint64s(strs []string, addInvalid, returnOnInvalid bool) ([]u
return vals, err return vals, err
} }
type Parser func(str string) (interface{}, error) type Parser func(str string) (interface{}, error)
// parseTimesFormat transforms strings to times in given format. // parseTimesFormat transforms strings to times in given format.
func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) {
vals := make([]time.Time, 0, len(strs)) vals := make([]time.Time, 0, len(strs))
@ -801,7 +801,6 @@ func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnO
return vals, err return vals, err
} }
// doParse transforms strings to different types // doParse transforms strings to different types
func (k *Key) doParse(strs []string, addInvalid, returnOnInvalid bool, parser Parser) ([]interface{}, error) { func (k *Key) doParse(strs []string, addInvalid, returnOnInvalid bool, parser Parser) ([]interface{}, error) {
vals := make([]interface{}, 0, len(strs)) vals := make([]interface{}, 0, len(strs))

12
vendor/gopkg.in/ini.v1/parser.go generated vendored
View File

@ -131,7 +131,7 @@ func readKeyName(delimiters string, in []byte) (string, int, error) {
// Check if key name surrounded by quotes. // Check if key name surrounded by quotes.
var keyQuote string var keyQuote string
if line[0] == '"' { if line[0] == '"' {
if len(line) > 6 && string(line[0:3]) == `"""` { if len(line) > 6 && line[0:3] == `"""` {
keyQuote = `"""` keyQuote = `"""`
} else { } else {
keyQuote = `"` keyQuote = `"`
@ -232,7 +232,7 @@ func (p *parser) readValue(in []byte, bufferSize int) (string, error) {
} }
var valQuote string var valQuote string
if len(line) > 3 && string(line[0:3]) == `"""` { if len(line) > 3 && line[0:3] == `"""` {
valQuote = `"""` valQuote = `"""`
} else if line[0] == '`' { } else if line[0] == '`' {
valQuote = "`" valQuote = "`"
@ -289,12 +289,8 @@ func (p *parser) readValue(in []byte, bufferSize int) (string, error) {
hasSurroundedQuote(line, '"')) && !p.options.PreserveSurroundedQuote { hasSurroundedQuote(line, '"')) && !p.options.PreserveSurroundedQuote {
line = line[1 : len(line)-1] line = line[1 : len(line)-1]
} else if len(valQuote) == 0 && p.options.UnescapeValueCommentSymbols { } else if len(valQuote) == 0 && p.options.UnescapeValueCommentSymbols {
if strings.Contains(line, `\;`) { line = strings.ReplaceAll(line, `\;`, ";")
line = strings.Replace(line, `\;`, ";", -1) line = strings.ReplaceAll(line, `\#`, "#")
}
if strings.Contains(line, `\#`) {
line = strings.Replace(line, `\#`, "#", -1)
}
} else if p.options.AllowPythonMultilineValues && lastChar == '\n' { } else if p.options.AllowPythonMultilineValues && lastChar == '\n' {
return p.readPythonMultilines(line, bufferSize) return p.readPythonMultilines(line, bufferSize)
} }

2
vendor/gopkg.in/ini.v1/section.go generated vendored
View File

@ -217,7 +217,7 @@ func (s *Section) KeysHash() map[string]string {
defer s.f.lock.RUnlock() defer s.f.lock.RUnlock()
} }
hash := map[string]string{} hash := make(map[string]string, len(s.keysHash))
for key, value := range s.keysHash { for key, value := range s.keysHash {
hash[key] = value hash[key] = value
} }

10
vendor/modules.txt vendored
View File

@ -1,9 +1,5 @@
# github.com/gopherjs/gopherjs v0.0.0-20210406100015-1e088ea4ee04 # github.com/stretchr/testify v1.7.0
## explicit ## explicit; go 1.13
# github.com/smartystreets/assertions v1.2.0 # gopkg.in/ini.v1 v1.63.2
## explicit
# github.com/smartystreets/goconvey v1.6.4
## explicit
# gopkg.in/ini.v1 v1.62.0
## explicit ## explicit
gopkg.in/ini.v1 gopkg.in/ini.v1