You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: pipeline_utils.go
    path of file: ./repos/erda/internal/tools/orchestrator/utils
    
    the code of the file until where you have to start completion: // Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import (
	"fmt"
	"strconv"
	"strings"

	"github.com/pkg/errors"

	pipelinepb "github.com/erda-project/erda-proto-go/core/pipeline/pipeline/pb"

	"github.com/erda-project/erda/apistructs"
	"github.com/erda-project/erda/bundle"
	"github.com/erda-project/erda/pkg/strutil"
)

// GenRedeployPipelineYaml gen pipeline.y
    
func FindCreatingRuntimesByRelease(appID uint64, envs map[string][]string, ymlName string, bdl *bundle.Bundle) ([]apistructs.RuntimeSummaryDTO, error) {
	var result []apistructs.RuntimeSummaryDTO
	pipelinePageReq := apistructs.PipelinePageListRequest{
		Sources:  []apistructs.PipelineSource{apistructs.PipelineSourceDice},
		Statuses: []string{"Running"},
	}
	if appID != 0 {
		pipelinePageReq.MustMatchLabelsQueryParams = []string{"appID=" + strconv.FormatUint(appID, 10)}
	}
	if ymlName != "" {
		pipelinePageReq.YmlNames = []string{ymlName}
	}

	resp, err := bdl.PageListPipeline(pipelinePageReq)
	if err != nil {
		return nil, err
	}

	for _, v := range resp.Pipelines {
		if !strings.Contains(v.YmlName, "dice-deploy-release") {
			// not the target pipeline
			continue
		}

		branchSlice := strings.SplitN(v.YmlName, "-", 4)
		if len(branchSlice) != 4 {
			return nil, errors.Errorf("Invalid yaml name %s", v.YmlName)
		}
		branch := branchSlice[3]
		runtimeBranchs, ok := envs[strings.ToLower(v.Extra.DiceWorkspace)]

		if !ok || strutil.Exist(runtimeBranchs, branch) {
			// first condition means user have permission
			// second condition means that the runtime data of db has higher priority
			// And one branch corresponds to only one rutime
			continue
		}

		// get pipeline detail to confirm whether the runtime has been created
		piplineDetail, err := bdl.GetPipeline(v.ID)
		if err != nil {
			return nil, err
		}

		if !isUndoneTaskOFDeployByRelease(piplineDetail) {
			// Task has been completed
			continue
		}

		result = append(result, apistructs.RuntimeSummaryDTO{
			RuntimeInspectDTO: apistructs.RuntimeInspectDTO{
				Name:         v.FilterLabels["branch"],
				Source:       apistructs.RELEASE,
				Status:       "Init",
				DeployStatus: apistructs.DeploymentStatusDeploying,
				ClusterName:  v.ClusterName,
				Extra: map[string]interface{}{"applicationId": v.FilterLabels["appID"], "buildId": v.ID,
					"workspace": v.Extra.DiceWorkspace, "commitId": v.Commit, "fakeRuntime": true},
				TimeCreated: *v.TimeBegin,
				CreatedAt:   *v.TimeBegin,
				UpdatedAt:   *v.TimeBegin,
			},
			LastOperateTime: *v.TimeBegin,
			LastOperator:    fmt.Sprintf("%v", v.Extra.RunUser.ID),
		})
	}

	return result, nil
}