github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/tekton/utils.go (about)

     1  /*
     2  Copyright 2022.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package tekton
    18  
    19  import (
    20  	"github.com/redhat-appstudio/release-service/metadata"
    21  	tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
    22  	"knative.dev/pkg/apis"
    23  	"sigs.k8s.io/controller-runtime/pkg/client"
    24  )
    25  
    26  // isReleasePipelineRun returns a boolean indicating whether the object passed is a managed Release PipelineRun or not.
    27  func isReleasePipelineRun(object client.Object) bool {
    28  	_, ok := object.(*tektonv1.PipelineRun)
    29  	if !ok {
    30  		return false
    31  	}
    32  
    33  	labelValue, found := object.GetLabels()[metadata.PipelinesTypeLabel]
    34  
    35  	return found && labelValue == metadata.ManagedPipelineType
    36  }
    37  
    38  // hasPipelineSucceeded returns a boolean indicating whether the PipelineRun succeeded or not.
    39  // If the object passed to this function is not a PipelineRun, the function will return false.
    40  func hasPipelineSucceeded(object client.Object) bool {
    41  	if pipelineRun, ok := object.(*tektonv1.PipelineRun); ok {
    42  		return !pipelineRun.Status.GetCondition(apis.ConditionSucceeded).IsUnknown()
    43  	}
    44  
    45  	return false
    46  }