Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Unified Diff: swarming/tasktemplate/template.go

Issue 2701033003: milo: Add SwarmBucket templating. (Closed)
Patch Set: Apparently "/swarming" is gitignored! Added... Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/appengine/swarming/testdata/build-running-logdog.swarm ('k') | swarming/tasktemplate/template_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: swarming/tasktemplate/template.go
diff --git a/swarming/tasktemplate/template.go b/swarming/tasktemplate/template.go
new file mode 100644
index 0000000000000000000000000000000000000000..bf423e35009e87e0bd79a77d620ab1650afb52ac
--- /dev/null
+++ b/swarming/tasktemplate/template.go
@@ -0,0 +1,43 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+// Package tasktemplate resolves Swarming task templates.
+//
+// Templated strings may be passed to Swarming tasks in order to have them
+// resolve task-side parameters. See Params for more information.
+package tasktemplate
+
+import (
+ "github.com/luci/luci-go/common/data/text/stringtemplate"
+)
+
+// Params contains supported Swarming task string substitution parameters.
+//
+// A template string can be resolved by passing it to a Params instance's
+// Resolve method.
+type Params struct {
+ // SwarmingRunID is the substitution to use for the "swarming_run_id" template
+ // parameter.
+ //
+ // Note that this is the Swarming Run ID, not Task ID. The Run ID is the
+ // combination of the Task ID with the try number.
+ SwarmingRunID string
+}
+
+func (p *Params) substMap() map[string]string {
+ res := make(map[string]string, 1)
+ if p.SwarmingRunID != "" {
+ res["swarming_run_id"] = p.SwarmingRunID
+ }
+ return res
+}
+
+// Resolve resolves v against p's parameters, populating any template fields
+// with their respective parameter value.
+//
+// If the string is invalid, or if it references an undefined template
+// parameter, an error will be returned.
+func (p *Params) Resolve(v string) (string, error) {
+ return stringtemplate.Resolve(v, p.substMap())
+}
« no previous file with comments | « milo/appengine/swarming/testdata/build-running-logdog.swarm ('k') | swarming/tasktemplate/template_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698