From fbec1ec1cf0259dbf18674113e241d6fbc88c3c6 Mon Sep 17 00:00:00 2001 From: mdrakos Date: Wed, 20 Nov 2024 16:00:47 -0800 Subject: [PATCH] Rename messages to notifications --- cmd/state-svc/gqlgen.yml | 4 +- .../{messages => notifications}/condition.go | 2 +- .../notifications.go} | 122 +- .../notifications_test.go} | 80 +- cmd/state-svc/internal/resolver/resolver.go | 10 +- .../internal/server/generated/generated.go | 1212 ++++++----------- cmd/state-svc/schema/schema.graphqls | 18 +- .../messenger.go => notifier/notifier.go} | 58 +- cmd/state/main.go | 8 +- internal/constants/constants.go | 4 +- internal/graph/generated.go | 118 +- pkg/platform/api/svc/request/messaging.go | 31 - pkg/platform/api/svc/request/notification.go | 31 + pkg/platform/model/svc.go | 12 +- ...g_int_test.go => notification_int_test.go} | 84 +- 15 files changed, 687 insertions(+), 1107 deletions(-) rename cmd/state-svc/internal/{messages => notifications}/condition.go (98%) rename cmd/state-svc/internal/{messages/messages.go => notifications/notifications.go} (50%) rename cmd/state-svc/internal/{messages/messages_test.go => notifications/notifications_test.go} (78%) rename cmd/state/internal/cmdtree/exechandlers/{messenger/messenger.go => notifier/notifier.go} (53%) delete mode 100644 pkg/platform/api/svc/request/messaging.go create mode 100644 pkg/platform/api/svc/request/notification.go rename test/integration/{msg_int_test.go => notification_int_test.go} (62%) diff --git a/cmd/state-svc/gqlgen.yml b/cmd/state-svc/gqlgen.yml index 0c6a28fb70..476087864a 100644 --- a/cmd/state-svc/gqlgen.yml +++ b/cmd/state-svc/gqlgen.yml @@ -39,8 +39,8 @@ model: # gqlgen will search for any type names in the schema in these go packages # if they match it will use them, otherwise it will generate them. -autobind: - - "github.com/ActiveState/cli/internal/graph" +# autobind: +# - "github.com/ActiveState/cli/internal/graph" # This section declares type mapping between the GraphQL and go type systems # diff --git a/cmd/state-svc/internal/messages/condition.go b/cmd/state-svc/internal/notifications/condition.go similarity index 98% rename from cmd/state-svc/internal/messages/condition.go rename to cmd/state-svc/internal/notifications/condition.go index 5e39e8326e..2645dd98ea 100644 --- a/cmd/state-svc/internal/messages/condition.go +++ b/cmd/state-svc/internal/notifications/condition.go @@ -1,4 +1,4 @@ -package messages +package notifications import ( "regexp" diff --git a/cmd/state-svc/internal/messages/messages.go b/cmd/state-svc/internal/notifications/notifications.go similarity index 50% rename from cmd/state-svc/internal/messages/messages.go rename to cmd/state-svc/internal/notifications/notifications.go index 37581d067b..6d65b35393 100644 --- a/cmd/state-svc/internal/messages/messages.go +++ b/cmd/state-svc/internal/notifications/notifications.go @@ -1,4 +1,4 @@ -package messages +package notifications import ( "encoding/json" @@ -25,7 +25,7 @@ import ( const ConfigKeyLastReport = "messages.last_reported" -type Messages struct { +type Notifications struct { cfg *config.Instance auth *auth.Auth baseParams *ConditionParams @@ -33,7 +33,7 @@ type Messages struct { checkMutex sync.Mutex } -func New(cfg *config.Instance, auth *auth.Auth) (*Messages, error) { +func New(cfg *config.Instance, auth *auth.Auth) (*Notifications, error) { osVersion, err := sysinfo.OSVersion() if err != nil { return nil, errs.Wrap(err, "Could not get OS version") @@ -52,7 +52,7 @@ func New(cfg *config.Instance, auth *auth.Auth) (*Messages, error) { return resp, err }) - return &Messages{ + return &Notifications{ baseParams: &ConditionParams{ OS: sysinfo.OS().String(), OSVersion: NewVersionFromSysinfo(osVersion), @@ -65,22 +65,22 @@ func New(cfg *config.Instance, auth *auth.Auth) (*Messages, error) { }, nil } -func (m *Messages) Close() error { +func (m *Notifications) Close() error { m.poll.Close() return nil } -func (m *Messages) Check(command string, flags []string) ([]*graph.MessageInfo, error) { - // Prevent multiple checks at the same time, which could lead to the same message showing multiple times +func (m *Notifications) Check(command string, flags []string) ([]*graph.NotificationInfo, error) { + // Prevent multiple checks at the same time, which could lead to the same notification showing multiple times m.checkMutex.Lock() defer m.checkMutex.Unlock() cacheValue := m.poll.ValueFromCache() if cacheValue == nil { - return []*graph.MessageInfo{}, nil + return []*graph.NotificationInfo{}, nil } - allMessages, ok := cacheValue.([]*graph.MessageInfo) + allNotifications, ok := cacheValue.([]*graph.NotificationInfo) if !ok { return nil, errs.New("cacheValue has unexpected type: %T", cacheValue) } @@ -95,10 +95,10 @@ func (m *Messages) Check(command string, flags []string) ([]*graph.MessageInfo, conditionParams.UserID = id.String() } - logging.Debug("Checking %d messages with params: %#v", len(allMessages), conditionParams) + logging.Debug("Checking %d notifications with params: %#v", len(allNotifications), conditionParams) lastReportMap := m.cfg.GetStringMap(ConfigKeyLastReport) - msgs, err := check(&conditionParams, allMessages, lastReportMap, time.Now()) + msgs, err := check(&conditionParams, allNotifications, lastReportMap, time.Now()) if err != nil { return nil, errs.Wrap(err, "Could not check messages") } @@ -106,27 +106,27 @@ func (m *Messages) Check(command string, flags []string) ([]*graph.MessageInfo, lastReportMap[msg.ID] = time.Now().Format(time.RFC3339) } if err := m.cfg.Set(ConfigKeyLastReport, lastReportMap); err != nil { - return nil, errs.Wrap(err, "Could not save last reported messages") + return nil, errs.Wrap(err, "Could not save last reported notifications") } return msgs, nil } -func messageInDateRange(message *graph.MessageInfo, baseTime time.Time) (bool, error) { - if message.StartDate != "" { - startDate, err := time.Parse(time.RFC3339, message.StartDate) +func notificationInDateRange(notification *graph.NotificationInfo, baseTime time.Time) (bool, error) { + if notification.StartDate != "" { + startDate, err := time.Parse(time.RFC3339, notification.StartDate) if err != nil { - return false, errs.Wrap(err, "Could not parse start date for message %s", message.ID) + return false, errs.Wrap(err, "Could not parse start date for notification %s", notification.ID) } if baseTime.Before(startDate) { return false, nil } } - if message.EndDate != "" { - endDate, err := time.Parse(time.RFC3339, message.EndDate) + if notification.EndDate != "" { + endDate, err := time.Parse(time.RFC3339, notification.EndDate) if err != nil { - return false, errs.Wrap(err, "Could not parse end date for message %s", message.ID) + return false, errs.Wrap(err, "Could not parse end date for notification %s", notification.ID) } if baseTime.After(endDate) { return false, nil @@ -136,73 +136,73 @@ func messageInDateRange(message *graph.MessageInfo, baseTime time.Time) (bool, e return true, nil } -func check(params *ConditionParams, messages []*graph.MessageInfo, lastReportMap map[string]interface{}, baseTime time.Time) ([]*graph.MessageInfo, error) { +func check(params *ConditionParams, notifications []*graph.NotificationInfo, lastReportMap map[string]interface{}, baseTime time.Time) ([]*graph.NotificationInfo, error) { funcMap := conditionFuncMap() - filteredMessages := []*graph.MessageInfo{} - for _, message := range messages { - logging.Debug("Checking message %s", message.ID) + filteredNotifications := []*graph.NotificationInfo{} + for _, notification := range notifications { + logging.Debug("Checking notification %s", notification.ID) // Ensure we don't show the same message too often - if lastReport, ok := lastReportMap[message.ID]; ok { + if lastReport, ok := lastReportMap[notification.ID]; ok { lr, ok := lastReport.(string) if !ok { - return nil, errs.New("Could not get last reported time for message %s as it's not a string: %T", message.ID, lastReport) + return nil, errs.New("Could not get last reported time for notification %s as it's not a string: %T", notification.ID, lastReport) } lastReportTime, err := time.Parse(time.RFC3339, lr) if err != nil { - return nil, errs.New("Could not parse last reported time for message %s as it's not a valid RFC3339 value: %v", message.ID, lastReport) + return nil, errs.New("Could not parse last reported time for notification %s as it's not a valid RFC3339 value: %v", notification.ID, lastReport) } lastReportTimeAgo := baseTime.Sub(lastReportTime) - showMessage, err := repeatValid(message.Repeat, lastReportTimeAgo) + showNotification, err := repeatValid(notification.Repeat, lastReportTimeAgo) if err != nil { - return nil, errs.Wrap(err, "Could not validate repeat for message %s", message.ID) + return nil, errs.Wrap(err, "Could not validate repeat for notification %s", notification.ID) } - if !showMessage { - logging.Debug("Skipping message %s as it was shown %s ago", message.ID, lastReportTimeAgo) + if !showNotification { + logging.Debug("Skipping notification %s as it was shown %s ago", notification.ID, lastReportTimeAgo) continue } } // Check if message is within date range - inRange, err := messageInDateRange(message, baseTime) + inRange, err := notificationInDateRange(notification, baseTime) if err != nil { - logging.Warning("Could not check if message %s is in date range: %v", message.ID, err) + logging.Warning("Could not check if notification %s is in date range: %v", notification.ID, err) continue } if !inRange { - logging.Debug("Skipping message %s as it is outside of its date range", message.ID) + logging.Debug("Skipping notification %s as it is outside of its date range", notification.ID) continue } // Validate the conditional - if message.Condition != "" { - result, err := strutils.ParseTemplate(fmt.Sprintf(`{{%s}}`, message.Condition), params, funcMap) + if notification.Condition != "" { + result, err := strutils.ParseTemplate(fmt.Sprintf(`{{%s}}`, notification.Condition), params, funcMap) if err != nil { - logging.Warning("Could not parse condition template for message %s: %v", message.ID, err) + logging.Warning("Could not parse condition template for notification %s: %v", notification.ID, err) continue } if result == "true" { - logging.Debug("Including message %s as condition %s evaluated to %s", message.ID, message.Condition, result) - filteredMessages = append(filteredMessages, message) + logging.Debug("Including notification %s as condition %s evaluated to %s", notification.ID, notification.Condition, result) + filteredNotifications = append(filteredNotifications, notification) } else { - logging.Debug("Skipping message %s as condition %s evaluated to %s", message.ID, message.Condition, result) + logging.Debug("Skipping notification %s as condition %s evaluated to %s", notification.ID, notification.Condition, result) } } else { - logging.Debug("Including message %s as it has no condition", message.ID) - filteredMessages = append(filteredMessages, message) + logging.Debug("Including notification %s as it has no condition", notification.ID) + filteredNotifications = append(filteredNotifications, notification) } } - return filteredMessages, nil + return filteredNotifications, nil } -func fetch() ([]*graph.MessageInfo, error) { +func fetch() ([]*graph.NotificationInfo, error) { var body []byte var err error - if v := os.Getenv(constants.MessagesOverrideEnvVarName); v != "" { + if v := os.Getenv(constants.NotificationsOverrideEnvVarName); v != "" { body, err = fileutils.ReadFile(v) if err != nil { return nil, errs.Wrap(err, "Could not read messages override file") @@ -214,40 +214,40 @@ func fetch() ([]*graph.MessageInfo, error) { } } - var messages []*graph.MessageInfo - if err := json.Unmarshal(body, &messages); err != nil { + var notifications []*graph.NotificationInfo + if err := json.Unmarshal(body, ¬ifications); err != nil { return nil, errs.Wrap(err, "Could not unmarshall messages information") } // Set defaults - for _, message := range messages { - if message.Placement == "" { - message.Placement = graph.MessagePlacementTypeBeforeCmd + for _, notification := range notifications { + if notification.Placement == "" { + notification.Placement = graph.NotificationPlacementTypeBeforeCmd } - if message.Interrupt == "" { - message.Interrupt = graph.MessageInterruptTypeDisabled + if notification.Interrupt == "" { + notification.Interrupt = graph.NotificationInterruptTypeDisabled } - if message.Repeat == "" { - message.Repeat = graph.MessageRepeatTypeDisabled + if notification.Repeat == "" { + notification.Repeat = graph.NotificationRepeatTypeDisabled } } - return messages, nil + return notifications, nil } -func repeatValid(repeatType graph.MessageRepeatType, lastReportTimeAgo time.Duration) (bool, error) { +func repeatValid(repeatType graph.NotificationRepeatType, lastReportTimeAgo time.Duration) (bool, error) { switch repeatType { - case graph.MessageRepeatTypeConstantly: + case graph.NotificationRepeatTypeConstantly: return true, nil - case graph.MessageRepeatTypeDisabled: + case graph.NotificationRepeatTypeDisabled: return false, nil - case graph.MessageRepeatTypeHourly: + case graph.NotificationRepeatTypeHourly: return lastReportTimeAgo >= time.Hour, nil - case graph.MessageRepeatTypeDaily: + case graph.NotificationRepeatTypeDaily: return lastReportTimeAgo >= 24*time.Hour, nil - case graph.MessageRepeatTypeWeekly: + case graph.NotificationRepeatTypeWeekly: return lastReportTimeAgo >= 7*24*time.Hour, nil - case graph.MessageRepeatTypeMonthly: + case graph.NotificationRepeatTypeMonthly: return lastReportTimeAgo >= 30*24*time.Hour, nil default: return false, errs.New("Unknown repeat type: %s", repeatType) diff --git a/cmd/state-svc/internal/messages/messages_test.go b/cmd/state-svc/internal/notifications/notifications_test.go similarity index 78% rename from cmd/state-svc/internal/messages/messages_test.go rename to cmd/state-svc/internal/notifications/notifications_test.go index 186bc6719e..fae1dd5e3b 100644 --- a/cmd/state-svc/internal/messages/messages_test.go +++ b/cmd/state-svc/internal/notifications/notifications_test.go @@ -1,4 +1,4 @@ -package messages +package notifications import ( "reflect" @@ -14,7 +14,7 @@ func Test_check(t *testing.T) { baseTime := time.Now() type args struct { params *ConditionParams - messages []*graph.MessageInfo + notifications []*graph.NotificationInfo lastReportMap map[string]interface{} baseTime time.Time } @@ -28,7 +28,7 @@ func Test_check(t *testing.T) { "No special conditions", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A"}, {ID: "B"}, {ID: "C"}, }, lastReportMap: map[string]interface{}{}, @@ -43,7 +43,7 @@ func Test_check(t *testing.T) { params: &ConditionParams{ Command: "foo", }, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", Condition: `eq .Command "bar"`}, {ID: "B", Condition: `eq .Command "foo"`}, {ID: "C", Condition: `eq .Command "foobar"`}, @@ -60,7 +60,7 @@ func Test_check(t *testing.T) { params: &ConditionParams{ UserEmail: "john@doe.org", }, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", Condition: `contains .UserEmail "john"`}, {ID: "B", Condition: `contains .UserEmail "fred"`}, }, @@ -76,7 +76,7 @@ func Test_check(t *testing.T) { params: &ConditionParams{ UserEmail: "john@doe.org", }, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", Condition: `hasPrefix .UserEmail "john"`}, {ID: "B", Condition: `hasPrefix .UserEmail "org"`}, }, @@ -92,7 +92,7 @@ func Test_check(t *testing.T) { params: &ConditionParams{ UserEmail: "john@doe.org", }, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", Condition: `hasSuffix .UserEmail "john"`}, {ID: "B", Condition: `hasSuffix .UserEmail "org"`}, }, @@ -108,7 +108,7 @@ func Test_check(t *testing.T) { params: &ConditionParams{ UserEmail: "john@doe.org", }, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", Condition: `regexMatch .UserEmail ".*@doe.org$"`}, {ID: "B", Condition: `regexMatch .UserEmail "^doe.org$"`}, }, @@ -124,7 +124,7 @@ func Test_check(t *testing.T) { params: &ConditionParams{ UserEmail: "john@doe.org", }, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", Condition: `regexMatch .UserEmail ".*@doe.org$"`}, {ID: "B", Condition: `regexMatch .UserEmail ".*("`}, }, @@ -140,7 +140,7 @@ func Test_check(t *testing.T) { params: &ConditionParams{ StateVersion: NewVersionFromSemver(semver.MustParse("7.8.9-SHA123456a7b")), }, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", Condition: `eq .StateVersion.Major 7`}, {ID: "B", Condition: `eq .StateVersion.Minor 8`}, {ID: "C", Condition: `eq .StateVersion.Patch 9`}, @@ -160,10 +160,10 @@ func Test_check(t *testing.T) { "Repeat Disabled", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ - {ID: "A", Repeat: graph.MessageRepeatTypeDisabled}, - {ID: "B", Repeat: graph.MessageRepeatTypeDisabled}, - {ID: "C", Repeat: graph.MessageRepeatTypeDisabled}, + notifications: []*graph.NotificationInfo{ + {ID: "A", Repeat: graph.NotificationRepeatTypeDisabled}, + {ID: "B", Repeat: graph.NotificationRepeatTypeDisabled}, + {ID: "C", Repeat: graph.NotificationRepeatTypeDisabled}, }, lastReportMap: map[string]interface{}{ "A": baseTime.Format(time.RFC3339), @@ -178,10 +178,10 @@ func Test_check(t *testing.T) { "Repeat Constantly", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ - {ID: "A", Repeat: graph.MessageRepeatTypeConstantly}, - {ID: "B", Repeat: graph.MessageRepeatTypeConstantly}, - {ID: "C", Repeat: graph.MessageRepeatTypeConstantly}, + notifications: []*graph.NotificationInfo{ + {ID: "A", Repeat: graph.NotificationRepeatTypeConstantly}, + {ID: "B", Repeat: graph.NotificationRepeatTypeConstantly}, + {ID: "C", Repeat: graph.NotificationRepeatTypeConstantly}, }, lastReportMap: map[string]interface{}{ "A": baseTime.Format(time.RFC3339), @@ -196,10 +196,10 @@ func Test_check(t *testing.T) { "Repeat Hourly", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ - {ID: "A", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "B", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, + notifications: []*graph.NotificationInfo{ + {ID: "A", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "B", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "C", Repeat: graph.NotificationRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ "A": baseTime.Format(time.RFC3339), @@ -215,10 +215,10 @@ func Test_check(t *testing.T) { "Repeat Daily", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ - {ID: "A", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "B", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, + notifications: []*graph.NotificationInfo{ + {ID: "A", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "B", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "C", Repeat: graph.NotificationRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ "A": baseTime.Format(time.RFC3339), @@ -234,10 +234,10 @@ func Test_check(t *testing.T) { "Repeat Weekly", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ - {ID: "A", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "B", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, + notifications: []*graph.NotificationInfo{ + {ID: "A", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "B", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "C", Repeat: graph.NotificationRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ "A": baseTime.Format(time.RFC3339), @@ -253,10 +253,10 @@ func Test_check(t *testing.T) { "Repeat Monthly", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ - {ID: "A", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "B", Repeat: graph.MessageRepeatTypeHourly}, - {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, + notifications: []*graph.NotificationInfo{ + {ID: "A", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "B", Repeat: graph.NotificationRepeatTypeHourly}, + {ID: "C", Repeat: graph.NotificationRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ "A": baseTime.Format(time.RFC3339), @@ -272,7 +272,7 @@ func Test_check(t *testing.T) { "Date Range - Within Range", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", StartDate: baseTime.Add(-24 * time.Hour).Format(time.RFC3339), EndDate: baseTime.Add(24 * time.Hour).Format(time.RFC3339)}, {ID: "B", StartDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339), EndDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, {ID: "C", StartDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339), EndDate: baseTime.Add(24 * time.Hour).Format(time.RFC3339)}, @@ -287,7 +287,7 @@ func Test_check(t *testing.T) { "Date Range - No Dates Specified", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A"}, {ID: "B", StartDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339)}, {ID: "C", EndDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, @@ -302,7 +302,7 @@ func Test_check(t *testing.T) { "Date Range - Invalid Date Format", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", StartDate: "invalid-date"}, }, lastReportMap: map[string]interface{}{}, @@ -315,7 +315,7 @@ func Test_check(t *testing.T) { "Date Range - Only Start Date", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", StartDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339)}, {ID: "B", StartDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, }, @@ -329,7 +329,7 @@ func Test_check(t *testing.T) { "Date Range - Only End Date", args{ params: &ConditionParams{}, - messages: []*graph.MessageInfo{ + notifications: []*graph.NotificationInfo{ {ID: "A", EndDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, {ID: "B", EndDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339)}, }, @@ -342,7 +342,7 @@ func Test_check(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := check(tt.args.params, tt.args.messages, tt.args.lastReportMap, tt.args.baseTime) + got, err := check(tt.args.params, tt.args.notifications, tt.args.lastReportMap, tt.args.baseTime) if (err != nil) != tt.wantErr { t.Errorf("check() error = %v, wantErr %v", errs.JoinMessage(err), tt.wantErr) return diff --git a/cmd/state-svc/internal/resolver/resolver.go b/cmd/state-svc/internal/resolver/resolver.go index ba91441e7f..4f218fefb8 100644 --- a/cmd/state-svc/internal/resolver/resolver.go +++ b/cmd/state-svc/internal/resolver/resolver.go @@ -11,7 +11,7 @@ import ( "github.com/ActiveState/cli/cmd/state-svc/internal/graphqltypes" "github.com/ActiveState/cli/cmd/state-svc/internal/hash" - "github.com/ActiveState/cli/cmd/state-svc/internal/messages" + "github.com/ActiveState/cli/cmd/state-svc/internal/notifications" "github.com/ActiveState/cli/cmd/state-svc/internal/rtwatcher" genserver "github.com/ActiveState/cli/cmd/state-svc/internal/server/generated" "github.com/ActiveState/cli/internal/analytics/client/sync" @@ -35,7 +35,7 @@ import ( type Resolver struct { cfg *config.Instance - messages *messages.Messages + messages *notifications.Notifications updatePoller *poller.Poller authPoller *poller.Poller projectIDCache *projectcache.ID @@ -50,7 +50,7 @@ type Resolver struct { // var _ genserver.ResolverRoot = &Resolver{} // Must implement ResolverRoot func New(cfg *config.Instance, an *sync.Client, auth *authentication.Auth) (*Resolver, error) { - msg, err := messages.New(cfg, auth) + msg, err := notifications.New(cfg, auth) if err != nil { return nil, errs.Wrap(err, "Could not initialize messages") } @@ -247,9 +247,9 @@ func (r *Resolver) ReportRuntimeUsage(_ context.Context, pid int, exec, source s return &graph.ReportRuntimeUsageResponse{Received: true}, nil } -func (r *Resolver) CheckMessages(ctx context.Context, command string, flags []string) ([]*graph.MessageInfo, error) { +func (r *Resolver) CheckNotifications(ctx context.Context, command string, flags []string) ([]*graph.NotificationInfo, error) { defer func() { panics.LogAndPanic(recover(), debug.Stack()) }() - logging.Debug("Check messages resolver") + logging.Debug("Check notifications resolver") return r.messages.Check(command, flags) } diff --git a/cmd/state-svc/internal/server/generated/generated.go b/cmd/state-svc/internal/server/generated/generated.go index cfb794c9ee..b290494161 100644 --- a/cmd/state-svc/internal/server/generated/generated.go +++ b/cmd/state-svc/internal/server/generated/generated.go @@ -79,21 +79,21 @@ type ComplexityRoot struct { User func(childComplexity int) int } - MessageInfo struct { - Condition func(childComplexity int) int - EndDate func(childComplexity int) int - ID func(childComplexity int) int - Interrupt func(childComplexity int) int - Message func(childComplexity int) int - Placement func(childComplexity int) int - Repeat func(childComplexity int) int - StartDate func(childComplexity int) int - } - Mutation struct { SetCache func(childComplexity int, key string, value string, expiry int) int } + NotificationInfo struct { + Condition func(childComplexity int) int + EndDate func(childComplexity int) int + ID func(childComplexity int) int + Interrupt func(childComplexity int) int + Notification func(childComplexity int) int + Placement func(childComplexity int) int + Repeat func(childComplexity int) int + StartDate func(childComplexity int) int + } + Organization struct { Role func(childComplexity int) int URLname func(childComplexity int) int @@ -112,7 +112,7 @@ type ComplexityRoot struct { Query struct { AnalyticsEvent func(childComplexity int, category string, action string, source string, label *string, dimensionsJSON string) int AvailableUpdate func(childComplexity int, desiredChannel string, desiredVersion string) int - CheckMessages func(childComplexity int, command string, flags []string) int + CheckNotifications func(childComplexity int, command string, flags []string) int ConfigChanged func(childComplexity int, key string) int FetchLogTail func(childComplexity int) int GetCache func(childComplexity int, key string) int @@ -157,7 +157,7 @@ type QueryResolver interface { Projects(ctx context.Context) ([]*graph.Project, error) AnalyticsEvent(ctx context.Context, category string, action string, source string, label *string, dimensionsJSON string) (*graph.AnalyticsEventResponse, error) ReportRuntimeUsage(ctx context.Context, pid int, exec string, source string, dimensionsJSON string) (*graph.ReportRuntimeUsageResponse, error) - CheckMessages(ctx context.Context, command string, flags []string) ([]*graph.MessageInfo, error) + CheckNotifications(ctx context.Context, command string, flags []string) ([]*graph.NotificationInfo, error) ConfigChanged(ctx context.Context, key string) (*graph.ConfigChangedResponse, error) FetchLogTail(ctx context.Context) (string, error) GetProcessesInUse(ctx context.Context, execDir string) ([]*graph.ProcessInfo, error) @@ -283,73 +283,73 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.JWT.User(childComplexity), true - case "MessageInfo.condition": - if e.complexity.MessageInfo.Condition == nil { + case "Mutation.setCache": + if e.complexity.Mutation.SetCache == nil { break } - return e.complexity.MessageInfo.Condition(childComplexity), true - - case "MessageInfo.endDate": - if e.complexity.MessageInfo.EndDate == nil { - break + args, err := ec.field_Mutation_setCache_args(context.TODO(), rawArgs) + if err != nil { + return 0, false } - return e.complexity.MessageInfo.EndDate(childComplexity), true + return e.complexity.Mutation.SetCache(childComplexity, args["key"].(string), args["value"].(string), args["expiry"].(int)), true - case "MessageInfo.id": - if e.complexity.MessageInfo.ID == nil { + case "NotificationInfo.condition": + if e.complexity.NotificationInfo.Condition == nil { break } - return e.complexity.MessageInfo.ID(childComplexity), true + return e.complexity.NotificationInfo.Condition(childComplexity), true - case "MessageInfo.interrupt": - if e.complexity.MessageInfo.Interrupt == nil { + case "NotificationInfo.endDate": + if e.complexity.NotificationInfo.EndDate == nil { break } - return e.complexity.MessageInfo.Interrupt(childComplexity), true + return e.complexity.NotificationInfo.EndDate(childComplexity), true - case "MessageInfo.message": - if e.complexity.MessageInfo.Message == nil { + case "NotificationInfo.id": + if e.complexity.NotificationInfo.ID == nil { break } - return e.complexity.MessageInfo.Message(childComplexity), true + return e.complexity.NotificationInfo.ID(childComplexity), true - case "MessageInfo.placement": - if e.complexity.MessageInfo.Placement == nil { + case "NotificationInfo.interrupt": + if e.complexity.NotificationInfo.Interrupt == nil { break } - return e.complexity.MessageInfo.Placement(childComplexity), true + return e.complexity.NotificationInfo.Interrupt(childComplexity), true - case "MessageInfo.repeat": - if e.complexity.MessageInfo.Repeat == nil { + case "NotificationInfo.notification": + if e.complexity.NotificationInfo.Notification == nil { break } - return e.complexity.MessageInfo.Repeat(childComplexity), true + return e.complexity.NotificationInfo.Notification(childComplexity), true - case "MessageInfo.startDate": - if e.complexity.MessageInfo.StartDate == nil { + case "NotificationInfo.placement": + if e.complexity.NotificationInfo.Placement == nil { break } - return e.complexity.MessageInfo.StartDate(childComplexity), true + return e.complexity.NotificationInfo.Placement(childComplexity), true - case "Mutation.setCache": - if e.complexity.Mutation.SetCache == nil { + case "NotificationInfo.repeat": + if e.complexity.NotificationInfo.Repeat == nil { break } - args, err := ec.field_Mutation_setCache_args(context.TODO(), rawArgs) - if err != nil { - return 0, false + return e.complexity.NotificationInfo.Repeat(childComplexity), true + + case "NotificationInfo.startDate": + if e.complexity.NotificationInfo.StartDate == nil { + break } - return e.complexity.Mutation.SetCache(childComplexity, args["key"].(string), args["value"].(string), args["expiry"].(int)), true + return e.complexity.NotificationInfo.StartDate(childComplexity), true case "Organization.role": if e.complexity.Organization.Role == nil { @@ -417,17 +417,17 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.AvailableUpdate(childComplexity, args["desiredChannel"].(string), args["desiredVersion"].(string)), true - case "Query.checkMessages": - if e.complexity.Query.CheckMessages == nil { + case "Query.checkNotifications": + if e.complexity.Query.CheckNotifications == nil { break } - args, err := ec.field_Query_checkMessages_args(context.TODO(), rawArgs) + args, err := ec.field_Query_checkNotifications_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.CheckMessages(childComplexity, args["command"].(string), args["flags"].([]string)), true + return e.complexity.Query.CheckNotifications(childComplexity, args["command"].(string), args["flags"].([]string)), true case "Query.configChanged": if e.complexity.Query.ConfigChanged == nil { @@ -731,7 +731,7 @@ type ReportRuntimeUsageResponse { received: Boolean! } -enum MessageRepeatType { +enum NotificationRepeatType { Disabled Constantly Hourly @@ -740,26 +740,26 @@ enum MessageRepeatType { Monthly } -enum MessageInterruptType { +enum NotificationInterruptType { Disabled Prompt Exit } -enum MessagePlacementType { +enum NotificationPlacementType { BeforeCmd AfterCmd } -type MessageInfo { +type NotificationInfo { id: String! - message: String! + notification: String! condition: String! startDate: String! endDate: String! - repeat: MessageRepeatType! - interrupt: MessageInterruptType! - placement: MessagePlacementType! + repeat: NotificationRepeatType! + interrupt: NotificationInterruptType! + placement: NotificationPlacementType! } type Organization { @@ -796,7 +796,7 @@ type Query { projects: [Project]! analyticsEvent(category: String!, action: String!, source: String!, label: String, dimensionsJson: String!): AnalyticsEventResponse reportRuntimeUsage(pid: Int!, exec: String!, source: String!, dimensionsJson: String!): ReportRuntimeUsageResponse - checkMessages(command: String!, flags: [String!]!): [MessageInfo!]! + checkNotifications(command: String!, flags: [String!]!): [NotificationInfo!]! configChanged(key: String!): ConfigChangedResponse fetchLogTail: String! getProcessesInUse(execDir: String!): [ProcessInfo!]! @@ -830,710 +830,290 @@ var parsedSchema = gqlparser.MustLoadSchema(sources...) func (ec *executionContext) field_Mutation_setCache_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Mutation_setCache_argsKey(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["key"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["key"] = arg0 - arg1, err := ec.field_Mutation_setCache_argsValue(ctx, rawArgs) - if err != nil { - return nil, err + var arg1 string + if tmp, ok := rawArgs["value"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["value"] = arg1 - arg2, err := ec.field_Mutation_setCache_argsExpiry(ctx, rawArgs) - if err != nil { - return nil, err + var arg2 int + if tmp, ok := rawArgs["expiry"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expiry")) + arg2, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } } args["expiry"] = arg2 return args, nil } -func (ec *executionContext) field_Mutation_setCache_argsKey( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["key"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) - if tmp, ok := rawArgs["key"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Mutation_setCache_argsValue( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["value"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) - if tmp, ok := rawArgs["value"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Mutation_setCache_argsExpiry( - ctx context.Context, - rawArgs map[string]interface{}, -) (int, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["expiry"] - if !ok { - var zeroVal int - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("expiry")) - if tmp, ok := rawArgs["expiry"]; ok { - return ec.unmarshalNInt2int(ctx, tmp) - } - - var zeroVal int - return zeroVal, nil -} func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query___type_argsName(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["name"] = arg0 return args, nil } -func (ec *executionContext) field_Query___type_argsName( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["name"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) - if tmp, ok := rawArgs["name"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} func (ec *executionContext) field_Query_analyticsEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_analyticsEvent_argsCategory(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["category"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("category")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["category"] = arg0 - arg1, err := ec.field_Query_analyticsEvent_argsAction(ctx, rawArgs) - if err != nil { - return nil, err + var arg1 string + if tmp, ok := rawArgs["action"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("action")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["action"] = arg1 - arg2, err := ec.field_Query_analyticsEvent_argsSource(ctx, rawArgs) - if err != nil { - return nil, err + var arg2 string + if tmp, ok := rawArgs["source"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) + arg2, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["source"] = arg2 - arg3, err := ec.field_Query_analyticsEvent_argsLabel(ctx, rawArgs) - if err != nil { - return nil, err + var arg3 *string + if tmp, ok := rawArgs["label"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("label")) + arg3, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } } args["label"] = arg3 - arg4, err := ec.field_Query_analyticsEvent_argsDimensionsJSON(ctx, rawArgs) - if err != nil { - return nil, err + var arg4 string + if tmp, ok := rawArgs["dimensionsJson"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) + arg4, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["dimensionsJson"] = arg4 return args, nil } -func (ec *executionContext) field_Query_analyticsEvent_argsCategory( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["category"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("category")) - if tmp, ok := rawArgs["category"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_analyticsEvent_argsAction( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["action"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("action")) - if tmp, ok := rawArgs["action"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_analyticsEvent_argsSource( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["source"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) - if tmp, ok := rawArgs["source"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_analyticsEvent_argsLabel( - ctx context.Context, - rawArgs map[string]interface{}, -) (*string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["label"] - if !ok { - var zeroVal *string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("label")) - if tmp, ok := rawArgs["label"]; ok { - return ec.unmarshalOString2ᚖstring(ctx, tmp) - } - - var zeroVal *string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_analyticsEvent_argsDimensionsJSON( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["dimensionsJson"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) - if tmp, ok := rawArgs["dimensionsJson"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} func (ec *executionContext) field_Query_availableUpdate_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_availableUpdate_argsDesiredChannel(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["desiredChannel"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredChannel")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["desiredChannel"] = arg0 - arg1, err := ec.field_Query_availableUpdate_argsDesiredVersion(ctx, rawArgs) - if err != nil { - return nil, err + var arg1 string + if tmp, ok := rawArgs["desiredVersion"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredVersion")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["desiredVersion"] = arg1 return args, nil } -func (ec *executionContext) field_Query_availableUpdate_argsDesiredChannel( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["desiredChannel"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredChannel")) - if tmp, ok := rawArgs["desiredChannel"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_availableUpdate_argsDesiredVersion( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["desiredVersion"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredVersion")) - if tmp, ok := rawArgs["desiredVersion"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} -func (ec *executionContext) field_Query_checkMessages_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (ec *executionContext) field_Query_checkNotifications_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_checkMessages_argsCommand(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["command"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("command")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["command"] = arg0 - arg1, err := ec.field_Query_checkMessages_argsFlags(ctx, rawArgs) - if err != nil { - return nil, err + var arg1 []string + if tmp, ok := rawArgs["flags"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("flags")) + arg1, err = ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) + if err != nil { + return nil, err + } } args["flags"] = arg1 return args, nil } -func (ec *executionContext) field_Query_checkMessages_argsCommand( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["command"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("command")) - if tmp, ok := rawArgs["command"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_checkMessages_argsFlags( - ctx context.Context, - rawArgs map[string]interface{}, -) ([]string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["flags"] - if !ok { - var zeroVal []string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flags")) - if tmp, ok := rawArgs["flags"]; ok { - return ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) - } - - var zeroVal []string - return zeroVal, nil -} func (ec *executionContext) field_Query_configChanged_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_configChanged_argsKey(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["key"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["key"] = arg0 return args, nil } -func (ec *executionContext) field_Query_configChanged_argsKey( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["key"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) - if tmp, ok := rawArgs["key"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} func (ec *executionContext) field_Query_getCache_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_getCache_argsKey(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["key"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["key"] = arg0 return args, nil } -func (ec *executionContext) field_Query_getCache_argsKey( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["key"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) - if tmp, ok := rawArgs["key"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} func (ec *executionContext) field_Query_getProcessesInUse_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_getProcessesInUse_argsExecDir(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["execDir"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execDir")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["execDir"] = arg0 return args, nil } -func (ec *executionContext) field_Query_getProcessesInUse_argsExecDir( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["execDir"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("execDir")) - if tmp, ok := rawArgs["execDir"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} func (ec *executionContext) field_Query_hashGlobs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_hashGlobs_argsWd(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 string + if tmp, ok := rawArgs["wd"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("wd")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["wd"] = arg0 - arg1, err := ec.field_Query_hashGlobs_argsGlobs(ctx, rawArgs) - if err != nil { - return nil, err + var arg1 []string + if tmp, ok := rawArgs["globs"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("globs")) + arg1, err = ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) + if err != nil { + return nil, err + } } args["globs"] = arg1 return args, nil } -func (ec *executionContext) field_Query_hashGlobs_argsWd( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["wd"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("wd")) - if tmp, ok := rawArgs["wd"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_hashGlobs_argsGlobs( - ctx context.Context, - rawArgs map[string]interface{}, -) ([]string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["globs"] - if !ok { - var zeroVal []string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("globs")) - if tmp, ok := rawArgs["globs"]; ok { - return ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) - } - - var zeroVal []string - return zeroVal, nil -} func (ec *executionContext) field_Query_reportRuntimeUsage_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field_Query_reportRuntimeUsage_argsPid(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 int + if tmp, ok := rawArgs["pid"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("pid")) + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } } args["pid"] = arg0 - arg1, err := ec.field_Query_reportRuntimeUsage_argsExec(ctx, rawArgs) - if err != nil { - return nil, err + var arg1 string + if tmp, ok := rawArgs["exec"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("exec")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["exec"] = arg1 - arg2, err := ec.field_Query_reportRuntimeUsage_argsSource(ctx, rawArgs) - if err != nil { - return nil, err + var arg2 string + if tmp, ok := rawArgs["source"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) + arg2, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["source"] = arg2 - arg3, err := ec.field_Query_reportRuntimeUsage_argsDimensionsJSON(ctx, rawArgs) - if err != nil { - return nil, err + var arg3 string + if tmp, ok := rawArgs["dimensionsJson"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) + arg3, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } args["dimensionsJson"] = arg3 return args, nil } -func (ec *executionContext) field_Query_reportRuntimeUsage_argsPid( - ctx context.Context, - rawArgs map[string]interface{}, -) (int, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["pid"] - if !ok { - var zeroVal int - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("pid")) - if tmp, ok := rawArgs["pid"]; ok { - return ec.unmarshalNInt2int(ctx, tmp) - } - - var zeroVal int - return zeroVal, nil -} - -func (ec *executionContext) field_Query_reportRuntimeUsage_argsExec( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["exec"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("exec")) - if tmp, ok := rawArgs["exec"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_reportRuntimeUsage_argsSource( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["source"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) - if tmp, ok := rawArgs["source"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} - -func (ec *executionContext) field_Query_reportRuntimeUsage_argsDimensionsJSON( - ctx context.Context, - rawArgs map[string]interface{}, -) (string, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["dimensionsJson"] - if !ok { - var zeroVal string - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) - if tmp, ok := rawArgs["dimensionsJson"]; ok { - return ec.unmarshalNString2string(ctx, tmp) - } - - var zeroVal string - return zeroVal, nil -} func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field___Type_enumValues_argsIncludeDeprecated(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } } args["includeDeprecated"] = arg0 return args, nil } -func (ec *executionContext) field___Type_enumValues_argsIncludeDeprecated( - ctx context.Context, - rawArgs map[string]interface{}, -) (bool, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["includeDeprecated"] - if !ok { - var zeroVal bool - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - if tmp, ok := rawArgs["includeDeprecated"]; ok { - return ec.unmarshalOBoolean2bool(ctx, tmp) - } - - var zeroVal bool - return zeroVal, nil -} func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - arg0, err := ec.field___Type_fields_argsIncludeDeprecated(ctx, rawArgs) - if err != nil { - return nil, err + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } } args["includeDeprecated"] = arg0 return args, nil } -func (ec *executionContext) field___Type_fields_argsIncludeDeprecated( - ctx context.Context, - rawArgs map[string]interface{}, -) (bool, error) { - // We won't call the directive if the argument is null. - // Set call_argument_directives_with_null to true to call directives - // even if the argument is null. - _, ok := rawArgs["includeDeprecated"] - if !ok { - var zeroVal bool - return zeroVal, nil - } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - if tmp, ok := rawArgs["includeDeprecated"]; ok { - return ec.unmarshalOBoolean2bool(ctx, tmp) - } - - var zeroVal bool - return zeroVal, nil -} // endregion ***************************** args.gotpl ***************************** @@ -2177,8 +1757,8 @@ func (ec *executionContext) fieldContext_JWT_user(_ context.Context, field graph return fc, nil } -func (ec *executionContext) _MessageInfo_id(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_id(ctx, field) +func (ec *executionContext) _Mutation_setCache(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_setCache(ctx, field) if err != nil { return graphql.Null } @@ -2191,38 +1771,46 @@ func (ec *executionContext) _MessageInfo_id(ctx context.Context, field graphql.C }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ID, nil + return ec.resolvers.Mutation().SetCache(rctx, fc.Args["key"].(string), fc.Args["value"].(string), fc.Args["expiry"].(int)) }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(string) + res := resTmp.(*graphqltypes.Void) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalOVoid2ᚖgithubᚗcomᚋActiveStateᚋcliᚋcmdᚋstateᚑsvcᚋinternalᚋgraphqltypesᚐVoid(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_setCache(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "Mutation", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Void does not have child fields") }, } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_setCache_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } -func (ec *executionContext) _MessageInfo_message(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_message(ctx, field) +func (ec *executionContext) _NotificationInfo_id(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_id(ctx, field) if err != nil { return graphql.Null } @@ -2235,7 +1823,7 @@ func (ec *executionContext) _MessageInfo_message(ctx context.Context, field grap }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Message, nil + return obj.ID, nil }) if err != nil { ec.Error(ctx, err) @@ -2252,9 +1840,9 @@ func (ec *executionContext) _MessageInfo_message(ctx context.Context, field grap return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_message(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "NotificationInfo", Field: field, IsMethod: false, IsResolver: false, @@ -2265,8 +1853,8 @@ func (ec *executionContext) fieldContext_MessageInfo_message(_ context.Context, return fc, nil } -func (ec *executionContext) _MessageInfo_condition(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_condition(ctx, field) +func (ec *executionContext) _NotificationInfo_notification(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_notification(ctx, field) if err != nil { return graphql.Null } @@ -2279,7 +1867,7 @@ func (ec *executionContext) _MessageInfo_condition(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Condition, nil + return obj.Notification, nil }) if err != nil { ec.Error(ctx, err) @@ -2296,9 +1884,9 @@ func (ec *executionContext) _MessageInfo_condition(ctx context.Context, field gr return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_condition(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_notification(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "NotificationInfo", Field: field, IsMethod: false, IsResolver: false, @@ -2309,8 +1897,8 @@ func (ec *executionContext) fieldContext_MessageInfo_condition(_ context.Context return fc, nil } -func (ec *executionContext) _MessageInfo_startDate(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_startDate(ctx, field) +func (ec *executionContext) _NotificationInfo_condition(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_condition(ctx, field) if err != nil { return graphql.Null } @@ -2323,7 +1911,7 @@ func (ec *executionContext) _MessageInfo_startDate(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.StartDate, nil + return obj.Condition, nil }) if err != nil { ec.Error(ctx, err) @@ -2340,9 +1928,9 @@ func (ec *executionContext) _MessageInfo_startDate(ctx context.Context, field gr return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_startDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_condition(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "NotificationInfo", Field: field, IsMethod: false, IsResolver: false, @@ -2353,8 +1941,8 @@ func (ec *executionContext) fieldContext_MessageInfo_startDate(_ context.Context return fc, nil } -func (ec *executionContext) _MessageInfo_endDate(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_endDate(ctx, field) +func (ec *executionContext) _NotificationInfo_startDate(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_startDate(ctx, field) if err != nil { return graphql.Null } @@ -2367,7 +1955,7 @@ func (ec *executionContext) _MessageInfo_endDate(ctx context.Context, field grap }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.EndDate, nil + return obj.StartDate, nil }) if err != nil { ec.Error(ctx, err) @@ -2384,9 +1972,9 @@ func (ec *executionContext) _MessageInfo_endDate(ctx context.Context, field grap return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_endDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_startDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "NotificationInfo", Field: field, IsMethod: false, IsResolver: false, @@ -2397,8 +1985,8 @@ func (ec *executionContext) fieldContext_MessageInfo_endDate(_ context.Context, return fc, nil } -func (ec *executionContext) _MessageInfo_repeat(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_repeat(ctx, field) +func (ec *executionContext) _NotificationInfo_endDate(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_endDate(ctx, field) if err != nil { return graphql.Null } @@ -2411,7 +1999,7 @@ func (ec *executionContext) _MessageInfo_repeat(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Repeat, nil + return obj.EndDate, nil }) if err != nil { ec.Error(ctx, err) @@ -2423,26 +2011,26 @@ func (ec *executionContext) _MessageInfo_repeat(ctx context.Context, field graph } return graphql.Null } - res := resTmp.(graph.MessageRepeatType) + res := resTmp.(string) fc.Result = res - return ec.marshalNMessageRepeatType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageRepeatType(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_repeat(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_endDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "NotificationInfo", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type MessageRepeatType does not have child fields") + return nil, errors.New("field of type String does not have child fields") }, } return fc, nil } -func (ec *executionContext) _MessageInfo_interrupt(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_interrupt(ctx, field) +func (ec *executionContext) _NotificationInfo_repeat(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_repeat(ctx, field) if err != nil { return graphql.Null } @@ -2455,7 +2043,7 @@ func (ec *executionContext) _MessageInfo_interrupt(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Interrupt, nil + return obj.Repeat, nil }) if err != nil { ec.Error(ctx, err) @@ -2467,26 +2055,26 @@ func (ec *executionContext) _MessageInfo_interrupt(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(graph.MessageInterruptType) + res := resTmp.(graph.NotificationRepeatType) fc.Result = res - return ec.marshalNMessageInterruptType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageInterruptType(ctx, field.Selections, res) + return ec.marshalNNotificationRepeatType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationRepeatType(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_interrupt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_repeat(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "NotificationInfo", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type MessageInterruptType does not have child fields") + return nil, errors.New("field of type NotificationRepeatType does not have child fields") }, } return fc, nil } -func (ec *executionContext) _MessageInfo_placement(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_MessageInfo_placement(ctx, field) +func (ec *executionContext) _NotificationInfo_interrupt(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_interrupt(ctx, field) if err != nil { return graphql.Null } @@ -2499,7 +2087,7 @@ func (ec *executionContext) _MessageInfo_placement(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Placement, nil + return obj.Interrupt, nil }) if err != nil { ec.Error(ctx, err) @@ -2511,26 +2099,26 @@ func (ec *executionContext) _MessageInfo_placement(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(graph.MessagePlacementType) + res := resTmp.(graph.NotificationInterruptType) fc.Result = res - return ec.marshalNMessagePlacementType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessagePlacementType(ctx, field.Selections, res) + return ec.marshalNNotificationInterruptType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationInterruptType(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_MessageInfo_placement(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_interrupt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "MessageInfo", + Object: "NotificationInfo", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type MessagePlacementType does not have child fields") + return nil, errors.New("field of type NotificationInterruptType does not have child fields") }, } return fc, nil } -func (ec *executionContext) _Mutation_setCache(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_setCache(ctx, field) +func (ec *executionContext) _NotificationInfo_placement(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_placement(ctx, field) if err != nil { return graphql.Null } @@ -2543,41 +2131,33 @@ func (ec *executionContext) _Mutation_setCache(ctx context.Context, field graphq }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().SetCache(rctx, fc.Args["key"].(string), fc.Args["value"].(string), fc.Args["expiry"].(int)) + return obj.Placement, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*graphqltypes.Void) + res := resTmp.(graph.NotificationPlacementType) fc.Result = res - return ec.marshalOVoid2ᚖgithubᚗcomᚋActiveStateᚋcliᚋcmdᚋstateᚑsvcᚋinternalᚋgraphqltypesᚐVoid(ctx, field.Selections, res) + return ec.marshalNNotificationPlacementType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationPlacementType(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_setCache(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_placement(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Mutation", + Object: "NotificationInfo", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Void does not have child fields") + return nil, errors.New("field of type NotificationPlacementType does not have child fields") }, } - defer func() { - if r := recover(); r != nil { - err = ec.Recover(ctx, r) - ec.Error(ctx, err) - } - }() - ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Mutation_setCache_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } return fc, nil } @@ -3116,8 +2696,8 @@ func (ec *executionContext) fieldContext_Query_reportRuntimeUsage(ctx context.Co return fc, nil } -func (ec *executionContext) _Query_checkMessages(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query_checkMessages(ctx, field) +func (ec *executionContext) _Query_checkNotifications(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_checkNotifications(ctx, field) if err != nil { return graphql.Null } @@ -3130,7 +2710,7 @@ func (ec *executionContext) _Query_checkMessages(ctx context.Context, field grap }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().CheckMessages(rctx, fc.Args["command"].(string), fc.Args["flags"].([]string)) + return ec.resolvers.Query().CheckNotifications(rctx, fc.Args["command"].(string), fc.Args["flags"].([]string)) }) if err != nil { ec.Error(ctx, err) @@ -3142,12 +2722,12 @@ func (ec *executionContext) _Query_checkMessages(ctx context.Context, field grap } return graphql.Null } - res := resTmp.([]*graph.MessageInfo) + res := resTmp.([]*graph.NotificationInfo) fc.Result = res - return ec.marshalNMessageInfo2ᚕᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageInfoᚄ(ctx, field.Selections, res) + return ec.marshalNNotificationInfo2ᚕᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationInfoᚄ(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query_checkMessages(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query_checkNotifications(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Query", Field: field, @@ -3156,23 +2736,23 @@ func (ec *executionContext) fieldContext_Query_checkMessages(ctx context.Context Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": - return ec.fieldContext_MessageInfo_id(ctx, field) - case "message": - return ec.fieldContext_MessageInfo_message(ctx, field) + return ec.fieldContext_NotificationInfo_id(ctx, field) + case "notification": + return ec.fieldContext_NotificationInfo_notification(ctx, field) case "condition": - return ec.fieldContext_MessageInfo_condition(ctx, field) + return ec.fieldContext_NotificationInfo_condition(ctx, field) case "startDate": - return ec.fieldContext_MessageInfo_startDate(ctx, field) + return ec.fieldContext_NotificationInfo_startDate(ctx, field) case "endDate": - return ec.fieldContext_MessageInfo_endDate(ctx, field) + return ec.fieldContext_NotificationInfo_endDate(ctx, field) case "repeat": - return ec.fieldContext_MessageInfo_repeat(ctx, field) + return ec.fieldContext_NotificationInfo_repeat(ctx, field) case "interrupt": - return ec.fieldContext_MessageInfo_interrupt(ctx, field) + return ec.fieldContext_NotificationInfo_interrupt(ctx, field) case "placement": - return ec.fieldContext_MessageInfo_placement(ctx, field) + return ec.fieldContext_NotificationInfo_placement(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type MessageInfo", field.Name) + return nil, fmt.Errorf("no field named %q was found under type NotificationInfo", field.Name) }, } defer func() { @@ -3182,7 +2762,7 @@ func (ec *executionContext) fieldContext_Query_checkMessages(ctx context.Context } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Query_checkMessages_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Query_checkNotifications_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } @@ -6199,54 +5779,100 @@ func (ec *executionContext) _JWT(ctx context.Context, sel ast.SelectionSet, obj return out } -var messageInfoImplementors = []string{"MessageInfo"} +var mutationImplementors = []string{"Mutation"} -func (ec *executionContext) _MessageInfo(ctx context.Context, sel ast.SelectionSet, obj *graph.MessageInfo) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, messageInfoImplementors) +func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, mutationImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Mutation", + }) out := graphql.NewFieldSet(fields) deferred := make(map[string]*graphql.FieldSet) for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("MessageInfo") + out.Values[i] = graphql.MarshalString("Mutation") + case "setCache": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_setCache(ctx, field) + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var notificationInfoImplementors = []string{"NotificationInfo"} + +func (ec *executionContext) _NotificationInfo(ctx context.Context, sel ast.SelectionSet, obj *graph.NotificationInfo) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, notificationInfoImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("NotificationInfo") case "id": - out.Values[i] = ec._MessageInfo_id(ctx, field, obj) + out.Values[i] = ec._NotificationInfo_id(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } - case "message": - out.Values[i] = ec._MessageInfo_message(ctx, field, obj) + case "notification": + out.Values[i] = ec._NotificationInfo_notification(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } case "condition": - out.Values[i] = ec._MessageInfo_condition(ctx, field, obj) + out.Values[i] = ec._NotificationInfo_condition(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } case "startDate": - out.Values[i] = ec._MessageInfo_startDate(ctx, field, obj) + out.Values[i] = ec._NotificationInfo_startDate(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } case "endDate": - out.Values[i] = ec._MessageInfo_endDate(ctx, field, obj) + out.Values[i] = ec._NotificationInfo_endDate(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } case "repeat": - out.Values[i] = ec._MessageInfo_repeat(ctx, field, obj) + out.Values[i] = ec._NotificationInfo_repeat(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } case "interrupt": - out.Values[i] = ec._MessageInfo_interrupt(ctx, field, obj) + out.Values[i] = ec._NotificationInfo_interrupt(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } case "placement": - out.Values[i] = ec._MessageInfo_placement(ctx, field, obj) + out.Values[i] = ec._NotificationInfo_placement(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } @@ -6273,52 +5899,6 @@ func (ec *executionContext) _MessageInfo(ctx context.Context, sel ast.SelectionS return out } -var mutationImplementors = []string{"Mutation"} - -func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, mutationImplementors) - ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ - Object: "Mutation", - }) - - out := graphql.NewFieldSet(fields) - deferred := make(map[string]*graphql.FieldSet) - for i, field := range fields { - innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ - Object: field.Name, - Field: field, - }) - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Mutation") - case "setCache": - out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { - return ec._Mutation_setCache(ctx, field) - }) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - out.Dispatch(ctx) - if out.Invalids > 0 { - return graphql.Null - } - - atomic.AddInt32(&ec.deferred, int32(len(deferred))) - - for label, dfs := range deferred { - ec.processDeferredGroup(graphql.DeferredGroup{ - Label: label, - Path: graphql.GetPath(ctx), - FieldSet: dfs, - Context: ctx, - }) - } - - return out -} - var organizationImplementors = []string{"Organization"} func (ec *executionContext) _Organization(ctx context.Context, sel ast.SelectionSet, obj *graph.Organization) graphql.Marshaler { @@ -6568,7 +6148,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "checkMessages": + case "checkNotifications": field := field innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { @@ -6577,7 +6157,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_checkMessages(ctx, field) + res = ec._Query_checkNotifications(ctx, field) if res == graphql.Null { atomic.AddUint32(&fs.Invalids, 1) } @@ -7362,7 +6942,7 @@ func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.Selecti return res } -func (ec *executionContext) marshalNMessageInfo2ᚕᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageInfoᚄ(ctx context.Context, sel ast.SelectionSet, v []*graph.MessageInfo) graphql.Marshaler { +func (ec *executionContext) marshalNNotificationInfo2ᚕᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationInfoᚄ(ctx context.Context, sel ast.SelectionSet, v []*graph.NotificationInfo) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup isLen1 := len(v) == 1 @@ -7386,7 +6966,7 @@ func (ec *executionContext) marshalNMessageInfo2ᚕᚖgithubᚗcomᚋActiveState if !isLen1 { defer wg.Done() } - ret[i] = ec.marshalNMessageInfo2ᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageInfo(ctx, sel, v[i]) + ret[i] = ec.marshalNNotificationInfo2ᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationInfo(ctx, sel, v[i]) } if isLen1 { f(i) @@ -7406,43 +6986,43 @@ func (ec *executionContext) marshalNMessageInfo2ᚕᚖgithubᚗcomᚋActiveState return ret } -func (ec *executionContext) marshalNMessageInfo2ᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageInfo(ctx context.Context, sel ast.SelectionSet, v *graph.MessageInfo) graphql.Marshaler { +func (ec *executionContext) marshalNNotificationInfo2ᚖgithubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationInfo(ctx context.Context, sel ast.SelectionSet, v *graph.NotificationInfo) graphql.Marshaler { if v == nil { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "the requested element is null which the schema does not allow") } return graphql.Null } - return ec._MessageInfo(ctx, sel, v) + return ec._NotificationInfo(ctx, sel, v) } -func (ec *executionContext) unmarshalNMessageInterruptType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageInterruptType(ctx context.Context, v interface{}) (graph.MessageInterruptType, error) { - var res graph.MessageInterruptType +func (ec *executionContext) unmarshalNNotificationInterruptType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationInterruptType(ctx context.Context, v interface{}) (graph.NotificationInterruptType, error) { + var res graph.NotificationInterruptType err := res.UnmarshalGQL(v) return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalNMessageInterruptType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageInterruptType(ctx context.Context, sel ast.SelectionSet, v graph.MessageInterruptType) graphql.Marshaler { +func (ec *executionContext) marshalNNotificationInterruptType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationInterruptType(ctx context.Context, sel ast.SelectionSet, v graph.NotificationInterruptType) graphql.Marshaler { return v } -func (ec *executionContext) unmarshalNMessagePlacementType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessagePlacementType(ctx context.Context, v interface{}) (graph.MessagePlacementType, error) { - var res graph.MessagePlacementType +func (ec *executionContext) unmarshalNNotificationPlacementType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationPlacementType(ctx context.Context, v interface{}) (graph.NotificationPlacementType, error) { + var res graph.NotificationPlacementType err := res.UnmarshalGQL(v) return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalNMessagePlacementType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessagePlacementType(ctx context.Context, sel ast.SelectionSet, v graph.MessagePlacementType) graphql.Marshaler { +func (ec *executionContext) marshalNNotificationPlacementType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationPlacementType(ctx context.Context, sel ast.SelectionSet, v graph.NotificationPlacementType) graphql.Marshaler { return v } -func (ec *executionContext) unmarshalNMessageRepeatType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageRepeatType(ctx context.Context, v interface{}) (graph.MessageRepeatType, error) { - var res graph.MessageRepeatType +func (ec *executionContext) unmarshalNNotificationRepeatType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationRepeatType(ctx context.Context, v interface{}) (graph.NotificationRepeatType, error) { + var res graph.NotificationRepeatType err := res.UnmarshalGQL(v) return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalNMessageRepeatType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐMessageRepeatType(ctx context.Context, sel ast.SelectionSet, v graph.MessageRepeatType) graphql.Marshaler { +func (ec *executionContext) marshalNNotificationRepeatType2githubᚗcomᚋActiveStateᚋcliᚋinternalᚋgraphᚐNotificationRepeatType(ctx context.Context, sel ast.SelectionSet, v graph.NotificationRepeatType) graphql.Marshaler { return v } diff --git a/cmd/state-svc/schema/schema.graphqls b/cmd/state-svc/schema/schema.graphqls index 9f71c26909..094c3b829d 100644 --- a/cmd/state-svc/schema/schema.graphqls +++ b/cmd/state-svc/schema/schema.graphqls @@ -31,7 +31,7 @@ type ReportRuntimeUsageResponse { received: Boolean! } -enum MessageRepeatType { +enum NotificationRepeatType { Disabled Constantly Hourly @@ -40,26 +40,26 @@ enum MessageRepeatType { Monthly } -enum MessageInterruptType { +enum NotificationInterruptType { Disabled Prompt Exit } -enum MessagePlacementType { +enum NotificationPlacementType { BeforeCmd AfterCmd } -type MessageInfo { +type NotificationInfo { id: String! - message: String! + notification: String! condition: String! startDate: String! endDate: String! - repeat: MessageRepeatType! - interrupt: MessageInterruptType! - placement: MessagePlacementType! + repeat: NotificationRepeatType! + interrupt: NotificationInterruptType! + placement: NotificationPlacementType! } type Organization { @@ -96,7 +96,7 @@ type Query { projects: [Project]! analyticsEvent(category: String!, action: String!, source: String!, label: String, dimensionsJson: String!): AnalyticsEventResponse reportRuntimeUsage(pid: Int!, exec: String!, source: String!, dimensionsJson: String!): ReportRuntimeUsageResponse - checkMessages(command: String!, flags: [String!]!): [MessageInfo!]! + checkNotifications(command: String!, flags: [String!]!): [NotificationInfo!]! configChanged(key: String!): ConfigChangedResponse fetchLogTail: String! getProcessesInUse(execDir: String!): [ProcessInfo!]! diff --git a/cmd/state/internal/cmdtree/exechandlers/messenger/messenger.go b/cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go similarity index 53% rename from cmd/state/internal/cmdtree/exechandlers/messenger/messenger.go rename to cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go index efbbb825ed..4c670a612a 100644 --- a/cmd/state/internal/cmdtree/exechandlers/messenger/messenger.go +++ b/cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go @@ -1,4 +1,4 @@ -package messenger +package notifier import ( "fmt" @@ -16,20 +16,20 @@ import ( "golang.org/x/net/context" ) -type Messenger struct { - out output.Outputer - svcModel *model.SvcModel - messages []*graph.MessageInfo +type Notifier struct { + out output.Outputer + svcModel *model.SvcModel + notifications []*graph.NotificationInfo } -func New(out output.Outputer, svcModel *model.SvcModel) *Messenger { - return &Messenger{ +func New(out output.Outputer, svcModel *model.SvcModel) *Notifier { + return &Notifier{ out: out, svcModel: svcModel, } } -func (m *Messenger) OnExecStart(cmd *captain.Command, _ []string) error { +func (m *Notifier) OnExecStart(cmd *captain.Command, _ []string) error { if m.out.Type().IsStructured() { // No point showing messaging on non-plain output (eg. json) return nil @@ -42,23 +42,23 @@ func (m *Messenger) OnExecStart(cmd *captain.Command, _ []string) error { cmds := cmd.JoinedCommandNames() flags := cmd.ActiveFlagNames() - messages, err := m.svcModel.CheckMessages(context.Background(), cmds, flags) + notifications, err := m.svcModel.CheckNotifications(context.Background(), cmds, flags) if err != nil { - multilog.Error("Could not report messages as CheckMessages return an error: %s", errs.JoinMessage(err)) + multilog.Error("Could not report notifications as CheckNotifications return an error: %s", errs.JoinMessage(err)) } - m.messages = messages + m.notifications = notifications - logging.Debug("Received %d messages to print", len(messages)) + logging.Debug("Received %d notifications to print", len(notifications)) - if err := m.PrintByPlacement(graph.MessagePlacementTypeBeforeCmd); err != nil { + if err := m.PrintByPlacement(graph.NotificationPlacementTypeBeforeCmd); err != nil { return errs.Wrap(err, "message error occurred before cmd") } return nil } -func (m *Messenger) OnExecStop(cmd *captain.Command, _ []string) error { +func (m *Notifier) OnExecStop(cmd *captain.Command, _ []string) error { if m.out.Type().IsStructured() { // No point showing messaging on non-plain output (eg. json) return nil @@ -68,36 +68,36 @@ func (m *Messenger) OnExecStop(cmd *captain.Command, _ []string) error { return nil // do not print update/deprecation warnings/messages when running `state update` } - if err := m.PrintByPlacement(graph.MessagePlacementTypeAfterCmd); err != nil { + if err := m.PrintByPlacement(graph.NotificationPlacementTypeAfterCmd); err != nil { return errs.Wrap(err, "message error occurred before cmd") } return nil } -func (m *Messenger) PrintByPlacement(placement graph.MessagePlacementType) error { +func (m *Notifier) PrintByPlacement(placement graph.NotificationPlacementType) error { exit := []string{} - messages := []*graph.MessageInfo{} - for _, message := range m.messages { - if message.Placement != placement { - logging.Debug("Skipping message %s as it's placement (%s) does not match %s", message.ID, message.Placement, placement) - messages = append(messages, message) + notifications := []*graph.NotificationInfo{} + for _, notification := range m.notifications { + if notification.Placement != placement { + logging.Debug("Skipping notification %s as it's placement (%s) does not match %s", notification.ID, notification.Placement, placement) + notifications = append(notifications, notification) continue } - if placement == graph.MessagePlacementTypeAfterCmd { + if placement == graph.NotificationPlacementTypeAfterCmd { m.out.Notice("") // Line break after } - logging.Debug("Printing message: %s", message.ID) - m.out.Notice(message.Message) + logging.Debug("Printing notification: %s, %s", notification.ID, notification.Notification) + m.out.Notice(notification.Notification) - if placement == graph.MessagePlacementTypeBeforeCmd { + if placement == graph.NotificationPlacementTypeBeforeCmd { m.out.Notice("") // Line break before } - if message.Interrupt == graph.MessageInterruptTypePrompt { + if notification.Interrupt == graph.NotificationInterruptTypePrompt { if m.out.Config().Interactive { m.out.Print(locale.Tl("messenger_prompt_continue", "Press ENTER to continue.")) fmt.Scanln(ptr.To("")) // Wait for input from user @@ -106,12 +106,12 @@ func (m *Messenger) PrintByPlacement(placement graph.MessagePlacementType) error } } - if message.Interrupt == graph.MessageInterruptTypeExit { - exit = append(exit, message.ID) + if notification.Interrupt == graph.NotificationInterruptTypeExit { + exit = append(exit, notification.ID) } } - m.messages = messages + m.notifications = notifications if len(exit) > 0 { // It's the responsibility of the message to give the user context as to why this exit happened. diff --git a/cmd/state/main.go b/cmd/state/main.go index 84ae4a16fb..2788e8d1b9 100644 --- a/cmd/state/main.go +++ b/cmd/state/main.go @@ -10,7 +10,7 @@ import ( "time" "github.com/ActiveState/cli/cmd/state/internal/cmdtree" - "github.com/ActiveState/cli/cmd/state/internal/cmdtree/exechandlers/messenger" + "github.com/ActiveState/cli/cmd/state/internal/cmdtree/exechandlers/notifier" anAsync "github.com/ActiveState/cli/internal/analytics/client/async" anaConst "github.com/ActiveState/cli/internal/analytics/constants" "github.com/ActiveState/cli/internal/captain" @@ -247,9 +247,9 @@ func run(args []string, isInteractive bool, cfg *config.Instance, out output.Out logging.Debug("Could not find child command, error: %v", err) } - msger := messenger.New(out, svcmodel) - cmds.OnExecStart(msger.OnExecStart) - cmds.OnExecStop(msger.OnExecStop) + notifier := notifier.New(out, svcmodel) + cmds.OnExecStart(notifier.OnExecStart) + cmds.OnExecStop(notifier.OnExecStop) // Auto update to latest state tool version if possible. if updated, err := autoUpdate(svcmodel, args, childCmd, cfg, an, out); err == nil && updated { diff --git a/internal/constants/constants.go b/internal/constants/constants.go index f64eb5650d..56bd48c1a3 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -154,8 +154,8 @@ const OptinUnstableEnvVarName = "ACTIVESTATE_OPTIN_UNSTABLE" // ServiceSockDir overrides the default socket path root diriectory used by the state service const ServiceSockDir = "ACTIVESTATE_SVC_SOCK" -// MessagesOverrideEnvVarName is used to override the location of the messages file (for testing purposes - should hold local filepath) -const MessagesOverrideEnvVarName = "ACTIVESTATE_MESSAGES_OVERRIDE" +// NotificationsOverrideEnvVarName is used to override the location of the notifications file (for testing purposes - should hold local filepath) +const NotificationsOverrideEnvVarName = "ACTIVESTATE_NOTIFICATIONS_OVERRIDE" // DisableErrorTipsEnvVarName disables the display of tips in error messages. // This should only be used by the installer so-as not to pollute error message output. diff --git a/internal/graph/generated.go b/internal/graph/generated.go index 61f7178059..482806f028 100644 --- a/internal/graph/generated.go +++ b/internal/graph/generated.go @@ -40,18 +40,18 @@ type Jwt struct { User *User `json:"user"` } -type MessageInfo struct { - ID string `json:"id"` - Message string `json:"message"` - Condition string `json:"condition"` - StartDate string `json:"startDate"` - EndDate string `json:"endDate"` - Repeat MessageRepeatType `json:"repeat"` - Interrupt MessageInterruptType `json:"interrupt"` - Placement MessagePlacementType `json:"placement"` +type Mutation struct { } -type Mutation struct { +type NotificationInfo struct { + ID string `json:"id"` + Notification string `json:"notification"` + Condition string `json:"condition"` + StartDate string `json:"startDate"` + EndDate string `json:"endDate"` + Repeat NotificationRepeatType `json:"repeat"` + Interrupt NotificationInterruptType `json:"interrupt"` + Placement NotificationPlacementType `json:"placement"` } type Organization struct { @@ -95,135 +95,135 @@ type Version struct { State *StateVersion `json:"state"` } -type MessageInterruptType string +type NotificationInterruptType string const ( - MessageInterruptTypeDisabled MessageInterruptType = "Disabled" - MessageInterruptTypePrompt MessageInterruptType = "Prompt" - MessageInterruptTypeExit MessageInterruptType = "Exit" + NotificationInterruptTypeDisabled NotificationInterruptType = "Disabled" + NotificationInterruptTypePrompt NotificationInterruptType = "Prompt" + NotificationInterruptTypeExit NotificationInterruptType = "Exit" ) -var AllMessageInterruptType = []MessageInterruptType{ - MessageInterruptTypeDisabled, - MessageInterruptTypePrompt, - MessageInterruptTypeExit, +var AllNotificationInterruptType = []NotificationInterruptType{ + NotificationInterruptTypeDisabled, + NotificationInterruptTypePrompt, + NotificationInterruptTypeExit, } -func (e MessageInterruptType) IsValid() bool { +func (e NotificationInterruptType) IsValid() bool { switch e { - case MessageInterruptTypeDisabled, MessageInterruptTypePrompt, MessageInterruptTypeExit: + case NotificationInterruptTypeDisabled, NotificationInterruptTypePrompt, NotificationInterruptTypeExit: return true } return false } -func (e MessageInterruptType) String() string { +func (e NotificationInterruptType) String() string { return string(e) } -func (e *MessageInterruptType) UnmarshalGQL(v interface{}) error { +func (e *NotificationInterruptType) UnmarshalGQL(v interface{}) error { str, ok := v.(string) if !ok { return fmt.Errorf("enums must be strings") } - *e = MessageInterruptType(str) + *e = NotificationInterruptType(str) if !e.IsValid() { - return fmt.Errorf("%s is not a valid MessageInterruptType", str) + return fmt.Errorf("%s is not a valid NotificationInterruptType", str) } return nil } -func (e MessageInterruptType) MarshalGQL(w io.Writer) { +func (e NotificationInterruptType) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } -type MessagePlacementType string +type NotificationPlacementType string const ( - MessagePlacementTypeBeforeCmd MessagePlacementType = "BeforeCmd" - MessagePlacementTypeAfterCmd MessagePlacementType = "AfterCmd" + NotificationPlacementTypeBeforeCmd NotificationPlacementType = "BeforeCmd" + NotificationPlacementTypeAfterCmd NotificationPlacementType = "AfterCmd" ) -var AllMessagePlacementType = []MessagePlacementType{ - MessagePlacementTypeBeforeCmd, - MessagePlacementTypeAfterCmd, +var AllNotificationPlacementType = []NotificationPlacementType{ + NotificationPlacementTypeBeforeCmd, + NotificationPlacementTypeAfterCmd, } -func (e MessagePlacementType) IsValid() bool { +func (e NotificationPlacementType) IsValid() bool { switch e { - case MessagePlacementTypeBeforeCmd, MessagePlacementTypeAfterCmd: + case NotificationPlacementTypeBeforeCmd, NotificationPlacementTypeAfterCmd: return true } return false } -func (e MessagePlacementType) String() string { +func (e NotificationPlacementType) String() string { return string(e) } -func (e *MessagePlacementType) UnmarshalGQL(v interface{}) error { +func (e *NotificationPlacementType) UnmarshalGQL(v interface{}) error { str, ok := v.(string) if !ok { return fmt.Errorf("enums must be strings") } - *e = MessagePlacementType(str) + *e = NotificationPlacementType(str) if !e.IsValid() { - return fmt.Errorf("%s is not a valid MessagePlacementType", str) + return fmt.Errorf("%s is not a valid NotificationPlacementType", str) } return nil } -func (e MessagePlacementType) MarshalGQL(w io.Writer) { +func (e NotificationPlacementType) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } -type MessageRepeatType string +type NotificationRepeatType string const ( - MessageRepeatTypeDisabled MessageRepeatType = "Disabled" - MessageRepeatTypeConstantly MessageRepeatType = "Constantly" - MessageRepeatTypeHourly MessageRepeatType = "Hourly" - MessageRepeatTypeDaily MessageRepeatType = "Daily" - MessageRepeatTypeWeekly MessageRepeatType = "Weekly" - MessageRepeatTypeMonthly MessageRepeatType = "Monthly" + NotificationRepeatTypeDisabled NotificationRepeatType = "Disabled" + NotificationRepeatTypeConstantly NotificationRepeatType = "Constantly" + NotificationRepeatTypeHourly NotificationRepeatType = "Hourly" + NotificationRepeatTypeDaily NotificationRepeatType = "Daily" + NotificationRepeatTypeWeekly NotificationRepeatType = "Weekly" + NotificationRepeatTypeMonthly NotificationRepeatType = "Monthly" ) -var AllMessageRepeatType = []MessageRepeatType{ - MessageRepeatTypeDisabled, - MessageRepeatTypeConstantly, - MessageRepeatTypeHourly, - MessageRepeatTypeDaily, - MessageRepeatTypeWeekly, - MessageRepeatTypeMonthly, +var AllNotificationRepeatType = []NotificationRepeatType{ + NotificationRepeatTypeDisabled, + NotificationRepeatTypeConstantly, + NotificationRepeatTypeHourly, + NotificationRepeatTypeDaily, + NotificationRepeatTypeWeekly, + NotificationRepeatTypeMonthly, } -func (e MessageRepeatType) IsValid() bool { +func (e NotificationRepeatType) IsValid() bool { switch e { - case MessageRepeatTypeDisabled, MessageRepeatTypeConstantly, MessageRepeatTypeHourly, MessageRepeatTypeDaily, MessageRepeatTypeWeekly, MessageRepeatTypeMonthly: + case NotificationRepeatTypeDisabled, NotificationRepeatTypeConstantly, NotificationRepeatTypeHourly, NotificationRepeatTypeDaily, NotificationRepeatTypeWeekly, NotificationRepeatTypeMonthly: return true } return false } -func (e MessageRepeatType) String() string { +func (e NotificationRepeatType) String() string { return string(e) } -func (e *MessageRepeatType) UnmarshalGQL(v interface{}) error { +func (e *NotificationRepeatType) UnmarshalGQL(v interface{}) error { str, ok := v.(string) if !ok { return fmt.Errorf("enums must be strings") } - *e = MessageRepeatType(str) + *e = NotificationRepeatType(str) if !e.IsValid() { - return fmt.Errorf("%s is not a valid MessageRepeatType", str) + return fmt.Errorf("%s is not a valid NotificationRepeatType", str) } return nil } -func (e MessageRepeatType) MarshalGQL(w io.Writer) { +func (e NotificationRepeatType) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } diff --git a/pkg/platform/api/svc/request/messaging.go b/pkg/platform/api/svc/request/messaging.go deleted file mode 100644 index a762e924ee..0000000000 --- a/pkg/platform/api/svc/request/messaging.go +++ /dev/null @@ -1,31 +0,0 @@ -package request - -type MessagingRequest struct { - command string - flags []string -} - -func NewMessagingRequest(command string, flags []string) *MessagingRequest { - return &MessagingRequest{ - command: command, - flags: flags, - } -} - -func (m *MessagingRequest) Query() string { - return `query($command: String!, $flags: [String!]!) { - checkMessages(command: $command, flags: $flags) { - id - message - interrupt - placement - } - }` -} - -func (m *MessagingRequest) Vars() (map[string]interface{}, error) { - return map[string]interface{}{ - "command": m.command, - "flags": m.flags, - }, nil -} diff --git a/pkg/platform/api/svc/request/notification.go b/pkg/platform/api/svc/request/notification.go new file mode 100644 index 0000000000..a4983960ac --- /dev/null +++ b/pkg/platform/api/svc/request/notification.go @@ -0,0 +1,31 @@ +package request + +type NotificationRequest struct { + command string + flags []string +} + +func NewNotificationRequest(command string, flags []string) *NotificationRequest { + return &NotificationRequest{ + command: command, + flags: flags, + } +} + +func (m *NotificationRequest) Query() string { + return `query($command: String!, $flags: [String!]!) { + checkNotifications(command: $command, flags: $flags) { + id + notification + interrupt + placement + } + }` +} + +func (m *NotificationRequest) Vars() (map[string]interface{}, error) { + return map[string]interface{}{ + "command": m.command, + "flags": m.flags, + }, nil +} diff --git a/pkg/platform/model/svc.go b/pkg/platform/model/svc.go index c61a660b6a..5cfca41cfa 100644 --- a/pkg/platform/model/svc.go +++ b/pkg/platform/model/svc.go @@ -125,14 +125,14 @@ func (m *SvcModel) ReportRuntimeUsage(ctx context.Context, pid int, exec, source return nil } -func (m *SvcModel) CheckMessages(ctx context.Context, command string, flags []string) ([]*graph.MessageInfo, error) { - logging.Debug("Checking for messages") - defer profile.Measure("svc:CheckMessages", time.Now()) +func (m *SvcModel) CheckNotifications(ctx context.Context, command string, flags []string) ([]*graph.NotificationInfo, error) { + logging.Debug("Checking for notifications") + defer profile.Measure("svc:CheckNotifications", time.Now()) - r := request.NewMessagingRequest(command, flags) - resp := []*graph.MessageInfo{} + r := request.NewNotificationRequest(command, flags) + resp := []*graph.NotificationInfo{} if err := m.request(ctx, r, &resp); err != nil { - return nil, errs.Wrap(err, "Error sending messages request") + return nil, errs.Wrap(err, "Error sending notifications request") } return resp, nil diff --git a/test/integration/msg_int_test.go b/test/integration/notification_int_test.go similarity index 62% rename from test/integration/msg_int_test.go rename to test/integration/notification_int_test.go index fbf16e3ab9..77a48e999b 100644 --- a/test/integration/msg_int_test.go +++ b/test/integration/notification_int_test.go @@ -13,11 +13,11 @@ import ( "github.com/ActiveState/cli/internal/testhelpers/tagsuite" ) -type MsgIntegrationTestSuite struct { +type NotificationIntegrationTestSuite struct { tagsuite.Suite } -func (suite *MsgIntegrationTestSuite) TestMessage_None() { +func (suite *NotificationIntegrationTestSuite) TestNotification_None() { suite.OnlyRunForTags(tagsuite.Messaging, tagsuite.Critical) ts := e2e.New(suite.T(), false) defer ts.Close() @@ -30,7 +30,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_None() { // the logs for any potential issues. This is done automatically by ts.Close(). } -func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { +func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { suite.OnlyRunForTags(tagsuite.Messaging, tagsuite.Critical) tests := []struct { Name string @@ -42,7 +42,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Defaults", `[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message" + "Notification": "This is a [NOTICE]simple[/RESET] notification" }]`, false, true, @@ -51,7 +51,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Repeat Hourly", `[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "Repeat": "Hourly" }]`, false, @@ -61,7 +61,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Repeat Constantly", `[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "Repeat": "Constantly" }]`, true, @@ -71,7 +71,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Within Date Range", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -84,7 +84,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Outside Date Range", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -97,7 +97,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Only Start Date - Inside Range", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s" }]`, time.Now().Add(-1*time.Hour).Format(time.RFC3339)), @@ -108,7 +108,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Only End Date - Inside Range", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "EndDate": "%s" }]`, time.Now().Add(1*time.Hour).Format(time.RFC3339)), @@ -119,7 +119,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Outside Date Range - Future", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -132,7 +132,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Outside Date Range - Past", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -145,7 +145,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Only Start Date - Outside Range", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s" }]`, time.Now().Add(1*time.Hour).Format(time.RFC3339)), @@ -156,7 +156,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Only End Date - Outside Range", fmt.Sprintf(`[{ "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "EndDate": "%s" }]`, time.Now().Add(-1*time.Hour).Format(time.RFC3339)), @@ -169,15 +169,15 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(tt.MessageJson), 0755) + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(tt.MessageJson), 0755) suite.Require().NoError(err) - cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.MessagesOverrideEnvVarName+"="+msgFile)) + cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.NotificationsOverrideEnvVarName+"="+msgFile)) if !tt.ExpectShown { - suite.Require().NotContains(cp.Output(), "This is a simple message", "Message should not appear when outside date range") + suite.Require().NotContains(cp.Output(), "This is a simple notification", "Notification should not appear when outside date range") } else { - cp.Expect(`This is a simple message`) + cp.Expect(`This is a simple notification`) } cp.Expect("ActiveState CLI by ActiveState Software Inc.") @@ -186,53 +186,53 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { // Ensure message doesn't stick around when we run another command cp = ts.Spawn("--version") if tt.ExpectRepeat { - cp.Expect(`This is a simple message`) + cp.Expect(`This is a simple notification`) } cp.ExpectExitCode(0) if !tt.ExpectRepeat { - suite.Require().NotContains(cp.Output(), "This is a simple message", "Should not repeat as that's the default behavior") + suite.Require().NotContains(cp.Output(), "This is a simple notification", "Should not repeat as that's the default behavior") } }) } } -func (suite *MsgIntegrationTestSuite) TestMessage_Basic_PlacementAfter() { +func (suite *NotificationIntegrationTestSuite) TestNotification_Basic_PlacementAfter() { suite.OnlyRunForTags(tagsuite.Messaging) ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(fmt.Sprintf(`[ + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(fmt.Sprintf(`[ { "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "Placement": "%s" } -]`, graph.MessagePlacementTypeAfterCmd)), 0755) +]`, graph.NotificationPlacementTypeAfterCmd)), 0755) suite.Require().NoError(err) - cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.MessagesOverrideEnvVarName+"="+msgFile)) + cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.NotificationsOverrideEnvVarName+"="+msgFile)) cp.Expect("ActiveState CLI by ActiveState Software Inc.") - cp.Expect(`This is a simple message`) + cp.Expect(`This is a simple notification`) cp.ExpectExitCode(0) } -func (suite *MsgIntegrationTestSuite) TestMessage_Basic_InterruptPrompt() { +func (suite *NotificationIntegrationTestSuite) TestNotification_Basic_InterruptPrompt() { suite.OnlyRunForTags(tagsuite.Messaging) ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(fmt.Sprintf(`[ + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(fmt.Sprintf(`[ { "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "Repeat": "Constantly", "Interrupt": "%s" } -]`, graph.MessageInterruptTypePrompt)), 0755) +]`, graph.NotificationInterruptTypePrompt)), 0755) suite.Require().NoError(err) - cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.MessagesOverrideEnvVarName+"="+msgFile)) - cp.Expect(`This is a simple message`) + cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.NotificationsOverrideEnvVarName+"="+msgFile)) + cp.Expect(`This is a simple notification`) cp.Expect("Press ENTER to continue") time.Sleep(time.Millisecond * 100) suite.Require().NotContains(cp.Output(), "ActiveState CLI by ActiveState Software Inc.") @@ -241,34 +241,34 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic_InterruptPrompt() { cp.ExpectExitCode(0) // Test that non-interactive does not prompt - cp = ts.SpawnCmdWithOpts("state", e2e.OptArgs("--version", "-n"), e2e.OptAppendEnv(constants.MessagesOverrideEnvVarName+"="+msgFile)) - cp.Expect(`This is a simple message`) + cp = ts.SpawnCmdWithOpts("state", e2e.OptArgs("--version", "-n"), e2e.OptAppendEnv(constants.NotificationsOverrideEnvVarName+"="+msgFile)) + cp.Expect(`This is a simple notification`) cp.Expect("ActiveState CLI by ActiveState Software Inc.") cp.ExpectExitCode(0) suite.Require().NotContains(cp.Output(), "Press ENTER to continue") } -func (suite *MsgIntegrationTestSuite) TestMessage_Basic_InterruptExit() { +func (suite *NotificationIntegrationTestSuite) TestNotification_Basic_InterruptExit() { suite.OnlyRunForTags(tagsuite.Messaging) ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(fmt.Sprintf(`[ + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(fmt.Sprintf(`[ { "ID": "simple", - "Message": "This is a [NOTICE]simple[/RESET] message", + "Notification": "This is a [NOTICE]simple[/RESET] notification", "Interrupt": "%s" } -]`, graph.MessageInterruptTypeExit)), 0755) +]`, graph.NotificationInterruptTypeExit)), 0755) suite.Require().NoError(err) - cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.MessagesOverrideEnvVarName+"="+msgFile)) + cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.NotificationsOverrideEnvVarName+"="+msgFile)) cp.ExpectExitCode(1) - suite.Require().Contains(cp.Snapshot(), "This is a simple message") + suite.Require().Contains(cp.Snapshot(), "This is a simple notification") suite.Require().NotContains(cp.Output(), "ActiveState CLI by ActiveState Software Inc.") ts.IgnoreLogErrors() } -func TestMsgIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(MsgIntegrationTestSuite)) +func TestNotificationIntegrationTestSuite(t *testing.T) { + suite.Run(t, new(NotificationIntegrationTestSuite)) }