Skip to content

Commit 263ddea

Browse files
authored
feat(task): allow to get watchers (#439)
closes #188 Signed-off-by: Thomas Bétrancourt <thomas@betrancourt.net>
1 parent 0c55dbf commit 263ddea

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

models/task/task.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,18 @@ func (t *Task) ExportTaskInfos(values *values.Values) {
666666
m["task_id"] = t.PublicID
667667
m["created"] = t.Created
668668
m["requester_username"] = t.RequesterUsername
669-
if t.RequesterGroups != nil && len(t.RequesterGroups) > 0 {
669+
if len(t.RequesterGroups) > 0 {
670670
m["requester_groups"] = strings.Join(t.RequesterGroups, utask.GroupsSeparator)
671671
}
672672
if t.ResolverUsername != nil {
673673
m["resolver_username"] = t.ResolverUsername
674674
}
675+
if len(t.WatcherUsernames) > 0 {
676+
m["watcher_usernames"] = strings.Join(t.WatcherUsernames, utask.UsernamesSeparator)
677+
}
678+
if len(t.WatcherGroups) > 0 {
679+
m["watcher_groups"] = strings.Join(t.WatcherGroups, utask.GroupsSeparator)
680+
}
675681
m["last_activity"] = t.LastActivity
676682
m["region"] = utask.FRegion
677683
if t.Resolution != nil {

models/tasktemplate/validate.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func validTemplate(template string, inputs, resolverInputs []string, steps map[s
3131
}
3232

3333
stepNames := stepNames(steps)
34-
taskInfoKeys := []string{"resolver_username", "created", "requester_username", "requester_groups", "task_id", "region", "resolution_id"}
34+
taskInfoKeys := []string{"resolver_username", "created", "requester_username", "requester_groups", "task_id", "region", "resolution_id", "watcher_usernames", "watcher_groups"}
3535
for _, m := range matches {
3636
parts := strings.Split(m[1], ".")
3737
if len(parts) >= 3 {
@@ -138,13 +138,14 @@ func stepNames(stepMap map[string]*step.Step) []string {
138138

139139
// tryVariablePath tries to match a chain of variables with the given properties.
140140
// For example:
141-
// given properties = map[foo:[bar] bar:[bar] qux:[foo] utaskRootKey:[qux]]
142-
// and parts = [qux foo bar bar bar]
143-
// "qux.foo.bar.bar.bar" is valid since "qux" makes "foo", "foo" makes "bar"
144-
// and "bar" makes "bar".
145-
// "qux.foo.bar.foo" is not valid since we cannot make "foo" from "bar".
146-
// "foo.bar.bar" is not valid either since we start looping on parts using
147-
// utaskRootKey map, which contains root properties of the json schema.
141+
//
142+
// given properties = map[foo:[bar] bar:[bar] qux:[foo] utaskRootKey:[qux]]
143+
// and parts = [qux foo bar bar bar]
144+
// "qux.foo.bar.bar.bar" is valid since "qux" makes "foo", "foo" makes "bar"
145+
// and "bar" makes "bar".
146+
// "qux.foo.bar.foo" is not valid since we cannot make "foo" from "bar".
147+
// "foo.bar.bar" is not valid either since we start looping on parts using
148+
// utaskRootKey map, which contains root properties of the json schema.
148149
func tryVariablePath(properties map[string][]string, parts []string) error {
149150
// start with root properties
150151
lastKey := jsonschema.RootKey

utask.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ const (
101101
// NotificationStrategyFailureOnly corresponds to the mode where notifications will only be sent if the state is BLOCKED
102102
NotificationStrategyFailureOnly = "failure_only"
103103

104+
// UsernamesSeparator corresponds to the separator used to break a string into a list of usernames and vice versa.
105+
UsernamesSeparator = ","
106+
104107
// GroupsSeparator corresponds to the separator used to break a string into a list of groups and vice versa.
105108
GroupsSeparator = ","
106109

0 commit comments

Comments
 (0)