go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/rpc/versioning/status.go (about)

     1  // Copyright 2021 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package versioning
    16  
    17  import (
    18  	"errors"
    19  	"fmt"
    20  
    21  	apiv0pb "go.chromium.org/luci/cv/api/v0"
    22  	apiv1pb "go.chromium.org/luci/cv/api/v1"
    23  	"go.chromium.org/luci/cv/internal/run"
    24  	"go.chromium.org/luci/cv/internal/tryjob"
    25  )
    26  
    27  // TryjobStatusV0 converts internal Tryjob statuses to an APIv0 equivalent.
    28  func TryjobStatusV0(tjs tryjob.Status, tjrs tryjob.Result_Status) apiv0pb.TryjobStatus {
    29  	switch tjs {
    30  	case tryjob.Status_STATUS_UNSPECIFIED:
    31  		panic(errors.New("tryjob status not specified"))
    32  	case tryjob.Status_PENDING:
    33  		return apiv0pb.TryjobStatus_PENDING
    34  	case tryjob.Status_TRIGGERED:
    35  		return apiv0pb.TryjobStatus_RUNNING
    36  	case tryjob.Status_ENDED:
    37  		switch tjrs {
    38  		case tryjob.Result_RESULT_STATUS_UNSPECIFIED:
    39  			panic(errors.New("tryjob result status not specified"))
    40  		case tryjob.Result_SUCCEEDED:
    41  			return apiv0pb.TryjobStatus_SUCCEEDED
    42  		case tryjob.Result_FAILED_TRANSIENTLY, tryjob.Result_FAILED_PERMANENTLY, tryjob.Result_TIMEOUT:
    43  			return apiv0pb.TryjobStatus_FAILED
    44  		default:
    45  			panic(fmt.Sprintf("unknown tryjob result status: %s", tjrs))
    46  		}
    47  	case tryjob.Status_CANCELLED:
    48  		return apiv0pb.TryjobStatus_CANCELLED
    49  	case tryjob.Status_UNTRIGGERED:
    50  		return apiv0pb.TryjobStatus_UNTRIGGERED
    51  	default:
    52  		panic(fmt.Sprintf("unknown tryjob status: %s", tjs))
    53  	}
    54  
    55  }
    56  
    57  // LegacyTryjobStatusV0 converts internal Tryjob status to an APIv0 equivalent.
    58  func LegacyTryjobStatusV0(s tryjob.Status) apiv0pb.Tryjob_Status {
    59  	return apiv0pb.Tryjob_Status(s)
    60  }
    61  
    62  // LegacyTryjobResultStatusV0 converts internal Tryjob Result status to an APIv0 equivalent.
    63  func LegacyTryjobResultStatusV0(s tryjob.Result_Status) apiv0pb.Tryjob_Result_Status {
    64  	return apiv0pb.Tryjob_Result_Status(s)
    65  }
    66  
    67  // RunStatusV0 converts internal Run status to an APIv0 equivalent.
    68  func RunStatusV0(s run.Status) apiv0pb.Run_Status {
    69  	return apiv0pb.Run_Status(s)
    70  }
    71  
    72  // RunStatusV1 converts internal Run status to an APIv1 equivalent.
    73  func RunStatusV1(s run.Status) apiv1pb.Run_Status {
    74  	return apiv1pb.Run_Status(s)
    75  }