Skip to content

feat(cli): pause notifications #13873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unpause -> resume
  • Loading branch information
mtojek committed Jul 11, 2024
commit 3694faee78405ed1a147f0028b8fa0a0116d10a1
24 changes: 13 additions & 11 deletions cli/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cli
import (
"fmt"

"golang.org/x/xerrors"

"github.com/coder/serpent"

"github.com/coder/coder/v2/codersdk"
Expand All @@ -14,12 +16,12 @@ func (r *RootCmd) notifications() *serpent.Command {
Short: "Manage Coder notifications",
Long: "Administrators can use these commands to change notification settings.\n" + FormatExamples(
Example{
Description: "Pause Coder notifications",
Description: "Pause Coder notifications. Administrators can temporarily stop notifiers from dispatching messages in case of the target outage (for example: unavailable SMTP server or Webhook not responding).",
Command: "coder notifications pause",
},
Example{
Description: "Unpause Coder notifications",
Command: "coder notifications unpause",
Description: "Resume Coder notifications",
Command: "coder notifications resume",
},
),
Aliases: []string{"notification"},
Expand All @@ -28,7 +30,7 @@ func (r *RootCmd) notifications() *serpent.Command {
},
Children: []*serpent.Command{
r.pauseNotifications(),
r.unpauseNotifications(),
r.resumeNotifications(),
},
}
return cmd
Expand All @@ -48,21 +50,21 @@ func (r *RootCmd) pauseNotifications() *serpent.Command {
NotifierPaused: true,
})
if err != nil {
return err
return xerrors.Errorf("unable to pause notifications %w", err)
}

_, _ = fmt.Fprintln(inv.Stderr, "Notifications are paused now.")
_, _ = fmt.Fprintln(inv.Stderr, "Notifications are now paused.")
return nil
},
}
return cmd
}

func (r *RootCmd) unpauseNotifications() *serpent.Command {
func (r *RootCmd) resumeNotifications() *serpent.Command {
client := new(codersdk.Client)
cmd := &serpent.Command{
Use: "unpause",
Short: "Unpause notifications",
Use: "resume",
Short: "Resume notifications",
Middleware: serpent.Chain(
serpent.RequireNArgs(0),
r.InitClient(client),
Expand All @@ -72,10 +74,10 @@ func (r *RootCmd) unpauseNotifications() *serpent.Command {
NotifierPaused: false,
})
if err != nil {
return err
return xerrors.Errorf("unable to resume notifications %w", err)
}

_, _ = fmt.Fprintln(inv.Stderr, "Notifications are unpaused now.")
_, _ = fmt.Fprintln(inv.Stderr, "Notifications are now resumed.")
return nil
},
}
Expand Down
6 changes: 3 additions & 3 deletions cli/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ func TestPauseNotifications_RegularUser(t *testing.T) {
var settings codersdk.NotificationsSettings
err = json.Unmarshal([]byte(settingsJSON), &settings)
require.NoError(t, err)
require.False(t, settings.NotifierPaused) // still unpaused
require.False(t, settings.NotifierPaused) // still running
}

func TestUnpauseNotifications(t *testing.T) {
func TestResumeNotifications(t *testing.T) {
t.Parallel()

// given
ownerClient, db := coderdtest.NewWithDatabase(t, nil)
_ = coderdtest.CreateFirstUser(t, ownerClient)

// when
inv, root := clitest.New(t, "notifications", "unpause")
inv, root := clitest.New(t, "notifications", "resume")
clitest.SetupConfig(t, ownerClient, root)

var buf bytes.Buffer
Expand Down
8 changes: 4 additions & 4 deletions cli/testdata/coder_notifications_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ USAGE:

$ coder notifications pause

- Unpause Coder notifications:
- Resume Coder notifications:

$ coder notifications unpause
$ coder notifications resume

SUBCOMMANDS:
pause Pause notifications
unpause Unpause notifications
pause Pause notifications
resume Resume notifications

———
Run `coder --help` for a list of global options.
9 changes: 9 additions & 0 deletions cli/testdata/coder_notifications_resume_--help.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coder v0.0.0-devel

USAGE:
coder notifications resume

Resume notifications

———
Run `coder --help` for a list of global options.
16 changes: 9 additions & 7 deletions docs/cli/notifications.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions docs/cli/notifications_resume.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions docs/cli/notifications_unpause.md

This file was deleted.

6 changes: 3 additions & 3 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,9 @@
"path": "cli/notifications_pause.md"
},
{
"title": "notifications unpause",
"description": "Unpause notifications",
"path": "cli/notifications_unpause.md"
"title": "notifications resume",
"description": "Resume notifications",
"path": "cli/notifications_resume.md"
},
{
"title": "open",
Expand Down
Loading