code: func StatusToV2(build *v1.ApiCommonBuildMessage) (pb.Status, error) {
  	switch build.Status {
  	case "":
  		return pb.Status_STATUS_UNSPECIFIED, nil
  
  	case "SCHEDULED":
  		return pb.Status_SCHEDULED, nil
  
  	case "STARTED":
  		return pb.Status_STARTED, nil
  
  	case "COMPLETED":
  		switch build.Result {
  		case "SUCCESS":
  			return pb.Status_SUCCESS, nil
  
  		case "FAILURE":
  			switch build.FailureReason {
  			case "", "BUILD_FAILURE":
  				return pb.Status_FAILURE, nil
  			case "INFRA_FAILURE", "BUILDBUCKET_FAILURE", "INVALID_BUILD_DEFINITION":
  				return pb.Status_INFRA_FAILURE, nil
  			default:
  				return 0, errors.Reason("unexpected failure reason %q", build.FailureReason).Tag(MalformedBuild).Err()
  			}
  
  		case "CANCELED":
  			switch build.CancelationReason {
  			case "", "CANCELED_EXPLICITLY":
  				return pb.Status_CANCELED, nil
  			case "TIMEOUT":
  				return pb.Status_INFRA_FAILURE, nil
  			default:
  				return 0, errors.Reason("unexpected cancellation reason %q", build.CancelationReason).Tag(MalformedBuild).Err()
  			}
  
  		default:
  			return 0, errors.Reason("unexpected result %q", build.Result).Tag(MalformedBuild).Err()
  		}
  
  	default:
  		return 0, errors.Reason("unexpected status %q", build.Status).Tag(MalformedBuild).Err()
  	}
  }
docs: // StatusToV2 converts v1 build's Status, Result, FailureReason and
  // CancelationReason to v2 Status enum.
  //
  // If build.Status is "", returns (Status_STATUS_UNSPECIFIED, nil).
  // Useful with partial buildbucket responses.