blob: 0fff4bf51dc2ac36885bf7fc178af4b9c65853d5 [file] [edit]
// Copyright 2026 Google LLC
//
// 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 besmsg
import (
"google.golang.org/protobuf/proto"
bespb "github.com/bazelbuild/rsclient/third_party/bazel/build_event_stream"
buildpb "google.golang.org/genproto/googleapis/devtools/build/v1"
)
// ExtractBuildEvent is a transformation helper that extracts the inner
// Bazel BuildEvent from a gRPC PublishBuildToolEventStreamRequest.
//
// This is used by components that need to inspect the details of
// specific Bazel events (like TargetFinished or ActionExecuted)
// without having to navigate the nested gRPC wrapper structure manually.
func ExtractBuildEvent(req *buildpb.PublishBuildToolEventStreamRequest) (*bespb.BuildEvent, bool) {
if req == nil {
return nil, false
}
orderedEvent := req.GetOrderedBuildEvent()
if orderedEvent == nil {
return nil, false
}
event := orderedEvent.GetEvent()
if event == nil {
return nil, false
}
// Unmarshal the embedded Bazel event from the BazelEvent Any message.
if bazelAny := event.GetBazelEvent(); bazelAny != nil {
bazelEvent := &bespb.BuildEvent{}
if err := proto.Unmarshal(bazelAny.Value, bazelEvent); err != nil {
return nil, false
}
return bazelEvent, true
}
return nil, false
}