From c72a106bab8a468a0246db00f631aa8a02110bcb Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 18 Jan 2021 10:48:35 +0800 Subject: [PATCH] Fix the pipeline list with incorrect paging calculating Signed-off-by: rick --- pkg/kapis/devops/v1alpha2/devops.go | 44 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/pkg/kapis/devops/v1alpha2/devops.go b/pkg/kapis/devops/v1alpha2/devops.go index fa8a8f510..96da69a7b 100644 --- a/pkg/kapis/devops/v1alpha2/devops.go +++ b/pkg/kapis/devops/v1alpha2/devops.go @@ -94,31 +94,33 @@ func (h *ProjectPipelineHandler) ListPipelines(req *restful.Request, resp *restf // get all pipelines which come from ks pipelineList := &clientDevOps.PipelineList{ Total: objs.TotalItems, - Items: make([]clientDevOps.Pipeline, objs.TotalItems), + Items: make([]clientDevOps.Pipeline, len(objs.Items)), } - pipelineMap := make(map[string]int, objs.TotalItems) - for i, item := range objs.Items { - if pipeline, ok := item.(v1alpha3.Pipeline); !ok { - continue - } else { - pip := clientDevOps.Pipeline{ - Name: pipeline.Name, + if pipelineList.Total > 0 && len(objs.Items) > 0 { + pipelineMap := make(map[string]int, pipelineList.Total) + for i, item := range objs.Items { + if pipeline, ok := item.(v1alpha3.Pipeline); !ok { + continue + } else { + pip := clientDevOps.Pipeline{ + Name: pipeline.Name, + } + + pipelineMap[pipeline.Name] = i + pipelineList.Items[i] = pip } - - pipelineMap[pipeline.Name] = i - pipelineList.Items[i] = pip } - } - // get all pipelines which come from Jenkins - // fill out the rest fields - res, err := h.devopsOperator.ListPipelines(req.Request) - if err != nil { - log.Error(err) - } else { - for _, item := range res.Items { - if index, ok := pipelineMap[item.Name]; ok { - pipelineList.Items[index] = item + // get all pipelines which come from Jenkins + // fill out the rest fields + res, err := h.devopsOperator.ListPipelines(req.Request) + if err != nil { + log.Error(err) + } else { + for _, item := range res.Items { + if index, ok := pipelineMap[item.Name]; ok { + pipelineList.Items[index] = item + } } } }