| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 // Package tasktemplate resolves Swarming task templates. |
| 6 // |
| 7 // Templated strings may be passed to Swarming tasks in order to have them |
| 8 // resolve task-side parameters. See Params for more information. |
| 9 package tasktemplate |
| 10 |
| 11 import ( |
| 12 "github.com/luci/luci-go/common/data/text/stringtemplate" |
| 13 ) |
| 14 |
| 15 // Params contains supported Swarming task string substitution parameters. |
| 16 // |
| 17 // A template string can be resolved by passing it to a Params instance's |
| 18 // Resolve method. |
| 19 type Params struct { |
| 20 // SwarmingRunID is the substitution to use for the "swarming_run_id" te
mplate |
| 21 // parameter. |
| 22 // |
| 23 // Note that this is the Swarming Run ID, not Task ID. The Run ID is the |
| 24 // combination of the Task ID with the try number. |
| 25 SwarmingRunID string |
| 26 } |
| 27 |
| 28 func (p *Params) substMap() map[string]string { |
| 29 res := make(map[string]string, 1) |
| 30 if p.SwarmingRunID != "" { |
| 31 res["swarming_run_id"] = p.SwarmingRunID |
| 32 } |
| 33 return res |
| 34 } |
| 35 |
| 36 // Resolve resolves v against p's parameters, populating any template fields |
| 37 // with their respective parameter value. |
| 38 // |
| 39 // If the string is invalid, or if it references an undefined template |
| 40 // parameter, an error will be returned. |
| 41 func (p *Params) Resolve(v string) (string, error) { |
| 42 return stringtemplate.Resolve(v, p.substMap()) |
| 43 } |
| OLD | NEW |