diff --git a/cmd/command/main.go b/cmd/command/main.go index 645bd607..da799530 100644 --- a/cmd/command/main.go +++ b/cmd/command/main.go @@ -168,7 +168,7 @@ func checkout() { func ci() { files := fileUtils.GetFilesFromParams(os.Args[2:]) if err := flagSet.Parse(os.Args[len(files)+2:]); err == nil { - action.CheckIn(files, noNeedConfirm, withCode) + action.CheckIn(productId, files, noNeedConfirm, withCode) } } diff --git a/internal/command/action/case.go b/internal/command/action/case.go index 1d5c005e..38b4b854 100644 --- a/internal/command/action/case.go +++ b/internal/command/action/case.go @@ -11,12 +11,12 @@ import ( stringUtils "github.com/easysoft/zentaoatf/pkg/lib/string" ) -func CheckIn(files []string, noNeedConfirm, withCode bool) { +func CheckIn(productId string, files []string, noNeedConfirm, withCode bool) { cases := scriptHelper.GetCaseByDirAndFile(files) config := configHelper.LoadByWorkspacePath(commConsts.ZtfDir) - zentaoHelper.CheckIn(cases, config, noNeedConfirm, withCode) + zentaoHelper.CheckIn(productId, cases, config, noNeedConfirm, withCode) } func Checkout(productId, moduleId, suiteId, taskId string, independentFile bool, scriptLang string) { diff --git a/internal/pkg/helper/zentao/bug.go b/internal/pkg/helper/zentao/bug.go index cda4c4d9..115aaa67 100644 --- a/internal/pkg/helper/zentao/bug.go +++ b/internal/pkg/helper/zentao/bug.go @@ -330,7 +330,7 @@ func generateCaseId(bugs []*commDomain.ZentaoBug, config commDomain.WorkspaceCon } } if bug.Case == 0 { - caseInfo, _ := CreateCase(bug.Product, bug.Title, nil, serverDomain.TestScript{}, config) + caseInfo, _ := CreateCase(fmt.Sprintf("%v", bug.Product), bug.Title, nil, serverDomain.TestScript{}, config) bug.Case = caseInfo.Id } } diff --git a/internal/pkg/helper/zentao/case.go b/internal/pkg/helper/zentao/case.go index 3b1f175b..deaa27bc 100644 --- a/internal/pkg/helper/zentao/case.go +++ b/internal/pkg/helper/zentao/case.go @@ -7,7 +7,6 @@ import ( "strconv" "strings" - "github.com/davecgh/go-spew/spew" serverConfig "github.com/easysoft/zentaoatf/internal/server/config" "github.com/fatih/color" @@ -28,7 +27,7 @@ import ( "github.com/kataras/iris/v12" ) -func CommitCase(caseId int, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript, +func CommitCase(productId string, caseId int, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript, config commDomain.WorkspaceConf, noNeedConfirm, withCode bool) (err error) { if serverConfig.CONFIG.AuthToken == "" { @@ -40,6 +39,15 @@ func CommitCase(caseId int, title string, steps []commDomain.ZentaoCaseStep, scr _, err = GetCaseById(config, caseId) if err != nil { + if !strings.Contains(err.Error(), "404") { + return + } + if len(productId) == 0 { + logUtils.Info("not found productId, like: pid=1") + return fmt.Errorf("not found productId, like: pid=1") + } + // 创建cases + _, err = CreateCase(productId, title, steps, script, config) return } @@ -87,7 +95,7 @@ func CommitCase(caseId int, title string, steps []commDomain.ZentaoCaseStep, scr return } -func CreateCase(productId int, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript, +func CreateCase(productId, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript, config commDomain.WorkspaceConf) (cs commDomain.ZtfCase, err error) { err = Login(config) @@ -95,7 +103,7 @@ func CreateCase(productId int, title string, steps []commDomain.ZentaoCaseStep, return } - uri := fmt.Sprintf("/products/%d/testcases", productId) + uri := fmt.Sprintf("/products/%v/testcases", productId) url := GenApiUrl(uri, nil, config.Url) requestObj := map[string]interface{}{ @@ -616,13 +624,11 @@ func ListCaseByModule(baseUrl string, productId, moduleId int) (casesResp commDo "module": moduleId, "limit": 10000, }, baseUrl) - spew.Dump(url) bytes, err := httpUtils.Get(url) if err != nil { err = ZentaoRequestErr(err.Error()) return } - spew.Dump(string(bytes)) casesResp, err = parseCases(bytes) if err != nil { err = ZentaoRequestErr(url, commConsts.ResponseParseErr.Message) diff --git a/internal/pkg/helper/zentao/sync.go b/internal/pkg/helper/zentao/sync.go index d8bea061..7b1bfcd7 100644 --- a/internal/pkg/helper/zentao/sync.go +++ b/internal/pkg/helper/zentao/sync.go @@ -5,7 +5,6 @@ import ( "fmt" "path/filepath" - "github.com/davecgh/go-spew/spew" fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file" i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118" logUtils "github.com/easysoft/zentaoatf/pkg/lib/log" @@ -34,7 +33,6 @@ func Checkout(settings commDomain.SyncSettings, config commDomain.WorkspaceConf, if !ok { return } - spew.Dump(settings) cases := make([]commDomain.ZtfCase, 0) if caseId != 0 { cs, err := GetTestCaseDetail(caseId, config) @@ -72,16 +70,16 @@ func Checkout(settings commDomain.SyncSettings, config commDomain.WorkspaceConf, return } -func CheckIn(cases []string, config commDomain.WorkspaceConf, noNeedConfirm, withCode bool) (count int, err error) { +func CheckIn(productId string, cases []string, config commDomain.WorkspaceConf, noNeedConfirm, withCode bool) (count int, err error) { for _, cs := range cases { - pass, id, _, title, _ := scriptHelper.GetCaseInfo(cs) + pass, caseId, _, title, _ := scriptHelper.GetCaseInfo(cs) if !pass { continue } steps := scriptHelper.GetStepAndExpectMap(cs) script, _ := scriptHelper.GetScriptContent(cs, -1) - err = CommitCase(id, title, steps, script, config, noNeedConfirm, withCode) + err = CommitCase(productId, caseId, title, steps, script, config, noNeedConfirm, withCode) if err == nil { count++ diff --git a/internal/server/modules/v1/controller/test-script.go b/internal/server/modules/v1/controller/test-script.go index 29c9ca79..7d172343 100644 --- a/internal/server/modules/v1/controller/test-script.go +++ b/internal/server/modules/v1/controller/test-script.go @@ -2,9 +2,10 @@ package controller import ( "fmt" - serverConfig "github.com/easysoft/zentaoatf/internal/server/config" "strings" + serverConfig "github.com/easysoft/zentaoatf/internal/server/config" + commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts" commDomain "github.com/easysoft/zentaoatf/internal/pkg/domain" configHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/config" @@ -249,9 +250,9 @@ func (c *TestScriptCtrl) SyncFromZentao(ctx iris.Context) { func (c *TestScriptCtrl) SyncToZentao(ctx iris.Context) { currSiteId, _ := ctx.URLParamInt("currSiteId") - currProductId, _ := ctx.URLParamInt("currProductId") + currProductId := ctx.URLParam("currProductId") - if currProductId == 0 { + if len(currProductId) == 0 { ctx.JSON(c.ErrResp(commConsts.ParamErr, "")) return } @@ -271,7 +272,7 @@ func (c *TestScriptCtrl) SyncToZentao(ctx iris.Context) { for _, set := range sets { totalNum += len(set.Cases) - count, _ := zentaoHelper.CheckIn(set.Cases, config, true, true) + count, _ := zentaoHelper.CheckIn(currProductId, set.Cases, config, true, true) successNum += count } @@ -284,6 +285,7 @@ func (c *TestScriptCtrl) SyncToZentao(ctx iris.Context) { func (c *TestScriptCtrl) SyncDirToZentao(ctx iris.Context) { dir := ctx.URLParam("dir") + productId := ctx.URLParam("productId") cases := scriptHelper.GetCaseByDirAndFile([]string{dir}) @@ -291,7 +293,8 @@ func (c *TestScriptCtrl) SyncDirToZentao(ctx iris.Context) { Url: serverConfig.CONFIG.Server, } - zentaoHelper.CheckIn(cases, config, true, true) + // TODO 产品ID 新增 + zentaoHelper.CheckIn(productId, cases, config, true, true) return }