sync code with go-git complete 📢
This commit is contained in:
parent
48adfea8ff
commit
250c8a029d
2
go.mod
2
go.mod
|
@ -3,6 +3,8 @@ module up2GitX
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/go-git/go-git/v5 v5.1.0
|
||||
github.com/gookit/color v1.2.5
|
||||
github.com/gookit/gcli/v2 v2.2.1
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1
|
||||
)
|
||||
|
|
68
go.sum
68
go.sum
|
@ -1,6 +1,25 @@
|
|||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
|
||||
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
|
||||
github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
|
||||
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||
github.com/go-git/go-git v1.0.0 h1:YcN9iDGDoXuIw0vHls6rINwV416HYa0EB2X+RBsyYp4=
|
||||
github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
|
||||
github.com/go-git/go-git/v5 v5.1.0 h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk=
|
||||
github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gookit/color v1.1.7/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ=
|
||||
github.com/gookit/color v1.2.5 h1:s1gzb/fg3HhkSLKyWVUsZcVBUo+R1TwEYTmmxH8gGFg=
|
||||
|
@ -10,23 +29,72 @@ github.com/gookit/gcli/v2 v2.2.1 h1:7uzRBODHIOl0vbmG3sPmQ2dn4f+0mxFPaoj2Mb2IFts=
|
|||
github.com/gookit/gcli/v2 v2.2.1/go.mod h1:E0Xwlbtx42V2bpx/Z9v0t01yTbOxwTEcwVZAesbkC/Q=
|
||||
github.com/gookit/goutil v0.2.7 h1:9cI9yDIBKT+RJHq6o3kRa3snQfozUkJoOwVH1aHGJhA=
|
||||
github.com/gookit/goutil v0.2.7/go.mod h1:8emMcACka2rFot/L9ZO7r3zjWiitzIhB/CfWXUCW75w=
|
||||
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
||||
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
|
||||
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
|
||||
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
|
||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
|
||||
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
|
||||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/gookit/color"
|
||||
"github.com/gookit/gcli/v2/interact"
|
||||
"github.com/gookit/gcli/v2/progress"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
|
||||
)
|
||||
|
||||
type RepoResult struct {
|
||||
|
@ -24,6 +25,7 @@ const (
|
|||
SUCCESS int = 0
|
||||
EXIST int = 1
|
||||
ERROR int = 2
|
||||
SKIP string = "1"
|
||||
SPL string = "------------------------------"
|
||||
)
|
||||
|
||||
|
@ -55,7 +57,7 @@ func syncGitee(c *gcli.Command, args []string) error {
|
|||
}
|
||||
|
||||
// enter userinfo to get access token
|
||||
askResult, success := askForAccount()
|
||||
askResult, success, auth := askForAccount()
|
||||
if !success {
|
||||
color.Red.Println(askResult)
|
||||
return nil
|
||||
|
@ -95,7 +97,11 @@ func syncGitee(c *gcli.Command, args []string) error {
|
|||
repoRes := createProjects(repos, public, accessToken, selectedNp)
|
||||
|
||||
// show results
|
||||
showRepoRes(repoRes)
|
||||
valid := showRepoRes(repoRes)
|
||||
if !valid {
|
||||
color.Red.Println("No repositories are available to be uploaded!")
|
||||
return nil
|
||||
}
|
||||
|
||||
// ask for exist and error details
|
||||
asErr := share.AskError()
|
||||
|
@ -106,15 +112,26 @@ func syncGitee(c *gcli.Command, args []string) error {
|
|||
if asExi == "0" {
|
||||
return nil
|
||||
}
|
||||
fmt.Println(asExi)
|
||||
|
||||
// available check
|
||||
avaiRepo := availableRepo(repoRes, asExi)
|
||||
if len(avaiRepo) == 0 {
|
||||
color.Red.Println("No repositories are available to be uploaded!")
|
||||
return nil
|
||||
}
|
||||
|
||||
// sync code
|
||||
color.Green.Println("Syncing Projects to Gitee, Please Wait...")
|
||||
syncRes := multiSync(avaiRepo, auth, asExi)
|
||||
showSyncRes(syncRes)
|
||||
return nil
|
||||
}
|
||||
|
||||
func askForAccount() (string, bool) {
|
||||
func askForAccount() (string, bool, *http.BasicAuth) {
|
||||
email, _ := interact.ReadLine("Please enter your Gitee email: ")
|
||||
password := interact.ReadPassword("Please enter your Gitee password: ")
|
||||
if len(email) == 0 || len(password) == 0 {
|
||||
return "Email or Password must be provided!", false
|
||||
return "Email or Password must be provided!", false, nil
|
||||
} else {
|
||||
params := fmt.Sprintf(`{
|
||||
"grant_type": "password",
|
||||
|
@ -130,11 +147,12 @@ func askForAccount() (string, bool) {
|
|||
result, err := share.Post("https://gitee.com/oauth/token", paramsJson)
|
||||
|
||||
if err != nil {
|
||||
return err.Error(), false
|
||||
return err.Error(), false, nil
|
||||
}
|
||||
|
||||
filterVal, ok := filterResult(result, "access_token")
|
||||
return filterVal, ok
|
||||
auth := &http.BasicAuth{email, password}
|
||||
return filterVal, ok, auth
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,24 +273,50 @@ func filterProjectResult(result map[string]interface{}, key string) (string, int
|
|||
return "Unexpectedly exit", ERROR
|
||||
}
|
||||
|
||||
func showRepoRes(repoRes []RepoResult) {
|
||||
func showRepoRes(repoRes []RepoResult) bool {
|
||||
printRepo(repoRes, SUCCESS)
|
||||
printRepo(repoRes, EXIST)
|
||||
printRepo(repoRes, ERROR)
|
||||
errNum := printRepo(repoRes, ERROR)
|
||||
return errNum != len(repoRes)
|
||||
}
|
||||
|
||||
func printRepo(repoRes []RepoResult, status int) {
|
||||
func printRepo(repoRes []RepoResult, status int) int {
|
||||
var p, result string
|
||||
errorNum := 0
|
||||
repoStatus := repoStatus(status)
|
||||
for _, item := range repoRes {
|
||||
if item.status == status {
|
||||
if status == ERROR {
|
||||
result = item.error
|
||||
errorNum = errorNum + 1
|
||||
} else {
|
||||
result = item.uri
|
||||
}
|
||||
p = fmt.Sprintf("Dir: (%s)\n Status: %s\n Result: %s\n%s", item.local, repoStatus, result, SPL)
|
||||
p = fmt.Sprintf("Dir: (%s)\n Status: %s\n Result: %s", item.local, repoStatus, result)
|
||||
colorRepo(status, p)
|
||||
fmt.Println(SPL)
|
||||
}
|
||||
}
|
||||
return errorNum
|
||||
}
|
||||
|
||||
func showSyncRes(syncRes []RepoResult) {
|
||||
printSync(syncRes, SUCCESS)
|
||||
printSync(syncRes, ERROR)
|
||||
}
|
||||
|
||||
func printSync(syncRes []RepoResult, status int) {
|
||||
var p, result string
|
||||
for _, item := range syncRes {
|
||||
if item.status == status {
|
||||
if status == SUCCESS {
|
||||
result = "Sync to Gitee SUCCESS!"
|
||||
} else {
|
||||
result = item.error
|
||||
}
|
||||
p = fmt.Sprintf("Dir: (%s)\n Gitee: %s\n Result: %s", item.local, item.uri, result)
|
||||
colorRepo(EXIST, p)
|
||||
fmt.Println(SPL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -303,4 +347,33 @@ func colorRepo(status int, p string) {
|
|||
default:
|
||||
color.Red.Println(p)
|
||||
}
|
||||
}
|
||||
|
||||
func multiSync(avaiRepo []RepoResult, auth *http.BasicAuth, force string) []RepoResult {
|
||||
var syncRes []RepoResult
|
||||
step := progress.Bar(len(avaiRepo))
|
||||
step.Start()
|
||||
for _, item := range avaiRepo {
|
||||
err := share.SyncRepo(auth, item.local, item.uri, force)
|
||||
if err != nil {
|
||||
item.status = ERROR
|
||||
item.error = err.Error()
|
||||
} else {
|
||||
item.status = SUCCESS
|
||||
}
|
||||
syncRes = append(syncRes, item)
|
||||
step.Advance()
|
||||
}
|
||||
step.Finish()
|
||||
return syncRes
|
||||
}
|
||||
|
||||
func availableRepo(repoRes []RepoResult, force string) []RepoResult {
|
||||
var avaiRepo []RepoResult
|
||||
for _, item := range repoRes {
|
||||
if item.status == SUCCESS || (item.status == EXIST && force != SKIP) {
|
||||
avaiRepo = append(avaiRepo, item)
|
||||
}
|
||||
}
|
||||
return avaiRepo
|
||||
}
|
|
@ -4,15 +4,19 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
NetHttp "net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/gookit/gcli/v2/interact"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
|
||||
)
|
||||
|
||||
func InvalidAlert(platform string) {
|
||||
|
@ -129,7 +133,7 @@ func ExitMessage() {
|
|||
}
|
||||
|
||||
func Get(url string) (map[string]interface{}, error) {
|
||||
response, err := http.Get(url)
|
||||
response, err := NetHttp.Get(url)
|
||||
if err != nil {
|
||||
color.Red.Printf("Request failed, Error: %s \n", err.Error())
|
||||
return nil, err
|
||||
|
@ -149,7 +153,7 @@ func Post(uri string, params map[string]interface{}) (map[string]interface{}, er
|
|||
data.Add(k, v.(string))
|
||||
}
|
||||
|
||||
response, err := http.PostForm(uri, data)
|
||||
response, err := NetHttp.PostForm(uri, data)
|
||||
if err != nil {
|
||||
color.Red.Printf("Request failed, Error: %s \n", err.Error())
|
||||
return nil, err
|
||||
|
@ -169,7 +173,7 @@ func PostForm(uri string, params map[string]interface{}) (map[string]interface{}
|
|||
data += fmt.Sprintf("%s=%s&%s", k, v.(string), data)
|
||||
}
|
||||
|
||||
response, err := http.Post(uri, "application/x-www-form-urlencoded", strings.NewReader(data))
|
||||
response, err := NetHttp.Post(uri, "application/x-www-form-urlencoded", strings.NewReader(data))
|
||||
if err != nil {
|
||||
color.Red.Printf("Request failed, Error: %s \n", err.Error())
|
||||
return nil, err
|
||||
|
@ -212,12 +216,53 @@ func AskError() string {
|
|||
|
||||
func AskExist() string {
|
||||
howTo := []string{"Exit and fix them",
|
||||
"Overwrite the remote (same as git push --force, you need exactly know what you do before you select this item)",
|
||||
"Skip them"}
|
||||
"Skip them",
|
||||
"Overwrite the remote (same as git push --force, you need exactly know what you do before you select this item)"}
|
||||
ques := "The are some projects name already exists, what would you like to do?"
|
||||
return selectOne(howTo, ques)
|
||||
}
|
||||
|
||||
func selectOne(items []string, ques string) string {
|
||||
return interact.SelectOne(ques, items, "",)
|
||||
}
|
||||
|
||||
func SyncRepo(auth *http.BasicAuth ,local string, uri string, force string) error {
|
||||
var forceStr string
|
||||
remote := fmt.Sprintf("up2GitX-%d", time.Now().Unix())
|
||||
r, err := git.PlainOpen(local)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer deleteRemote(r, remote)
|
||||
_, err = r.CreateRemote(&config.RemoteConfig{
|
||||
Name: remote,
|
||||
URLs: []string{uri},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch force { // push force or not
|
||||
case "2":
|
||||
forceStr = "+"
|
||||
default:
|
||||
forceStr = ""
|
||||
}
|
||||
rHeadStrings := fmt.Sprintf("%srefs/%s/*:refs/%s/*", forceStr, "heads", "heads")
|
||||
rTagStrings := fmt.Sprintf("%srefs/%s/*:refs/%s/*", forceStr, "tags", "tags")
|
||||
rHeads := config.RefSpec(rHeadStrings)
|
||||
rTags := config.RefSpec(rTagStrings)
|
||||
|
||||
err = r.Push(&git.PushOptions{RemoteName: remote,
|
||||
RefSpecs: []config.RefSpec{rHeads, rTags},
|
||||
Auth: auth})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteRemote(r *git.Repository, upRe string) {
|
||||
r.DeleteRemote(upRe)
|
||||
}
|
Loading…
Reference in New Issue