| // Copyright 2020 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package props |
| |
| import ( |
| "fmt" |
| |
| buildbucketpb "go.chromium.org/luci/buildbucket/proto" |
| "go.chromium.org/luci/luciexe/exe" |
| ) |
| |
| // Set input property on Build.Input.Properties. |
| func SetInputProperty(build *buildbucketpb.Build, key string, value interface{}) error { |
| return exe.WriteProperties(build.Input.Properties, map[string]interface{}{ |
| key: value, |
| }) |
| } |
| |
| // Gets string input property from Build.Input.Properties. |
| // If property was not set, returns empty string and a nil error. |
| func GetStringInputProperty(build *buildbucketpb.Build, key string) (string, error) { |
| var val string |
| if err := exe.ParseProperties(build.Input.Properties, map[string]interface{}{ |
| key: &val, |
| }); err != nil { |
| return "", fmt.Errorf("failed to read %s property: %w", key, err) |
| } |
| return val, nil |
| } |
| |
| // Gets bool input property from Build.Input.Properties. |
| // If property was not set, returns false and a nil error. |
| func GetBoolInputProperty(build *buildbucketpb.Build, key string) (bool, error) { |
| var val bool |
| if err := exe.ParseProperties(build.Input.Properties, map[string]interface{}{ |
| key: &val, |
| }); err != nil { |
| return false, fmt.Errorf("failed to read %s property: %w", key, err) |
| } |
| return val, nil |
| } |