From bb0e0650d5113eb8cacd11d58956b3452d3c2d3d Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Tue, 21 May 2024 15:04:16 +0800 Subject: [PATCH] feat(tibuild): fill result col for devbuild list api (#139) Close #140 Also support filter by creator (`createdBy`). Signed-off-by: wuhuizuo --------- Signed-off-by: wuhuizuo --- cloudevents-server/go.mod | 5 +- cloudevents-server/go.sum | 4 +- tibuild/Makefile | 4 +- tibuild/docs/docs.go | 11 +- tibuild/docs/swagger.json | 6 + tibuild/docs/swagger.yaml | 4 + .../controller/artifact_helper_handler.go | 20 ++-- .../pkg/rest/controller/dev_build_handler.go | 112 +++++++++--------- tibuild/pkg/rest/controller/hotfix_handler.go | 40 +++---- tibuild/pkg/rest/repo/dev_build_repo.go | 21 +++- tibuild/pkg/rest/repo/dev_build_repo_test.go | 19 +-- .../rest/service/cloud_event_client_test.go | 2 +- .../rest/service/dev_build_service_test.go | 2 +- tibuild/pkg/rest/service/model.go | 7 +- 14 files changed, 148 insertions(+), 109 deletions(-) diff --git a/cloudevents-server/go.mod b/cloudevents-server/go.mod index db1d821e..967db894 100644 --- a/cloudevents-server/go.mod +++ b/cloudevents-server/go.mod @@ -16,12 +16,11 @@ require ( k8s.io/apimachinery v0.23.9 ) -require filippo.io/edwards25519 v1.1.0 // indirect - require ( ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect + filippo.io/edwards25519 v1.1.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.0 // indirect github.com/Masterminds/sprig/v3 v3.2.3 @@ -97,7 +96,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect - go.uber.org/zap v1.22.0 // indirect + go.uber.org/zap v1.24.0 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/mod v0.15.0 // indirect diff --git a/cloudevents-server/go.sum b/cloudevents-server/go.sum index 9552aeca..4fbb84fb 100644 --- a/cloudevents-server/go.sum +++ b/cloudevents-server/go.sum @@ -491,8 +491,8 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.22.0 h1:Zcye5DUgBloQ9BaT4qc9BnjOFog5TvBSAGkJ3Nf70c0= -go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U= +go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= +go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= diff --git a/tibuild/Makefile b/tibuild/Makefile index cb47acac..333beea2 100644 --- a/tibuild/Makefile +++ b/tibuild/Makefile @@ -33,7 +33,9 @@ build.web: yarn build swagger: - swag init -d cmd/tibuild,pkg/rest + if [ ! -f $$(go env GOPATH)/bin/swag ]; then go install github.com/swaggo/swag/cmd/swag@v1.16.3; fi + $$(go env GOPATH)/bin/swag fmt -d ./cmd/tibuild,./pkg/rest + $$(go env GOPATH)/bin/swag init -d ./cmd/tibuild,./pkg/rest test: go test ./... diff --git a/tibuild/docs/docs.go b/tibuild/docs/docs.go index 6e25c354..be357779 100644 --- a/tibuild/docs/docs.go +++ b/tibuild/docs/docs.go @@ -1,5 +1,4 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Package docs Code generated by swaggo/swag. DO NOT EDIT package docs import "github.com/swaggo/swag" @@ -92,6 +91,12 @@ const docTemplate = `{ "description": "filter hotfix", "name": "hotfix", "in": "query" + }, + { + "type": "string", + "description": "filter created by", + "name": "createdBy", + "in": "query" } ], "responses": { @@ -740,6 +745,8 @@ var SwaggerInfo = &swag.Spec{ Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/tibuild/docs/swagger.json b/tibuild/docs/swagger.json index 62c6712f..3636e614 100644 --- a/tibuild/docs/swagger.json +++ b/tibuild/docs/swagger.json @@ -80,6 +80,12 @@ "description": "filter hotfix", "name": "hotfix", "in": "query" + }, + { + "type": "string", + "description": "filter created by", + "name": "createdBy", + "in": "query" } ], "responses": { diff --git a/tibuild/docs/swagger.yaml b/tibuild/docs/swagger.yaml index d667b9a8..9769b458 100644 --- a/tibuild/docs/swagger.yaml +++ b/tibuild/docs/swagger.yaml @@ -331,6 +331,10 @@ paths: in: query name: hotfix type: boolean + - description: filter created by + in: query + name: createdBy + type: string produces: - application/json responses: diff --git a/tibuild/pkg/rest/controller/artifact_helper_handler.go b/tibuild/pkg/rest/controller/artifact_helper_handler.go index 5244af51..df35f17f 100644 --- a/tibuild/pkg/rest/controller/artifact_helper_handler.go +++ b/tibuild/pkg/rest/controller/artifact_helper_handler.go @@ -17,16 +17,16 @@ func NewArtifactHelperHandler(j service.Jenkins) *ArtifactHelperHandler { } // SyncImage godoc -// @Summary sync hotfix image to dockerhub -// @Description sync -// @Tags artifact -// @Accept json -// @Produce json -// @Param ImageSyncRequest body service.ImageSyncRequest true "image sync to public, only hotfix is accepted right now" -// @Success 200 {object} service.ImageSyncRequest -// @Failure 400 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /api/artifact/sync-image [post] +// @Summary sync hotfix image to dockerhub +// @Description sync +// @Tags artifact +// @Accept json +// @Produce json +// @Param ImageSyncRequest body service.ImageSyncRequest true "image sync to public, only hotfix is accepted right now" +// @Success 200 {object} service.ImageSyncRequest +// @Failure 400 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /api/artifact/sync-image [post] func (h ArtifactHelperHandler) SyncImage(c *gin.Context) { params := service.ImageSyncRequest{} err := bindParam(¶ms, c) diff --git a/tibuild/pkg/rest/controller/dev_build_handler.go b/tibuild/pkg/rest/controller/dev_build_handler.go index fa667058..7c8b1d8c 100644 --- a/tibuild/pkg/rest/controller/dev_build_handler.go +++ b/tibuild/pkg/rest/controller/dev_build_handler.go @@ -65,17 +65,18 @@ func (h DevBuildHandler) authenticate(c *gin.Context) (context.Context, error) { } // CreateDevbuild godoc -// @Summary create and trigger devbuild -// @Description create and trigger devbuild -// @Tags devbuild -// @Accept json -// @Produce json -// @Param DevBuild body service.DevBuild true "build to create, only spec filed is required, others are ignored" -// @Param dryrun query bool false "dry run" default(false) -// @Success 200 {object} service.DevBuild -// @Failure 400 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /api/devbuilds [post] +// +// @Summary create and trigger devbuild +// @Description create and trigger devbuild +// @Tags devbuild +// @Accept json +// @Produce json +// @Param DevBuild body service.DevBuild true "build to create, only spec filed is required, others are ignored" +// @Param dryrun query bool false "dry run" default(false) +// @Success 200 {object} service.DevBuild +// @Failure 400 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /api/devbuilds [post] func (h DevBuildHandler) Create(c *gin.Context) { ctx, err := h.authenticate(c) if err != nil { @@ -102,16 +103,18 @@ func (h DevBuildHandler) Create(c *gin.Context) { } // ListDevbuild godoc -// @Summary list devbuild -// @Description list devbuild -// @Tags devbuild -// @Produce json -// @Param size query int false "the size limit of items" default(10) -// @Param offset query int false "the start position of items" default(0) -// @Param hotfix query bool false "filter hotfix" default(null) -// @Success 200 {array} service.DevBuild -// @Failure 400 {object} HTTPError -// @Router /api/devbuilds [get] +// +// @Summary list devbuild +// @Description list devbuild +// @Tags devbuild +// @Produce json +// @Param size query int false "the size limit of items" default(10) +// @Param offset query int false "the start position of items" default(0) +// @Param hotfix query bool false "filter hotfix" default(null) +// @Param createdBy query string false "filter created by" +// @Success 200 {array} service.DevBuild +// @Failure 400 {object} HTTPError +// @Router /api/devbuilds [get] func (h DevBuildHandler) List(c *gin.Context) { params := service.DevBuildListOption{} err := c.ShouldBindQuery(¶ms) @@ -131,16 +134,17 @@ func (h DevBuildHandler) List(c *gin.Context) { } // GetDevbuild godoc -// @Summary get devbuild -// @Description get devbuild -// @Tags devbuild -// @Produce json -// @Param id path int true "id of build" -// @Param sync query bool false "whether sync with jenkins" default(false) -// @Success 200 {object} service.DevBuild -// @Failure 400 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /api/devbuilds/{id} [get] +// +// @Summary get devbuild +// @Description get devbuild +// @Tags devbuild +// @Produce json +// @Param id path int true "id of build" +// @Param sync query bool false "whether sync with jenkins" default(false) +// @Success 200 {object} service.DevBuild +// @Failure 400 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /api/devbuilds/{id} [get] func (h DevBuildHandler) Get(c *gin.Context) { idStr := c.Param("id") id, err := strconv.Atoi(idStr) @@ -163,16 +167,17 @@ func (h DevBuildHandler) Get(c *gin.Context) { } // GetDevbuild godoc -// @Summary rerun devbuild -// @Description rerun devbuild -// @Tags devbuild -// @Produce json -// @Param id path int true "id of build" -// @Param dryrun query bool false "dry run" default(false) -// @Success 200 {object} service.DevBuild -// @Failure 400 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /api/devbuilds/{id}/rerun [post] +// +// @Summary rerun devbuild +// @Description rerun devbuild +// @Tags devbuild +// @Produce json +// @Param id path int true "id of build" +// @Param dryrun query bool false "dry run" default(false) +// @Success 200 {object} service.DevBuild +// @Failure 400 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /api/devbuilds/{id}/rerun [post] func (h DevBuildHandler) Rerun(c *gin.Context) { ctx, err := h.authenticate(c) if err != nil { @@ -200,18 +205,19 @@ func (h DevBuildHandler) Rerun(c *gin.Context) { } // UpdateDevbuild godoc -// @Summary update devbuild status -// @Description update the status field of a build -// @Tags devbuild -// @Accept json -// @Produce json -// @Param id path int true "id of build" -// @Param DevBuild body service.DevBuild true "build to update" -// @Param dryrun query bool false "dry run" default(false) -// @Success 200 {object} service.DevBuild -// @Failure 400 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /api/devbuilds/{id} [put] +// +// @Summary update devbuild status +// @Description update the status field of a build +// @Tags devbuild +// @Accept json +// @Produce json +// @Param id path int true "id of build" +// @Param DevBuild body service.DevBuild true "build to update" +// @Param dryrun query bool false "dry run" default(false) +// @Success 200 {object} service.DevBuild +// @Failure 400 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /api/devbuilds/{id} [put] func (h DevBuildHandler) Update(c *gin.Context) { idStr := c.Param("id") id, err := strconv.Atoi(idStr) diff --git a/tibuild/pkg/rest/controller/hotfix_handler.go b/tibuild/pkg/rest/controller/hotfix_handler.go index 90574d5b..c62e7489 100644 --- a/tibuild/pkg/rest/controller/hotfix_handler.go +++ b/tibuild/pkg/rest/controller/hotfix_handler.go @@ -14,16 +14,16 @@ type HotfixHandler struct { } // // CreateHotfixBranch godoc -// @Summary create hotfix branch -// @Description create hotfix branch -// @Tags hotfix -// @Accept json -// @Produce json -// @Param BranchCreateReq body service.BranchCreateReq true "hotfix param" -// @Success 200 {object} service.BranchCreateResp -// @Failure 422 {object} HTTPError -// @Failure 400 {object} HTTPError -// @Failure 500 {object} HTTPError +// @Summary create hotfix branch +// @Description create hotfix branch +// @Tags hotfix +// @Accept json +// @Produce json +// @Param BranchCreateReq body service.BranchCreateReq true "hotfix param" +// @Success 200 {object} service.BranchCreateResp +// @Failure 422 {object} HTTPError +// @Failure 400 {object} HTTPError +// @Failure 500 {object} HTTPError // // @Router /api/hotfix/create-branch [post] func (h HotfixHandler) CreateBranch(c *gin.Context) { params := service.BranchCreateReq{} @@ -40,16 +40,16 @@ func (h HotfixHandler) CreateBranch(c *gin.Context) { } // // CreateHotfixTag godoc -// @Summary create hotfix tag -// @Description create hotfix tag -// @Tags hotfix -// @Accept json -// @Produce json -// @Param TagCreateReq body service.TagCreateReq true "hotfix param" -// @Success 200 {object} service.TagCreateResp -// @Failure 422 {object} HTTPError -// @Failure 400 {object} HTTPError -// @Failure 500 {object} HTTPError +// @Summary create hotfix tag +// @Description create hotfix tag +// @Tags hotfix +// @Accept json +// @Produce json +// @Param TagCreateReq body service.TagCreateReq true "hotfix param" +// @Success 200 {object} service.TagCreateResp +// @Failure 422 {object} HTTPError +// @Failure 400 {object} HTTPError +// @Failure 500 {object} HTTPError // // @Router /api/hotfix/create-tag [post] func (h HotfixHandler) CreateTag(c *gin.Context) { params := service.TagCreateReq{} diff --git a/tibuild/pkg/rest/repo/dev_build_repo.go b/tibuild/pkg/rest/repo/dev_build_repo.go index 66844e77..154efac7 100644 --- a/tibuild/pkg/rest/repo/dev_build_repo.go +++ b/tibuild/pkg/rest/repo/dev_build_repo.go @@ -52,16 +52,27 @@ func (m DevBuildRepo) Update(ctx context.Context, id int, req DevBuild) (resp *D return &req, nil } -func (m DevBuildRepo) List(ctx context.Context, option DevBuildListOption) (resp []DevBuild, err error) { - result := []DevBuild{} - db := m.Db.Order("created_at DESC") +func (m DevBuildRepo) List(ctx context.Context, option DevBuildListOption) ([]DevBuild, error) { + db := m.Db.Order("created_at DESC").Offset(int(option.Offset)).Limit(int(option.Size)) if option.Hotfix != nil { db = db.Where(&DevBuild{Spec: DevBuildSpec{IsHotfix: *option.Hotfix}}, "IsHotfix") } - if err := db.Offset(int(option.Offset)).Limit(int(option.Size)).Find(&result).Error; err != nil { + if option.CreatedBy != nil && *option.CreatedBy != "" { + db = db.Where(&DevBuild{Meta: DevBuildMeta{CreatedBy: *option.CreatedBy}}, "CreatedBy") + } + + result := []DevBuild{} + if err := db.Find(&result).Error; err != nil { return nil, fmt.Errorf("%s%w", err.Error(), ErrInternalError) } - return result, err + + for i := range result { + if err := outofDB(&result[i]); err != nil { + return nil, err + } + } + + return result, nil } func intoDB(entity *DevBuild) (err error) { diff --git a/tibuild/pkg/rest/repo/dev_build_repo_test.go b/tibuild/pkg/rest/repo/dev_build_repo_test.go index d03d740e..4d5a5e4d 100644 --- a/tibuild/pkg/rest/repo/dev_build_repo_test.go +++ b/tibuild/pkg/rest/repo/dev_build_repo_test.go @@ -23,8 +23,10 @@ func TestDevBuildCreate(t *testing.T) { repo := DevBuildRepo{Db: odb} mock.ExpectBegin() now := time.Unix(1, 0) - mock.ExpectExec("INSERT INTO `dev_builds`").WithArgs(now, "", now, ProductBr, "", "v6.7.0", CommunityEdition, "", - "AA=BB", "https://raw.example.com/Dockerfile", "", "pingcap/builder", "", false, "", false, "" /* target_img */, JenkinsEngine, "" /* githash */, "PENDING", 0, "", nil, nil, json.RawMessage("null"), json.RawMessage("null")).WillReturnResult(sqlmock.NewResult(1, 1)) + mock.ExpectExec("INSERT INTO `dev_builds`").WithArgs(now, "", now, ProductBr, "", "", "v6.7.0", CommunityEdition, "", + "AA=BB", "https://raw.example.com/Dockerfile", "", "pingcap/builder", "", false, "", false, "", /* target_img */ + JenkinsEngine, "PENDING", 0, "", nil, nil, + json.RawMessage("null"), json.RawMessage("null")).WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectCommit() entity, err := repo.Create(context.TODO(), DevBuild{ @@ -46,7 +48,8 @@ func TestDevBuildList(t *testing.T) { require.NoError(t, err) repo := DevBuildRepo{Db: odb} rows := sqlmock.NewRows([]string{"id"}).AddRow(1).AddRow(2) - mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`is_hotfix` = \\? ORDER BY created_at DESC LIMIT 10 OFFSET 5").WithArgs(false).WillReturnRows(rows) + mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`is_hotfix` = \\? ORDER BY created_at DESC LIMIT \\? OFFSET \\?"). + WithArgs(false, 10, 5).WillReturnRows(rows) entities, err := repo.List(context.TODO(), DevBuildListOption{Offset: 5, Size: 10, Hotfix: &[]bool{false}[0]}) require.NoError(t, err) require.Equal(t, 2, len(entities)) @@ -66,7 +69,7 @@ func TestDevBuildUpdate(t *testing.T) { tekton_text, err := json.Marshal(tekton_status) require.NoError(t, err) mock.ExpectBegin() - mock.ExpectExec("UPDATE `dev_builds` SET").WithArgs(now, "", sqlmock.AnyArg(), ProductBr, "", "", "", "", "", "", "", "", "", false, "", false, "", "", "" /* GitHash */, "SUCCESS", 0, "", nil, nil, report_text, tekton_text, 1).WillReturnResult(sqlmock.NewResult(1, 1)) + mock.ExpectExec("UPDATE `dev_builds` SET").WithArgs(now, "", sqlmock.AnyArg(), ProductBr, "", "", "", "", "", "", "", "", "", "", false, "", false, "", "", "SUCCESS", 0, "", nil, nil, report_text, tekton_text, 1).WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectCommit() entity, err := repo.Update(context.TODO(), 1, @@ -88,7 +91,7 @@ func TestDevBuildGet(t *testing.T) { repo := DevBuildRepo{Db: odb} t.Run("proccessing", func(t *testing.T) { rows := sqlmock.NewRows([]string{"id", "status"}).AddRow(1, BuildStatusProcessing) - mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT 1").WillReturnRows(rows) + mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT \\?").WillReturnRows(rows) entity, err := repo.Get(context.TODO(), 1) require.NoError(t, err) require.Nil(t, entity.Status.BuildReport) @@ -99,7 +102,7 @@ func TestDevBuildGet(t *testing.T) { report_text, err := json.Marshal(report) require.NoError(t, err) rows := sqlmock.NewRows([]string{"id", "status", "build_report"}).AddRow(1, BuildStatusSuccess, report_text) - mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT 1").WillReturnRows(rows) + mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT \\?").WillReturnRows(rows) entity, err := repo.Get(context.TODO(), 1) require.NoError(t, err) require.Equal(t, report, *entity.Status.BuildReport) @@ -110,14 +113,14 @@ func TestDevBuildGet(t *testing.T) { tekton_text, err := json.Marshal(tekton) require.NoError(t, err) rows := sqlmock.NewRows([]string{"id", "status", "tekton_status"}).AddRow(1, BuildStatusSuccess, tekton_text) - mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT 1").WillReturnRows(rows) + mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT \\?").WillReturnRows(rows) entity, err := repo.Get(context.TODO(), 1) require.NoError(t, err) require.Equal(t, tekton, *entity.Status.TektonStatus) require.Empty(t, entity.Status.TektonStatusJson) }) t.Run("not found", func(t *testing.T) { - mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT 1").WillReturnError(gorm.ErrRecordNotFound) + mock.ExpectQuery("SELECT \\* FROM `dev_builds` WHERE `dev_builds`.`id` = \\? LIMIT \\?").WillReturnError(gorm.ErrRecordNotFound) entity, err := repo.Get(context.TODO(), 1) require.Nil(t, entity) require.ErrorIs(t, err, ErrNotFound) diff --git a/tibuild/pkg/rest/service/cloud_event_client_test.go b/tibuild/pkg/rest/service/cloud_event_client_test.go index 3cb7f3f3..53428e9d 100644 --- a/tibuild/pkg/rest/service/cloud_event_client_test.go +++ b/tibuild/pkg/rest/service/cloud_event_client_test.go @@ -32,7 +32,7 @@ func TestNewEvent(t *testing.T) { require.NoError(t, err) js, err := json.Marshal(ev) require.NoError(t, err) - expected := `{"specversion":"1.0","id":"","source":"tibuild.pingcap.net/api/devbuilds/1","type":"net.pingcap.tibuild.devbuild.push","subject":"1","datacontenttype":"application/json","data":{"ref":"refs/heads/master","after":"754095a9f460dcf31f053045cfedfb00b9ad8e81", "before":"00000000000000000000000000000000000000000","repository":{"name":"pd","owner":{"login":"tikv"},"clone_url":"https://github.com/tikv/pd"}},"user":"some@pingcap.com"}` + expected := `{"specversion":"1.0","id":"","source":"tibuild.pingcap.net/api/devbuilds/1","type":"net.pingcap.tibuild.devbuild.push","subject":"1","datacontenttype":"application/json","data":{"ref":"refs/heads/master","after":"754095a9f460dcf31f053045cfedfb00b9ad8e81", "before":"00000000000000000000000000000000000000000","repository":{"full_name":"tikv/pd", "name":"pd","owner":{"login":"tikv"},"clone_url":"https://github.com/tikv/pd.git"}},"user":"some@pingcap.com"}` require.JSONEq(t, expected, string(js)) } diff --git a/tibuild/pkg/rest/service/dev_build_service_test.go b/tibuild/pkg/rest/service/dev_build_service_test.go index 357ce276..dd56a0cf 100644 --- a/tibuild/pkg/rest/service/dev_build_service_test.go +++ b/tibuild/pkg/rest/service/dev_build_service_test.go @@ -299,7 +299,7 @@ func TestDevBuildGet(t *testing.T) { Status: DevBuildStatus{PipelineBuildID: 4, TektonStatus: &TektonStatus{Pipelines: []TektonPipeline{{Name: "p1"}}}}} entity, err := server.Get(context.TODO(), 1, DevBuildGetOption{}) require.NoError(t, err) - require.Equal(t, "http://tekton.net/p1", entity.Status.TektonStatus.Pipelines[0].URL) + require.Equal(t, "", entity.Status.TektonStatus.Pipelines[0].URL) }) t.Run("sync", func(t *testing.T) { mockedRepo.saved = DevBuild{ID: 1, diff --git a/tibuild/pkg/rest/service/model.go b/tibuild/pkg/rest/service/model.go index e1a88dbd..3ba0588b 100644 --- a/tibuild/pkg/rest/service/model.go +++ b/tibuild/pkg/rest/service/model.go @@ -149,9 +149,10 @@ type DevBuildMeta struct { } type DevBuildListOption struct { - Offset uint `form:"offset"` - Size uint `form:"size"` - Hotfix *bool `form:"hotfix"` + Offset uint `form:"offset"` + Size uint `form:"size"` + Hotfix *bool `form:"hotfix"` + CreatedBy *string `form:"createdBy"` } type DevBuildGetOption struct {