(ctx context.Context, app, ID string, params ProvisionParams)
| 9 | ) |
| 10 | |
| 11 | func Update(ctx context.Context, app, ID string, params ProvisionParams) error { |
| 12 | if app == "" { |
| 13 | return errors.New(ctx, "no app defined") |
| 14 | } |
| 15 | |
| 16 | c, err := config.ScalingoClient(ctx) |
| 17 | if err != nil { |
| 18 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 19 | } |
| 20 | notifier, err := c.NotifierByID(ctx, app, ID) |
| 21 | if err != nil { |
| 22 | return errors.Wrapf(ctx, err, "fail to get notifier from server") |
| 23 | } |
| 24 | |
| 25 | eventTypes, err := c.EventTypesList(ctx) |
| 26 | if err != nil { |
| 27 | return errors.Wrapf(ctx, err, "fail to list event types") |
| 28 | } |
| 29 | |
| 30 | // If there is no selected events, keep the existing ones |
| 31 | if len(params.SelectedEventNames) == 0 { |
| 32 | params.SelectedEventIDs = append([]string{}, notifier.SelectedEventIDs...) |
| 33 | } else { |
| 34 | for _, name := range params.SelectedEventNames { |
| 35 | for _, t := range eventTypes { |
| 36 | if t.Name == name { |
| 37 | params.SelectedEventIDs = append(params.SelectedEventIDs, t.ID) |
| 38 | break |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | if len(params.CollaboratorUsernames) > 0 { |
| 45 | params.UserIDs, err = collaboratorUserIDs(ctx, c, app, params.CollaboratorUsernames) |
| 46 | if err != nil { |
| 47 | return errors.Wrapf(ctx, err, "invalid collaborator usernames") |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | baseNotifier, err := c.NotifierUpdate(ctx, app, ID, params.NotifierParams) |
| 52 | if err != nil { |
| 53 | return errors.Wrapf(ctx, err, "fail to update notifier") |
| 54 | } |
| 55 | detailedNotifier := baseNotifier.Specialize() |
| 56 | |
| 57 | displayDetails(detailedNotifier, eventTypes) |
| 58 | io.Info() |
| 59 | io.Status("Notifier updated") |
| 60 | return nil |
| 61 | } |
no test coverage detected