Skip to content

Commit ce999c0

Browse files
authored
Merge pull request #4 from htdcx/dev/rollback
Add rollback
2 parents e285d71 + 6aff9a1 commit ce999c0

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ chmod +x code-push-go
3030

3131
#Update react native
3232
./code-push-go create_bundle -t <TargetVersion> -n <AppName> -d <DeploymentName> -p <(*Optional) React native project default:./> --description <(*Optional) Description default: ""/>
33+
34+
#More command
35+
./code-push-go
3336
```
3437

3538
## License

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ func main() {
2929
" login Authenticate in order to begin managing your apps\n" +
3030
" logout Log out of the current session\n" +
3131
" app View and manage your CodePush apps\n" +
32-
" create_bundle Create react native hotfix bundle"
32+
" create_bundle Create react native hotfix bundle\n" +
33+
" rollback Rollback last dundle"
34+
3335
var command string
3436
if len(args) <= 0 {
3537
fmt.Println(help)
@@ -46,6 +48,8 @@ func main() {
4648
opt.App{}.CreateBundle()
4749
case "app":
4850
opt.App{}.App(args)
51+
case "rollback":
52+
opt.App{}.Rollback()
4953
default:
5054
fmt.Println(help)
5155
return

opt/app.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os/exec"
1616
"strconv"
1717
"strings"
18+
"time"
1819

1920
"com.lc.go.codepush/client/constants"
2021
"com.lc.go.codepush/client/utils"
@@ -601,3 +602,76 @@ func (App) deleteDeployment() {
601602
fmt.Println("Delete deployment " + deploymentName + " success")
602603
}
603604
}
605+
606+
type rollbackReq struct {
607+
AppName *string `json:"appName" binding:"required"`
608+
Deployment *string `json:"deployment" binding:"required"`
609+
Version *string `json:"version" binding:"required"`
610+
}
611+
612+
type rollbackRep struct {
613+
Success *bool `json:"success"`
614+
Version *string `json:"version"`
615+
PackId *int `json:"packId"`
616+
Size *int64 `json:"size"`
617+
Hash *string `json:"hash"`
618+
CreateTime *int64 `json:"createTime"`
619+
}
620+
621+
func (App) Rollback() {
622+
saveLoginInfo, err := utils.GetLoginfo()
623+
if err != nil {
624+
log.Println(err.Error())
625+
return
626+
}
627+
628+
var targetVersion string
629+
var appName string
630+
var deployment string
631+
632+
flag.StringVar(&targetVersion, "t", "", "Target version")
633+
flag.StringVar(&appName, "n", "", "AppName")
634+
flag.StringVar(&deployment, "d", "", "DeploymentName")
635+
flag.Parse()
636+
637+
if appName == "" || deployment == "" || targetVersion == "" {
638+
fmt.Println("Usage: code-push-go rollback -n <AppName> -d <deployment> -t <TargetVersion>")
639+
return
640+
}
641+
642+
rollbackReq := rollbackReq{
643+
AppName: &appName,
644+
Deployment: &deployment,
645+
Version: &targetVersion,
646+
}
647+
648+
jsonByte, _ := json.Marshal(rollbackReq)
649+
Url, err := url.Parse(saveLoginInfo.ServerUrl + "/rollback")
650+
if err != nil {
651+
log.Panic("server url error :", err.Error())
652+
}
653+
reqStatus, err := utils.HttpPostToken[rollbackRep](Url.String(), jsonByte, &saveLoginInfo.Token)
654+
if err != nil {
655+
fmt.Println(err.Error())
656+
return
657+
}
658+
if *reqStatus.Success {
659+
fmt.Println("Rollback " + deployment + " success,currut version:")
660+
titles := []string{"DeploymentName", "AppVersion", "PackId", "Size", "Hash", "CreateTime"}
661+
table, err := gotable.Create(titles...)
662+
if err != nil {
663+
fmt.Println(err.Error())
664+
return
665+
}
666+
var columns []string
667+
if reqStatus.PackId == nil {
668+
columns = []string{deployment, *reqStatus.Version}
669+
} else {
670+
columns = []string{deployment, *reqStatus.Version, strconv.Itoa(*reqStatus.PackId), strconv.FormatInt(*reqStatus.Size, 10), *reqStatus.Hash, time.Unix(0, *reqStatus.CreateTime*1e6).String()}
671+
}
672+
673+
table.AddRow(columns)
674+
fmt.Println(table)
675+
676+
}
677+
}

0 commit comments

Comments
 (0)